From 295a86d1a96238c1d0b852ff7d12c94368a7313d Mon Sep 17 00:00:00 2001 From: aozarov Date: Fri, 22 May 2015 16:01:32 -0700 Subject: [PATCH 001/663] initial work on modules --- google-cloud-core/README.md | 55 +++ google-cloud-core/pom.xml | 94 ++++++ .../com/google/gcloud/AuthCredentials.java | 206 ++++++++++++ .../java/com/google/gcloud/BaseService.java | 1 + .../com/google/gcloud/ExceptionHandler.java | 280 ++++++++++++++++ .../java/com/google/gcloud/RetryHelper.java | 252 ++++++++++++++ .../java/com/google/gcloud/RetryParams.java | 292 ++++++++++++++++ .../main/java/com/google/gcloud/Service.java | 1 + .../com/google/gcloud/ServiceOptions.java | 314 ++++++++++++++++++ .../google/gcloud/spi/ServiceRpcFactory.java | 1 + .../google/gcloud/spi/ServiceRpcProvider.java | 32 ++ .../google/gcloud/ExceptionHandlerTest.java | 168 ++++++++++ .../com/google/gcloud/RetryHelperTest.java | 263 +++++++++++++++ .../com/google/gcloud/RetryParamsTest.java | 107 ++++++ 14 files changed, 2066 insertions(+) create mode 100644 google-cloud-core/README.md create mode 100644 google-cloud-core/pom.xml create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/BaseService.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/Service.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcProvider.java create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md new file mode 100644 index 0000000000..e22b159d21 --- /dev/null +++ b/google-cloud-core/README.md @@ -0,0 +1,55 @@ +Google Cloud Java Client +========================== + +Java idiomatic client for [Google Cloud Platform][cloud-platform] services. + +[![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java) +[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master) + +- [Homepage] (https://googlecloudplatform.github.io/gcloud-java/) +- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs) +- [Examples] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/examples/package-summary.html) + +This moudle provides common functionality and is required by the other service specific modules. + +Quickstart +---------- +Add this to your pom.xml file +```xml + + com.google.gcloud + gcloud-java-core + LATEST + +``` + +Contributing +------------ + +Contributions to this library are always welcome and highly encouraged. + +See [CONTRIBUTING] for more information on how to get started. + +Java Versions +------------- + +Java 7 or above is required for using this client. + +Versioning +---------- + +This library follows [Semantic Versioning] (http://semver.org/). + +It is currently in major version zero (``0.y.z``), which means that anything +may change at any time and the public API should not be considered +stable. + +License +------- + +Apache 2.0 - See [LICENSE] for more information. + + +[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md +[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE +[cloud-platform]: https://cloud.google.com/ diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml new file mode 100644 index 0000000000..7fbbe7dad2 --- /dev/null +++ b/google-cloud-core/pom.xml @@ -0,0 +1,94 @@ + + + 4.0.0 + com.google.gcloud + gcloud-java-core + jar + GCloud Java core + https://github.com/GoogleCloudPlatform/gcloud-java + + Java idiomatic client for Google Cloud Platform services. + + + com.google.gcloud + gcloud-java-pom + 0.0.5 + + + + com.google.auth + google-auth-library-credentials + 0.1.0 + + + com.google.auth + google-auth-library-oauth2-http + 0.1.0 + + + com.google.http-client + google-http-client + 1.19.0 + compile + + + com.google.oauth-client + google-oauth-client + 1.19.0 + compile + + + com.google.guava + guava + 18.0 + + + com.google.api-client + google-api-client-appengine + 1.20.0 + compile + + + guava-jdk5 + com.google.guava + + + + + com.google.http-client + google-http-client-jackson + 1.20.0 + compile + + + guava-jdk5 + com.google.guava + + + + + junit + junit + 4.12 + test + + + joda-time + joda-time + RELEASE + compile + + + org.json + json + 20090211 + compile + + + org.easymock + easymock + 3.3 + test + + + diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java new file mode 100644 index 0000000000..839da54e62 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -0,0 +1,206 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; +import com.google.api.client.googleapis.compute.ComputeCredential; +import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential; +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.http.HttpRequestInitializer; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.client.json.jackson.JacksonFactory; +import com.google.auth.http.HttpCredentialsAdapter; +import com.google.auth.oauth2.GoogleCredentials; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.security.GeneralSecurityException; +import java.security.PrivateKey; +import java.util.Objects; +import java.util.Set; + +/** + * Credentials for accessing Google Cloud services. + */ +public abstract class AuthCredentials implements Serializable { + + private static final long serialVersionUID = 236297804453464604L; + + private static class AppEngineAuthCredentials extends AuthCredentials { + + private static final long serialVersionUID = 7931300552744202954L; + + private static final AuthCredentials INSTANCE = new AppEngineAuthCredentials(); + + @Override + protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, + Set scopes) { + return new AppIdentityCredential(scopes); + } + + private Object readResolve() throws ObjectStreamException { + return INSTANCE; + } + } + + private static class ServiceAccountAuthCredentials extends AuthCredentials { + + private static final long serialVersionUID = 8007708734318445901L; + private final String account; + private final PrivateKey privateKey; + + private static final AuthCredentials NO_CREDENTIALS = new ServiceAccountAuthCredentials(); + + ServiceAccountAuthCredentials(String account, PrivateKey privateKey) { + this.account = checkNotNull(account); + this.privateKey = checkNotNull(privateKey); + } + + ServiceAccountAuthCredentials() { + account = null; + privateKey = null; + } + + @Override + protected HttpRequestInitializer httpRequestInitializer( + HttpTransport transport, Set scopes) { + GoogleCredential.Builder builder = new GoogleCredential.Builder() + .setTransport(transport) + .setJsonFactory(new JacksonFactory()); + if (privateKey != null) { + builder.setServiceAccountPrivateKey(privateKey); + builder.setServiceAccountId(account); + builder.setServiceAccountScopes(scopes); + } + return builder.build(); + } + + @Override + public int hashCode() { + return Objects.hash(account, privateKey); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ServiceAccountAuthCredentials)) { + return false; + } + ServiceAccountAuthCredentials other = (ServiceAccountAuthCredentials) obj; + return Objects.equals(account, other.account) + && Objects.equals(privateKey, other.privateKey); + } + } + + private static class ComputeEngineAuthCredentials extends AuthCredentials { + + private static final long serialVersionUID = -5217355402127260144L; + + private transient ComputeCredential computeCredential; + + ComputeEngineAuthCredentials() throws IOException, GeneralSecurityException { + computeCredential = getComputeCredential(); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + try { + computeCredential = getComputeCredential(); + } catch (GeneralSecurityException e) { + throw new IOException(e); + } + } + + @Override + protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, + Set scopes) { + return computeCredential; + } + } + + private static class ApplicationDefaultAuthCredentials extends AuthCredentials { + + private static final long serialVersionUID = -8306873864136099893L; + + private transient GoogleCredentials googleCredentials; + + ApplicationDefaultAuthCredentials() throws IOException { + googleCredentials = GoogleCredentials.getApplicationDefault(); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + googleCredentials = GoogleCredentials.getApplicationDefault(); + } + + @Override + protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, + Set scopes) { + return new HttpCredentialsAdapter(googleCredentials); + } + } + + protected abstract HttpRequestInitializer httpRequestInitializer(HttpTransport transport, + Set scopes); + + public static AuthCredentials createForAppEngine() { + return AppEngineAuthCredentials.INSTANCE; + } + + public static AuthCredentials createForComputeEngine() + throws IOException, GeneralSecurityException { + return new ComputeEngineAuthCredentials(); + } + + /** + * Returns the Application Default Credentials. + * + *

+ * Returns the Application Default Credentials which are credentials that identify and authorize + * the whole application. This is the built-in service account if running on Google Compute Engine + * or the credentials file from the path in the environment variable + * GOOGLE_APPLICATION_CREDENTIALS. + *

+ * + * @return the credentials instance. + * @throws IOException if the credentials cannot be created in the current environment. + */ + public static AuthCredentials createApplicationDefaults() throws IOException { + return new ApplicationDefaultAuthCredentials(); + } + + public static AuthCredentials createFor(String account, PrivateKey privateKey) { + return new ServiceAccountAuthCredentials(account, privateKey); + } + + public static AuthCredentials noCredentials() { + return ServiceAccountAuthCredentials.NO_CREDENTIALS; + } + + static ComputeCredential getComputeCredential() throws IOException, GeneralSecurityException { + NetHttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); + // Try to connect using Google Compute Engine service account credentials. + ComputeCredential credential = new ComputeCredential(transport, new JacksonFactory()); + // Force token refresh to detect if we are running on Google Compute Engine. + credential.refreshToken(); + return credential; + } +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java new file mode 100644 index 0000000000..4d96ac5b86 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java @@ -0,0 +1 @@ +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.gcloud; public abstract class BaseService implements Service { private final O options; protected BaseService(O options) { this.options = options; } @Override public O options() { return options; } } \ No newline at end of file diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java new file mode 100644 index 0000000000..412462ae15 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java @@ -0,0 +1,280 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static com.google.common.base.MoreObjects.firstNonNull; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.Set; +import java.util.concurrent.Callable; + +/** + * Exception handling used by {@link RetryHelper}. + */ +public final class ExceptionHandler implements Serializable { + + private static final long serialVersionUID = -2460707015779532919L; + + private static final ExceptionHandler DEFAULT_INSTANCE = + builder().retryOn(Exception.class).abortOn(RuntimeException.class).build(); + + private final ImmutableList interceptors; + private final ImmutableSet> retriableExceptions; + private final ImmutableSet> nonRetriableExceptions; + private final Set retryInfo = Sets.newHashSet(); + + public interface Interceptor extends Serializable { + + enum RetryResult { + + RETRY(true), ABORT(false); + + private final boolean booleanValue; + + RetryResult(boolean booleanValue) { + this.booleanValue = booleanValue; + } + + boolean booleanValue() { + return booleanValue; + } + } + + /** + * This method is called before exception evaluation and could short-circuit the process. + * + * @param exception the exception that is being evaluated + * @return {@link RetryResult} to indicate if the exception should be ignored ( + * {@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}), or evaluation + * should proceed ({@code null}). + */ + RetryResult beforeEval(Exception exception); + + /** + * This method is called after the evaluation and could alter its result. + * + * @param exception the exception that is being evaluated + * @param retryResult the result of the evaluation so far. + * @return {@link RetryResult} to indicate if the exception should be ignored ( + * {@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}), or evaluation + * should proceed ({@code null}). + */ + RetryResult afterEval(Exception exception, RetryResult retryResult); + } + + /** + * ExceptionHandler builder. + */ + public static class Builder { + + private final ImmutableList.Builder interceptors = ImmutableList.builder(); + private final ImmutableSet.Builder> retriableExceptions = + ImmutableSet.builder(); + private final ImmutableSet.Builder> nonRetriableExceptions = + ImmutableSet.builder(); + + private Builder() {} + + + /** + * Adds the exception handler interceptors. Call order will be maintained. + * + * @param interceptors the interceptors for this exception handler + * @return the Builder for chaining + */ + public Builder interceptor(Interceptor... interceptors) { + for (Interceptor interceptor : interceptors) { + this.interceptors.add(interceptor); + } + return this; + } + + /** + * Add the exceptions to ignore/retry-on. + * + * @param exceptions retry should continue when such exceptions are thrown + * @return the Builder for chaining + */ + @SafeVarargs + public final Builder retryOn(Class... exceptions) { + for (Class exception : exceptions) { + retriableExceptions.add(checkNotNull(exception)); + } + return this; + } + + /** + * Adds the exceptions to abort on. + * + * @param exceptions retry should abort when such exceptions are thrown + * @return the Builder for chaining + */ + @SafeVarargs + public final Builder abortOn(Class... exceptions) { + for (Class exception : exceptions) { + nonRetriableExceptions.add(checkNotNull(exception)); + } + return this; + } + + /** + * Returns a new ExceptionHandler instance. + */ + public ExceptionHandler build() { + return new ExceptionHandler(this); + } + } + + @VisibleForTesting + static final class RetryInfo implements Serializable { + + private static final long serialVersionUID = -4264634837841455974L; + private final Class exception; + private final Interceptor.RetryResult retry; + private final Set children = Sets.newHashSet(); + + RetryInfo(Class exception, Interceptor.RetryResult retry) { + this.exception = checkNotNull(exception); + this.retry = retry; + } + + @Override + public int hashCode() { + return exception.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof RetryInfo)) { + return false; + } + // We only care about exception in equality as we allow only one instance per exception + return ((RetryInfo) obj).exception.equals(exception); + } + } + + private ExceptionHandler(Builder builder) { + interceptors = builder.interceptors.build(); + retriableExceptions = builder.retriableExceptions.build(); + nonRetriableExceptions = builder.nonRetriableExceptions.build(); + Preconditions.checkArgument( + Sets.intersection(retriableExceptions, nonRetriableExceptions).isEmpty(), + "Same exception was found in both retryable and non-retryable sets"); + for (Class exception : retriableExceptions) { + addRetryInfo(new RetryInfo(exception, Interceptor.RetryResult.RETRY), retryInfo); + } + for (Class exception : nonRetriableExceptions) { + addRetryInfo(new RetryInfo(exception, Interceptor.RetryResult.ABORT), retryInfo); + } + } + + private static void addRetryInfo(RetryInfo retryInfo, Set dest) { + for (RetryInfo current : dest) { + if (current.exception.isAssignableFrom(retryInfo.exception)) { + addRetryInfo(retryInfo, current.children); + return; + } + if (retryInfo.exception.isAssignableFrom(current.exception)) { + retryInfo.children.add(current); + } + } + dest.removeAll(retryInfo.children); + dest.add(retryInfo); + } + + private static RetryInfo findMostSpecificRetryInfo(Set retryInfo, + Class exception) { + for (RetryInfo current : retryInfo) { + if (current.exception.isAssignableFrom(exception)) { + RetryInfo match = findMostSpecificRetryInfo(current.children, exception); + return match == null ? current : match; + } + } + return null; + } + + // called for Class, therefore a "call" method must be found. + private static Method getCallableMethod(Class clazz) { + try { + return clazz.getDeclaredMethod("call"); + } catch (NoSuchMethodException e) { + // check parent + return getCallableMethod(clazz.getSuperclass()); + } catch (SecurityException e) { + // This should never happen + throw new IllegalStateException("Unexpected exception", e); + } + } + + void verifyCaller(Callable callable) { + Method callMethod = getCallableMethod(callable.getClass()); + for (Class exceptionOrError : callMethod.getExceptionTypes()) { + Preconditions.checkArgument(Exception.class.isAssignableFrom(exceptionOrError), + "Callable method exceptions must be derived from Exception"); + @SuppressWarnings("unchecked") + Class exception = (Class) exceptionOrError; + Preconditions.checkArgument(findMostSpecificRetryInfo(retryInfo, exception) != null, + "Declared exception '" + exception + "' is not covered by exception handler"); + } + } + + public Set> getRetriableExceptions() { + return retriableExceptions; + } + + public Set> getNonRetriableExceptions() { + return nonRetriableExceptions; + } + + boolean shouldRetry(Exception ex) { + for (Interceptor interceptor : interceptors) { + Interceptor.RetryResult retryResult = interceptor.beforeEval(ex); + if (retryResult != null) { + return retryResult.booleanValue(); + } + } + RetryInfo retryInfo = findMostSpecificRetryInfo(this.retryInfo, ex.getClass()); + Interceptor.RetryResult retryResult = + retryInfo == null ? Interceptor.RetryResult.ABORT : retryInfo.retry; + for (Interceptor interceptor : interceptors) { + retryResult = firstNonNull(interceptor.afterEval(ex, retryResult), retryResult); + } + return retryResult.booleanValue(); + } + + /** + * Returns an instance which retry any checked exception and abort on any runtime exception. + */ + public static ExceptionHandler getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + public static Builder builder() { + return new Builder(); + } +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java new file mode 100644 index 0000000000..7b47209cd3 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java @@ -0,0 +1,252 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static com.google.common.base.Preconditions.checkNotNull; +import static java.lang.StrictMath.max; +import static java.lang.StrictMath.min; +import static java.lang.StrictMath.pow; +import static java.lang.StrictMath.random; +import static java.util.concurrent.TimeUnit.MILLISECONDS; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Stopwatch; + +import java.io.InterruptedIOException; +import java.nio.channels.ClosedByInterruptException; +import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Utility class for retrying operations. For more details about the parameters, see + * {@link RetryParams}. If the request is never successful, a {@link RetriesExhaustedException} will + * be thrown. + * + * @param return value of the closure that is being run with retries + */ +public class RetryHelper { + + private static final Logger log = Logger.getLogger(RetryHelper.class.getName()); + + private final Stopwatch stopwatch; + private final Callable callable; + private final RetryParams params; + private final ExceptionHandler exceptionHandler; + private int attemptNumber; + + + private static final ThreadLocal context = new ThreadLocal<>(); + + public static class RetryHelperException extends RuntimeException { + + private static final long serialVersionUID = -2907061015610448235L; + + RetryHelperException() {} + + RetryHelperException(String message) { + super(message); + } + + RetryHelperException(Throwable cause) { + super(cause); + } + + RetryHelperException(String message, Throwable cause) { + super(message, cause); + } + } + + /** + * Thrown when a RetryHelper failed to complete its work due to interruption. Throwing this + * exception also sets the thread interrupt flag. + */ + public static final class RetryInterruptedException extends RetryHelperException { + + private static final long serialVersionUID = 1678966737697204885L; + + RetryInterruptedException() {} + + /** + * Sets the caller thread interrupt flag and throws {@code RetryInterruptedException}. + */ + public static void propagate() throws RetryInterruptedException { + Thread.currentThread().interrupt(); + throw new RetryInterruptedException(); + } + } + + /** + * Thrown when a RetryHelper has attempted the maximum number of attempts allowed by RetryParams + * and was not successful. + */ + public static final class RetriesExhaustedException extends RetryHelperException { + + private static final long serialVersionUID = 780199686075408083L; + + RetriesExhaustedException(String message) { + super(message); + } + + RetriesExhaustedException(String message, Throwable cause) { + super(message, cause); + } + } + + /** + * Thrown when RetryHelper callable has indicate it should not be retried. + */ + public static final class NonRetriableException extends RetryHelperException { + + private static final long serialVersionUID = -2331878521983499652L; + + NonRetriableException(Throwable throwable) { + super(throwable); + } + } + + static class Context { + + private final RetryHelper helper; + + Context(RetryHelper helper) { + this.helper = helper; + } + + public RetryParams getRetryParams() { + return helper.params; + } + + public int getAttemptNumber() { + return helper.attemptNumber; + } + } + + @VisibleForTesting + static void setContext(Context ctx) { + if (ctx == null) { + context.remove(); + } else { + context.set(ctx); + } + } + + static Context getContext() { + return context.get(); + } + + @VisibleForTesting + RetryHelper(Callable callable, RetryParams params, ExceptionHandler exceptionHandler, + Stopwatch stopwatch) { + this.callable = checkNotNull(callable); + this.params = checkNotNull(params); + this.stopwatch = checkNotNull(stopwatch); + this.exceptionHandler = checkNotNull(exceptionHandler); + exceptionHandler.verifyCaller(callable); + } + + @Override + public String toString() { + ToStringHelper toStringHelper = MoreObjects.toStringHelper(this); + toStringHelper.add("params", params); + toStringHelper.add("stopwatch", stopwatch); + toStringHelper.add("attemptNumber", attemptNumber); + toStringHelper.add("callable", callable); + toStringHelper.add("exceptionHandler", exceptionHandler); + return toStringHelper.toString(); + } + + private V doRetry() throws RetryHelperException { + stopwatch.start(); + while (true) { + attemptNumber++; + Exception exception; + try { + V value = callable.call(); + if (attemptNumber > 1 && log.isLoggable(Level.FINE)) { + log.fine(this + ": attempt #" + attemptNumber + " succeeded"); + } + return value; + } catch (InterruptedException | InterruptedIOException | ClosedByInterruptException e) { + if (!exceptionHandler.shouldRetry(e)) { + RetryInterruptedException.propagate(); + } + exception = e; + } catch (Exception e) { + if (!exceptionHandler.shouldRetry(e)) { + throw new NonRetriableException(e); + } + exception = e; + } + if (attemptNumber >= params.getRetryMaxAttempts() + || attemptNumber >= params.getRetryMinAttempts() + && stopwatch.elapsed(MILLISECONDS) >= params.getTotalRetryPeriodMillis()) { + throw new RetriesExhaustedException(this + ": Too many failures, giving up", exception); + } + long sleepDurationMillis = getSleepDuration(params, attemptNumber); + if (log.isLoggable(Level.FINE)) { + log.fine(this + ": Attempt #" + attemptNumber + " failed [" + exception + + "], sleeping for " + sleepDurationMillis + " ms"); + } + try { + Thread.sleep(sleepDurationMillis); + } catch (InterruptedException e) { + // propagate as RetryInterruptedException + RetryInterruptedException.propagate(); + } + } + } + + @VisibleForTesting + static long getSleepDuration(RetryParams retryParams, int attemptsSoFar) { + long initialDelay = retryParams.getInitialRetryDelayMillis(); + double backoffFactor = retryParams.getRetryDelayBackoffFactor(); + long maxDelay = retryParams.getMaxRetryDelayMillis(); + long retryDelay = getExponentialValue(initialDelay, backoffFactor, maxDelay, attemptsSoFar); + return (long) ((random() / 2.0 + .75) * retryDelay); + } + + private static long getExponentialValue(long initialDelay, double backoffFactor, long maxDelay, + int attemptsSoFar) { + return (long) min(maxDelay, pow(backoffFactor, max(1, attemptsSoFar) - 1) * initialDelay); + } + + public static V runWithRetries(Callable callable) throws RetryHelperException { + return runWithRetries(callable, RetryParams.getDefaultInstance(), + ExceptionHandler.getDefaultInstance()); + } + + public static V runWithRetries(Callable callable, RetryParams params, + ExceptionHandler exceptionHandler) throws RetryHelperException { + return runWithRetries(callable, params, exceptionHandler, Stopwatch.createUnstarted()); + } + + @VisibleForTesting + static V runWithRetries(Callable callable, RetryParams params, + ExceptionHandler exceptionHandler, Stopwatch stopwatch) throws RetryHelperException { + RetryHelper retryHelper = new RetryHelper<>(callable, params, exceptionHandler, stopwatch); + Context previousContext = getContext(); + setContext(new Context(retryHelper)); + try { + return retryHelper.doRetry(); + } finally { + setContext(previousContext); + } + } +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java b/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java new file mode 100644 index 0000000000..0d38aea77a --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java @@ -0,0 +1,292 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; + +import java.io.Serializable; +import java.util.Objects; + +/** + * Parameters for configuring retries with an exponential backoff. Initial request is executed + * immediately. If the request fails but passes the {@link ExceptionHandler} criteria the calling + * thread sleeps for {@code initialRetryDelayMillis}. Each subsequent failure the sleep interval is + * calculated as: + *

+ * {@code retryDelayBackoffFactor ^ attempts * initialRetryDelayMillis} but would be upper-bounded + * to {@code maxRetryDelayMillis} + *

+ * This proceeds until either the request is successful, {@code retryMaxAttempts} are made, or both + * {@code retryMinAttempts} are made and {@code totalRetryPeriodMillis} have elapsed. To construct + * {@code RetryParams}, first create a {@link RetryParams.Builder}. The builder is mutable and each + * of the parameters can be set (any unset parameters will fallback to the defaults). The + * {@code Builder} can be then used to create an immutable {@code RetryParams} object. For default + * {@code RetryParams} use {@link #getDefaultInstance}. Default settings are subject to change + * release to release. If you require specific settings, explicitly create an instance of + * {@code RetryParams} with all the required settings. + * + * @see RetryHelper + */ +public final class RetryParams implements Serializable { + + private static final long serialVersionUID = -8492751576749007700L; + + public static final int DEFAULT_RETRY_MIN_ATTEMPTS = 3; + public static final int DEFAULT_RETRY_MAX_ATTEMPTS = 6; + public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 250L; + public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 10_000L; + public static final double DEFAULT_RETRY_DELAY_BACKOFF_FACTOR = 2.0; + public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L; + + private final int retryMinAttempts; + private final int retryMaxAttempts; + private final long initialRetryDelayMillis; + private final long maxRetryDelayMillis; + private final double retryDelayBackoffFactor; + private final long totalRetryPeriodMillis; + + private static final RetryParams DEFAULT_INSTANCE = new RetryParams(new Builder()); + private static final RetryParams NO_RETRIES = + builder().retryMaxAttempts(1).retryMinAttempts(1).build(); + + + /** + * RetryParams builder. + */ + public static final class Builder { + + private int retryMinAttempts; + private int retryMaxAttempts; + private long initialRetryDelayMillis; + private long maxRetryDelayMillis; + private double retryDelayBackoffFactor; + private long totalRetryPeriodMillis; + + private Builder() { + this(null); + } + + Builder(/* Nullable */RetryParams retryParams) { + if (retryParams == null) { + retryMinAttempts = DEFAULT_RETRY_MIN_ATTEMPTS; + retryMaxAttempts = DEFAULT_RETRY_MAX_ATTEMPTS; + initialRetryDelayMillis = DEFAULT_INITIAL_RETRY_DELAY_MILLIS; + maxRetryDelayMillis = DEFAULT_MAX_RETRY_DELAY_MILLIS; + retryDelayBackoffFactor = DEFAULT_RETRY_DELAY_BACKOFF_FACTOR; + totalRetryPeriodMillis = DEFAULT_TOTAL_RETRY_PERIOD_MILLIS; + } else { + retryMinAttempts = retryParams.getRetryMinAttempts(); + retryMaxAttempts = retryParams.getRetryMaxAttempts(); + initialRetryDelayMillis = retryParams.getInitialRetryDelayMillis(); + maxRetryDelayMillis = retryParams.getMaxRetryDelayMillis(); + retryDelayBackoffFactor = retryParams.getRetryDelayBackoffFactor(); + totalRetryPeriodMillis = retryParams.getTotalRetryPeriodMillis(); + } + } + + /** + * Sets retryMinAttempts. + * + * @param retryMinAttempts the retryMinAttempts to set + * @return the Builder for chaining + */ + public Builder retryMinAttempts(int retryMinAttempts) { + this.retryMinAttempts = retryMinAttempts; + return this; + } + + /** + * Sets retryMaxAttempts. + * + * @param retryMaxAttempts the retryMaxAttempts to set + * @return the Builder for chaining + */ + public Builder retryMaxAttempts(int retryMaxAttempts) { + this.retryMaxAttempts = retryMaxAttempts; + return this; + } + + /** + * Sets initialRetryDelayMillis. + * + * @param initialRetryDelayMillis the initialRetryDelayMillis to set + * @return the Builder for chaining + */ + public Builder initialRetryDelayMillis(long initialRetryDelayMillis) { + this.initialRetryDelayMillis = initialRetryDelayMillis; + return this; + } + + /** + * Sets maxRetryDelayMillis. + * + * @param maxRetryDelayMillis the maxRetryDelayMillis to set + * @return the Builder for chaining + */ + public Builder maxRetryDelayMillis(long maxRetryDelayMillis) { + this.maxRetryDelayMillis = maxRetryDelayMillis; + return this; + } + + /** + * Sets retryDelayBackoffFactor. + * + * @param retryDelayBackoffFactor the retryDelayBackoffFactor to set + * @return the Builder for chaining + */ + public Builder retryDelayBackoffFactor(double retryDelayBackoffFactor) { + this.retryDelayBackoffFactor = retryDelayBackoffFactor; + return this; + } + + /** + * Sets totalRetryPeriodMillis. + * + * @param totalRetryPeriodMillis the totalRetryPeriodMillis to set + * @return the Builder for chaining + */ + public Builder totalRetryPeriodMillis(long totalRetryPeriodMillis) { + this.totalRetryPeriodMillis = totalRetryPeriodMillis; + return this; + } + + /** + * Create an instance of RetryParams with the parameters set in this builder. + * + * @return a new instance of RetryParams + */ + public RetryParams build() { + return new RetryParams(this); + } + } + + /** + * Create a new RetryParams with the parameters from a {@link RetryParams.Builder} + * + * @param builder the parameters to use to construct the RetryParams object + */ + private RetryParams(Builder builder) { + retryMinAttempts = builder.retryMinAttempts; + retryMaxAttempts = builder.retryMaxAttempts; + initialRetryDelayMillis = builder.initialRetryDelayMillis; + maxRetryDelayMillis = builder.maxRetryDelayMillis; + retryDelayBackoffFactor = builder.retryDelayBackoffFactor; + totalRetryPeriodMillis = builder.totalRetryPeriodMillis; + checkArgument(retryMinAttempts >= 0, "retryMinAttempts must not be negative"); + checkArgument(retryMaxAttempts >= retryMinAttempts, + "retryMaxAttempts must not be smaller than retryMinAttempts"); + checkArgument(initialRetryDelayMillis >= 0, "initialRetryDelayMillis must not be negative"); + checkArgument(maxRetryDelayMillis >= initialRetryDelayMillis, + "maxRetryDelayMillis must not be smaller than initialRetryDelayMillis"); + checkArgument(retryDelayBackoffFactor >= 0, "retryDelayBackoffFactor must not be negative"); + checkArgument(totalRetryPeriodMillis >= 0, "totalRetryPeriodMillis must not be negative"); + } + + /** + * Returns an instance with the default parameters. + */ + public static RetryParams getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + public static RetryParams noRetries() { + return NO_RETRIES; + } + + /** + * Returns the retryMinAttempts. + */ + public int getRetryMinAttempts() { + return retryMinAttempts; + } + + /** + * Returns the retryMaxAttempts. + */ + public int getRetryMaxAttempts() { + return retryMaxAttempts; + } + + /** + * Returns the initialRetryDelayMillis. + */ + public long getInitialRetryDelayMillis() { + return initialRetryDelayMillis; + } + + /** + * Returns the maxRetryDelayMillis. + */ + public long getMaxRetryDelayMillis() { + return maxRetryDelayMillis; + } + + /** + * Returns the maxRetryDelayBackoffFactor. + */ + public double getRetryDelayBackoffFactor() { + return retryDelayBackoffFactor; + } + + /** + * Returns the totalRetryPeriodMillis. + */ + public long getTotalRetryPeriodMillis() { + return totalRetryPeriodMillis; + } + + @Override + public int hashCode() { + return Objects.hash(retryMinAttempts, retryMaxAttempts, initialRetryDelayMillis, + maxRetryDelayMillis, retryDelayBackoffFactor, totalRetryPeriodMillis); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof RetryParams)) { + return false; + } + RetryParams other = (RetryParams) obj; + return retryMinAttempts == other.retryMinAttempts && retryMaxAttempts == other.retryMaxAttempts + && initialRetryDelayMillis == other.initialRetryDelayMillis + && maxRetryDelayMillis == other.maxRetryDelayMillis + && retryDelayBackoffFactor == other.retryDelayBackoffFactor + && totalRetryPeriodMillis == other.totalRetryPeriodMillis; + } + + @Override + public String toString() { + ToStringHelper toStringHelper = MoreObjects.toStringHelper(this); + toStringHelper.add("retryMinAttempts", retryMinAttempts); + toStringHelper.add("retryMaxAttempts", retryMaxAttempts); + toStringHelper.add("initialRetryDelayMillis", initialRetryDelayMillis); + toStringHelper.add("maxRetryDelayMillis", maxRetryDelayMillis); + toStringHelper.add("retryDelayBackoffFactor", retryDelayBackoffFactor); + toStringHelper.add("totalRetryPeriodMillis", totalRetryPeriodMillis); + return toStringHelper.toString(); + } + + public static Builder builder() { + return new Builder(); + } +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Service.java b/google-cloud-core/src/main/java/com/google/gcloud/Service.java new file mode 100644 index 0000000000..02d810186b --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/Service.java @@ -0,0 +1 @@ +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.gcloud; public interface Service { O options(); } \ No newline at end of file diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java new file mode 100644 index 0000000000..448b617372 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -0,0 +1,314 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + + +import static com.google.common.base.MoreObjects.firstNonNull; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.nio.charset.StandardCharsets.UTF_8; + +import com.google.api.client.extensions.appengine.http.UrlFetchTransport; +import com.google.api.client.http.HttpRequestInitializer; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.gcloud.spi.ServiceRpcFactory; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Serializable; +import java.lang.reflect.Method; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Locale; +import java.util.Objects; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public abstract class ServiceOptions> implements Serializable { + + private static final String DEFAULT_HOST = "https://www.googleapis.com"; + private static final long serialVersionUID = 1203687993961393350L; + private static final String PROJECT_ENV_NAME = "default_project_id"; + + private final String projectId; + private final String host; + private final HttpTransportFactory httpTransportFactory; + private final AuthCredentials authCredentials; + private final RetryParams retryParams; + private final ServiceRpcFactory serviceRpcFactory; + + public interface HttpTransportFactory extends Serializable { + HttpTransport create(); + } + + private enum DefaultHttpTransportFactory implements HttpTransportFactory { + + INSTANCE; + + @Override + public HttpTransport create() { + // Consider App Engine + if (appEngineAppId() != null) { + try { + return new UrlFetchTransport(); + } catch (Exception ignore) { + // Maybe not on App Engine + } + } + // Consider Compute + try { + return AuthCredentials.getComputeCredential().getTransport(); + } catch (Exception e) { + // Maybe not on GCE + } + return new NetHttpTransport(); + } + } + + + + protected abstract static class Builder, + B extends Builder> { + + private String projectId; + private String host; + private HttpTransportFactory httpTransportFactory; + private AuthCredentials authCredentials; + private RetryParams retryParams; + private ServiceRpcFactory serviceRpcFactory; + + protected Builder() {} + + protected Builder(ServiceOptions options) { + projectId = options.projectId; + host = options.host; + httpTransportFactory = options.httpTransportFactory; + authCredentials = options.authCredentials; + retryParams = options.retryParams; + serviceRpcFactory = options.serviceRpcFactory; + } + + protected abstract ServiceOptions build(); + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + + public B projectId(String projectId) { + this.projectId = projectId; + return self(); + } + + public B host(String host) { + this.host = host; + return self(); + } + + public B httpTransportFactory(HttpTransportFactory httpTransportFactory) { + this.httpTransportFactory = httpTransportFactory; + return self(); + } + + public B authCredentials(AuthCredentials authCredentials) { + this.authCredentials = authCredentials; + return self(); + } + + public B retryParams(RetryParams retryParams) { + this.retryParams = retryParams; + return self(); + } + + public B serviceRpcFactory(ServiceRpcFactory serviceRpcFactory) { + this.serviceRpcFactory = serviceRpcFactory; + return self(); + } + } + + protected ServiceOptions(Builder builder) { + projectId = checkNotNull(builder.projectId != null ? builder.projectId : defaultProject()); + host = firstNonNull(builder.host, DEFAULT_HOST); + httpTransportFactory = + firstNonNull(builder.httpTransportFactory, DefaultHttpTransportFactory.INSTANCE); + authCredentials = firstNonNull(builder.authCredentials, defaultAuthCredentials()); + retryParams = builder.retryParams; + serviceRpcFactory = builder.serviceRpcFactory; + } + + private static AuthCredentials defaultAuthCredentials() { + // Consider App Engine. This will not be needed once issue #21 is fixed. + if (appEngineAppId() != null) { + try { + return AuthCredentials.createForAppEngine(); + } catch (Exception ignore) { + // Maybe not on App Engine + } + } + + try { + return AuthCredentials.createApplicationDefaults(); + } catch (Exception ex) { + // fallback to old-style + } + + // Consider old-style Compute. This will not be needed once issue #21 is fixed. + try { + return AuthCredentials.createForComputeEngine(); + } catch (Exception ignore) { + // Maybe not on GCE + } + return AuthCredentials.noCredentials(); + } + + protected static String appEngineAppId() { + return System.getProperty("com.google.appengine.application.id"); + } + + protected String defaultProject() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = getAppEngineProjectId(); + } + return projectId != null ? projectId : googleCloudProjectId(); + } + + protected static String googleCloudProjectId() { + try { + URL url = new URL("http://metadata/computeMetadata/v1/project/project-id"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestProperty("X-Google-Metadata-Request", "True"); + InputStream input = connection.getInputStream(); + if (connection.getResponseCode() == 200) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, UTF_8))) { + return reader.readLine(); + } + } + } catch (IOException ignore) { + // ignore + } + File configDir; + if (System.getenv().containsKey("CLOUDSDK_CONFIG")) { + configDir = new File(System.getenv("CLOUDSDK_CONFIG")); + } else if (isWindows() && System.getenv().containsKey("APPDATA")) { + configDir = new File(System.getenv("APPDATA"), "gcloud"); + } else { + configDir = new File(System.getProperty("user.home"), ".config/gcloud"); + } + try (BufferedReader reader = + new BufferedReader(new FileReader(new File(configDir, "properties")))) { + String line; + String section = null; + Pattern projectPattern = Pattern.compile("^project\\s*=\\s*(.*)$"); + Pattern sectionPattern = Pattern.compile("^\\[(.*)\\]$"); + while((line = reader.readLine()) != null) { + if (line.isEmpty() || line.startsWith(";")) { + continue; + } + line = line.trim(); + Matcher matcher = sectionPattern.matcher(line); + if (matcher.matches()) { + section = matcher.group(1); + } else if (section == null || section.equals("core")) { + matcher = projectPattern.matcher(line); + if (matcher.matches()) { + return matcher.group(1); + } + } + } + } catch (IOException ex) { + // ignore + } + // return null if can't determine + return null; + } + + private static boolean isWindows() { + return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).indexOf("windows") > -1; + } + + protected static String getAppEngineProjectId() { + // TODO(ozarov): An alternative to reflection would be to depend on AE api jar: + // http://mvnrepository.com/artifact/com.google.appengine/appengine-api-1.0-sdk/1.2.0 + try { + Class factoryClass = + Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory"); + Method method = factoryClass.getMethod("getAppIdentityService"); + Object appIdentityService = method.invoke(null); + method = appIdentityService.getClass().getMethod("getServiceAccountName"); + String serviceAccountName = (String) method.invoke(appIdentityService); + int indexOfAtSign = serviceAccountName.indexOf('@'); + return serviceAccountName.substring(0, indexOfAtSign); + } catch (Exception ignore) { + // return null if can't determine + return null; + } + } + + protected abstract Set scopes(); + + public String projectId() { + return projectId; + } + + public String host() { + return host; + } + + public HttpTransportFactory httpTransportFactory() { + return httpTransportFactory; + } + + public AuthCredentials authCredentials() { + return authCredentials; + } + + public RetryParams retryParams() { + return retryParams != null ? retryParams : RetryParams.noRetries(); + } + + public ServiceRpcFactory serviceRpcFactory() { + return serviceRpcFactory; + } + + public HttpRequestInitializer httpRequestInitializer() { + HttpTransport httpTransport = httpTransportFactory.create(); + return authCredentials().httpRequestInitializer(httpTransport, scopes()); + } + + @Override + public int hashCode() { + return Objects.hash(projectId, host, httpTransportFactory, authCredentials, retryParams, + serviceRpcFactory); + } + + protected boolean isEquals(ServiceOptions other) { + return Objects.equals(projectId, other.projectId) + && Objects.equals(host, other.host) + && Objects.equals(httpTransportFactory, other.httpTransportFactory) + && Objects.equals(authCredentials, other.authCredentials) + && Objects.equals(retryParams, other.retryParams) + && Objects.equals(serviceRpcFactory, other.serviceRpcFactory); + } + + public abstract Builder toBuilder(); +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java new file mode 100644 index 0000000000..a16d11217b --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java @@ -0,0 +1 @@ +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.gcloud.spi; import com.google.gcloud.ServiceOptions; import java.io.Serializable; public interface ServiceRpcFactory extends Serializable { S create(O options); } \ No newline at end of file diff --git a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcProvider.java b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcProvider.java new file mode 100644 index 0000000000..41a2bf2d58 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcProvider.java @@ -0,0 +1,32 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud.spi; + +import com.google.common.collect.Iterables; +import com.google.gcloud.ServiceOptions; + +import java.util.ServiceLoader; + +public class ServiceRpcProvider { + + public static > R get(O options, + Class> factoryClass) { + ServiceRpcFactory factory = Iterables.getFirst(ServiceLoader.load(factoryClass), null); + return factory == null ? null : factory.create(options); + } +} + diff --git a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java new file mode 100644 index 0000000000..3844f9de36 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java @@ -0,0 +1,168 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.google.gcloud.ExceptionHandler.Interceptor; +import com.google.gcloud.ExceptionHandler.Interceptor.RetryResult; + +import org.junit.Test; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.channels.ClosedByInterruptException; +import java.util.concurrent.Callable; +import java.util.concurrent.atomic.AtomicReference; + +/** + * Tests for {@link ExceptionHandler}. + */ +public class ExceptionHandlerTest { + + @Test + public void testVerifyCaller() { + class A implements Callable { + @Override + public Object call() throws IOException, InterruptedException { + return null; + } + } + + class B extends A { + } + + class C extends A { + @Override + public Object call() throws FileNotFoundException { + return "c"; + } + } + + class D extends C { + @Override + public Object call() throws IllegalArgumentException { + return "d"; + } + } + + class E extends A { + @Override + public String call() throws NullPointerException { + return "e"; + } + } + + class F extends A { + @Override + public Object call() throws Error { + return "f"; + } + } + + // using default exception handler (retry upon any non-runtime exceptions) + ExceptionHandler handler = ExceptionHandler.getDefaultInstance(); + assertValidCallable(new A(), handler); + assertValidCallable(new B(), handler); + assertValidCallable(new C(), handler); + assertValidCallable(new D(), handler); + assertValidCallable(new E(), handler); + assertInvalidCallable(new F(), handler); + + handler = ExceptionHandler.builder() + .retryOn(FileNotFoundException.class, NullPointerException.class) + .build(); + assertInvalidCallable(new A(), handler); + assertInvalidCallable(new B(), handler); + assertValidCallable(new C(), handler); + assertInvalidCallable(new D(), handler); + assertValidCallable(new E(), handler); + assertInvalidCallable(new F(), handler); + } + + private static void assertValidCallable(Callable callable, ExceptionHandler handler) { + handler.verifyCaller(callable); + } + + private static void assertInvalidCallable(Callable callable, ExceptionHandler handler) { + try { + handler.verifyCaller(callable); + fail("Expected RetryHelper constructor to fail"); + } catch (IllegalArgumentException ex) { + // expected + } + } + + @Test + public void testShouldTry() { + ExceptionHandler handler = ExceptionHandler.builder().retryOn(IOException.class).build(); + assertTrue(handler.shouldRetry(new IOException())); + assertTrue(handler.shouldRetry(new ClosedByInterruptException())); + assertFalse(handler.shouldRetry(new RuntimeException())); + + ExceptionHandler.Builder builder = ExceptionHandler.builder() + .retryOn(IOException.class, NullPointerException.class) + .abortOn(RuntimeException.class, ClosedByInterruptException.class, + InterruptedException.class); + + handler = builder.build(); + assertTrue(handler.shouldRetry(new IOException())); + assertFalse(handler.shouldRetry(new ClosedByInterruptException())); + assertFalse(handler.shouldRetry(new InterruptedException())); + assertFalse(handler.shouldRetry(new RuntimeException())); + assertTrue(handler.shouldRetry(new NullPointerException())); + + final AtomicReference before = new AtomicReference<>(RetryResult.ABORT); + @SuppressWarnings("serial") + Interceptor interceptor = new Interceptor() { + + @Override + public RetryResult afterEval(Exception exception, RetryResult retryResult) { + return retryResult == RetryResult.ABORT ? RetryResult.RETRY : RetryResult.ABORT; + } + + @Override + public RetryResult beforeEval(Exception exception) { + return before.get(); + } + }; + + builder.interceptor(interceptor); + handler = builder.build(); + assertFalse(handler.shouldRetry(new IOException())); + assertFalse(handler.shouldRetry(new ClosedByInterruptException())); + assertFalse(handler.shouldRetry(new InterruptedException())); + assertFalse(handler.shouldRetry(new RuntimeException())); + assertFalse(handler.shouldRetry(new NullPointerException())); + + before.set(RetryResult.RETRY); + assertTrue(handler.shouldRetry(new IOException())); + assertTrue(handler.shouldRetry(new ClosedByInterruptException())); + assertTrue(handler.shouldRetry(new InterruptedException())); + assertTrue(handler.shouldRetry(new RuntimeException())); + assertTrue(handler.shouldRetry(new NullPointerException())); + + before.set(null); + assertFalse(handler.shouldRetry(new IOException())); + assertTrue(handler.shouldRetry(new ClosedByInterruptException())); + assertTrue(handler.shouldRetry(new InterruptedException())); + assertTrue(handler.shouldRetry(new RuntimeException())); + assertFalse(handler.shouldRetry(new NullPointerException())); + } +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java b/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java new file mode 100644 index 0000000000..dfd933bcae --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java @@ -0,0 +1,263 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static java.util.concurrent.Executors.callable; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.google.common.base.Stopwatch; +import com.google.common.base.Ticker; +import com.google.gcloud.RetryHelper.NonRetriableException; +import com.google.gcloud.RetryHelper.RetriesExhaustedException; + +import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Iterator; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + +/** + * Tests for {@link RetryHelper}. + */ +public class RetryHelperTest { + + static class E1Exception extends Exception { + private static final long serialVersionUID = 3874933713392137001L; + } + + static class E2Exception extends E1Exception { + private static final long serialVersionUID = -8710227162480133598L; + } + + static class E3Exception extends E1Exception { + private static final long serialVersionUID = -7794256022024001666L; + } + + static class E4Exception extends E2Exception { + private static final long serialVersionUID = -5508018234693709156L; + } + + @Test + public void testTriesWithExceptionHandling() { + assertNull(RetryHelper.getContext()); + RetryParams params = + RetryParams.builder().initialRetryDelayMillis(0).retryMaxAttempts(3).build(); + ExceptionHandler handler = ExceptionHandler.builder() + .retryOn(IOException.class).abortOn(RuntimeException.class).build(); + final AtomicInteger count = new AtomicInteger(3); + try { + RetryHelper.runWithRetries(new Callable() { + @Override public Void call() throws IOException, NullPointerException { + if (count.decrementAndGet() == 2) { + assertEquals(1, RetryHelper.getContext().getAttemptNumber()); + throw new IOException("should be retried"); + } + assertEquals(2, RetryHelper.getContext().getAttemptNumber()); + throw new NullPointerException("Boo!"); + } + }, params, handler); + fail("Exception should have been thrown"); + } catch (NonRetriableException ex) { + assertEquals("Boo!", ex.getCause().getMessage()); + assertEquals(1, count.intValue()); + } + assertNull(RetryHelper.getContext()); + + params = RetryParams.builder().initialRetryDelayMillis(0).retryMaxAttempts(5).build(); + handler = ExceptionHandler.builder() + .retryOn(E1Exception.class, E4Exception.class) + .abortOn(E3Exception.class).build(); + final Iterator exceptions = Arrays.asList( + new E1Exception(), new E2Exception(), new E4Exception(), new E3Exception()).iterator(); + try { + RetryHelper.runWithRetries(new Callable() { + @Override public Void call() throws E1Exception { + throw exceptions.next(); + } + }, params, handler); + fail("Exception should have been thrown"); + } catch (NonRetriableException ex) { + assertTrue(ex.getCause() instanceof E3Exception); + } + assertNull(RetryHelper.getContext()); + } + + @Test + public void testTriesAtLeastMinTimes() { + // Total retry period set to 60 seconds so as to not factor into test + RetryParams params = RetryParams.builder().initialRetryDelayMillis(0) + .totalRetryPeriodMillis(60000) + .retryMinAttempts(5) + .retryMaxAttempts(10) + .build(); + final int timesToFail = 7; + assertNull(RetryHelper.getContext()); + int attempted = RetryHelper.runWithRetries(new Callable() { + int timesCalled; + @Override public Integer call() throws IOException { + timesCalled++; + assertEquals(timesCalled, RetryHelper.getContext().getAttemptNumber()); + assertEquals(10, RetryHelper.getContext().getRetryParams().getRetryMaxAttempts()); + if (timesCalled <= timesToFail) { + throw new IOException(); + } + return timesCalled; + } + }, params, ExceptionHandler.getDefaultInstance()); + assertEquals(timesToFail + 1, attempted); + assertNull(RetryHelper.getContext()); + } + + @Test + public void testTriesNoMoreThanMaxTimes() { + // Total retry period set to 60 seconds so as to not factor into test + final int maxAttempts = 10; + RetryParams params = RetryParams.builder().initialRetryDelayMillis(0) + .totalRetryPeriodMillis(60000) + .retryMinAttempts(0) + .retryMaxAttempts(maxAttempts) + .build(); + final AtomicInteger timesCalled = new AtomicInteger(0); + try { + RetryHelper.runWithRetries(callable(new Runnable() { + @Override public void run() { + // Throw an exception up to maxAttempts times, should never be called beyond that + if (timesCalled.incrementAndGet() <= maxAttempts) { + throw new RuntimeException(); + } + fail("Body was executed too many times: " + timesCalled.get()); + } + }), params, ExceptionHandler.builder().retryOn(RuntimeException.class).build()); + // Unnecessary as this line should not be possible reach even if RetryHandler is broken + fail("Should not have succeeded, expected all attempts to fail and give up."); + } catch (RetriesExhaustedException expected) { + // Expect the body to run exactly maxAttempts times + assertEquals(maxAttempts, timesCalled.get()); + } + } + + private static class FakeTicker extends Ticker { + private final AtomicLong nanos = new AtomicLong(); + + // Advances the ticker value by {@code time} in {@code timeUnit}. + void advance(long time, TimeUnit timeUnit) { + nanos.addAndGet(timeUnit.toNanos(time)); + } + + @Override + public long read() { + return nanos.get(); + } + } + + @Test + public void testTriesNoMoreLongerThanTotalRetryPeriod() { + final FakeTicker ticker = new FakeTicker(); + Stopwatch stopwatch = Stopwatch.createUnstarted(ticker); + // The 8th attempt (after min and before max) will trigger a 1 second (virtual) delay exceeding + // total retry period which is set just under 1 second. Test occurs faster than realtime. + RetryParams params = RetryParams.builder().initialRetryDelayMillis(0) + .totalRetryPeriodMillis(999) + .retryMinAttempts(5) + .retryMaxAttempts(10) + .build(); + ExceptionHandler handler = ExceptionHandler.builder().retryOn(RuntimeException.class).build(); + final int sleepOnAttempt = 8; + final AtomicInteger timesCalled = new AtomicInteger(0); + try { + RetryHelper.runWithRetries(callable(new Runnable() { + @Override public void run() { + timesCalled.incrementAndGet(); + if (timesCalled.get() == sleepOnAttempt) { + ticker.advance(1000, TimeUnit.MILLISECONDS); + } + throw new RuntimeException(); + } + }), params, handler, stopwatch); + fail(); + } catch (RetriesExhaustedException expected) { + // verify timesCalled + assertEquals(sleepOnAttempt, timesCalled.get()); + } + } + + @Test + public void testBackoffIsExponential() { + // Total retry period set to 60 seconds so as to not factor into test + RetryParams params = RetryParams.builder() + .initialRetryDelayMillis(10) + .maxRetryDelayMillis(10_000_000) + .retryDelayBackoffFactor(2) + .totalRetryPeriodMillis(60_000) + .retryMinAttempts(0) + .retryMaxAttempts(100) + .build(); + long sleepDuration = RetryHelper.getSleepDuration(params, 1); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 13 && sleepDuration >= 7); + sleepDuration = RetryHelper.getSleepDuration(params, 2); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 25 && sleepDuration >= 15); + sleepDuration = RetryHelper.getSleepDuration(params, 3); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 50 && sleepDuration >= 30); + sleepDuration = RetryHelper.getSleepDuration(params, 4); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 100 && sleepDuration >= 60); + sleepDuration = RetryHelper.getSleepDuration(params, 5); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 200 && sleepDuration >= 120); + sleepDuration = RetryHelper.getSleepDuration(params, 6); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 400 && sleepDuration >= 240); + sleepDuration = RetryHelper.getSleepDuration(params, 7); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 800 && sleepDuration >= 480); + sleepDuration = RetryHelper.getSleepDuration(params, 8); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 1600 && sleepDuration >= 960); + sleepDuration = RetryHelper.getSleepDuration(params, 9); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 3200 && sleepDuration >= 1920); + sleepDuration = RetryHelper.getSleepDuration(params, 10); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 6400 && sleepDuration >= 3840); + sleepDuration = RetryHelper.getSleepDuration(params, 11); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 12800 && sleepDuration >= 7680); + sleepDuration = RetryHelper.getSleepDuration(params, 12); + assertTrue(String.valueOf(sleepDuration), sleepDuration < 25600 && sleepDuration >= 15360); + } + + @Test + public void testNestedUsage() { + assertEquals((1 + 3) * 2, invokeNested(3, 2)); + } + + private int invokeNested(final int level, final int retries) { + if (level < 0) { + return 0; + } + return RetryHelper.runWithRetries(new Callable() { + @Override + public Integer call() throws IOException { + if (RetryHelper.getContext().getAttemptNumber() < retries) { + throw new IOException(); + } + assertEquals(retries, RetryHelper.getContext().getAttemptNumber()); + return invokeNested(level - 1, retries) + RetryHelper.getContext().getAttemptNumber(); + } + }); + } + +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java b/google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java new file mode 100644 index 0000000000..d1d5e3c076 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java @@ -0,0 +1,107 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static com.google.gcloud.RetryParams.DEFAULT_INITIAL_RETRY_DELAY_MILLIS; +import static com.google.gcloud.RetryParams.DEFAULT_MAX_RETRY_DELAY_MILLIS; +import static com.google.gcloud.RetryParams.DEFAULT_RETRY_DELAY_BACKOFF_FACTOR; +import static com.google.gcloud.RetryParams.DEFAULT_RETRY_MAX_ATTEMPTS; +import static com.google.gcloud.RetryParams.DEFAULT_RETRY_MIN_ATTEMPTS; +import static com.google.gcloud.RetryParams.DEFAULT_TOTAL_RETRY_PERIOD_MILLIS; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import com.google.gcloud.RetryParams.Builder; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.util.Arrays; + +/** + * Tests for {@link RetryParams}. + */ +@RunWith(JUnit4.class) +public class RetryParamsTest { + + @Test + public void testDefaults() { + RetryParams params1 = RetryParams.getDefaultInstance(); + RetryParams params2 = RetryParams.builder().build(); + for (RetryParams params : Arrays.asList(params1, params2)) { + assertEquals(DEFAULT_INITIAL_RETRY_DELAY_MILLIS, params.getInitialRetryDelayMillis()); + assertEquals(DEFAULT_MAX_RETRY_DELAY_MILLIS, params.getMaxRetryDelayMillis()); + assertEquals(DEFAULT_RETRY_DELAY_BACKOFF_FACTOR, params.getRetryDelayBackoffFactor(), 0); + assertEquals(DEFAULT_RETRY_MAX_ATTEMPTS, params.getRetryMaxAttempts()); + assertEquals(DEFAULT_RETRY_MIN_ATTEMPTS, params.getRetryMinAttempts()); + assertEquals(DEFAULT_TOTAL_RETRY_PERIOD_MILLIS, params.getTotalRetryPeriodMillis()); + } + } + + @Test + public void testSetAndCopy() { + RetryParams.Builder builder = RetryParams.builder(); + builder.initialRetryDelayMillis(101); + builder.maxRetryDelayMillis(102); + builder.retryDelayBackoffFactor(103); + builder.retryMinAttempts(107); + builder.retryMaxAttempts(108); + builder.totalRetryPeriodMillis(109); + RetryParams params1 = builder.build(); + RetryParams params2 = new RetryParams.Builder(params1).build(); + for (RetryParams params : Arrays.asList(params1, params2)) { + assertEquals(101, params.getInitialRetryDelayMillis()); + assertEquals(102, params.getMaxRetryDelayMillis()); + assertEquals(103, params.getRetryDelayBackoffFactor(), 0); + assertEquals(107, params.getRetryMinAttempts()); + assertEquals(108, params.getRetryMaxAttempts()); + assertEquals(109, params.getTotalRetryPeriodMillis()); + } + } + + @Test + public void testBadSettings() { + RetryParams.Builder builder = RetryParams.builder(); + builder.initialRetryDelayMillis(-1); + builder = assertFailure(builder); + builder.maxRetryDelayMillis(RetryParams.getDefaultInstance().getInitialRetryDelayMillis() - 1); + builder = assertFailure(builder); + builder.retryDelayBackoffFactor(-1); + builder = assertFailure(builder); + builder.retryMinAttempts(-1); + builder = assertFailure(builder); + builder.retryMaxAttempts(RetryParams.getDefaultInstance().getRetryMinAttempts() - 1); + builder = assertFailure(builder); + builder.totalRetryPeriodMillis(-1); + builder = assertFailure(builder); + // verify that it is OK for min and max to be equal + builder.retryMaxAttempts(RetryParams.getDefaultInstance().getRetryMinAttempts()); + builder.maxRetryDelayMillis(RetryParams.getDefaultInstance().getInitialRetryDelayMillis()); + builder.build(); + } + + private static Builder assertFailure(Builder builder) { + try { + builder.build(); + fail("Expected IllegalArgumentException"); + } catch (IllegalArgumentException ex) { + // expected + } + return RetryParams.builder(); + } +} From 5ec09840f03a4c8a759a9e840a0bff29c25c4213 Mon Sep 17 00:00:00 2001 From: aozarov Date: Tue, 26 May 2015 12:52:02 -0700 Subject: [PATCH 002/663] update pom descriptions --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7fbbe7dad2..78baf824c0 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -7,7 +7,7 @@ GCloud Java core https://github.com/GoogleCloudPlatform/gcloud-java - Java idiomatic client for Google Cloud Platform services. + Core module for the gcloud-java. com.google.gcloud From 561d01738520f9c307f34694c0b902c2511f3818 Mon Sep 17 00:00:00 2001 From: aozarov Date: Tue, 26 May 2015 14:23:42 -0700 Subject: [PATCH 003/663] remove StorageRpcProvider and add Javadoc to RPC factory interfaces --- .../com/google/gcloud/ServiceOptions.java | 11 +++++++ .../google/gcloud/spi/ServiceRpcFactory.java | 2 +- .../google/gcloud/spi/ServiceRpcProvider.java | 32 ------------------- 3 files changed, 12 insertions(+), 33 deletions(-) delete mode 100644 google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcProvider.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 448b617372..a974a1f191 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -25,6 +25,7 @@ import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.common.collect.Iterables; import com.google.gcloud.spi.ServiceRpcFactory; import java.io.BufferedReader; @@ -39,6 +40,7 @@ import java.net.URL; import java.util.Locale; import java.util.Objects; +import java.util.ServiceLoader; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -311,4 +313,13 @@ protected boolean isEquals(ServiceOptions other) { } public abstract Builder toBuilder(); + + /** + * Creates a service RPC using a factory loaded by {@link ServiceLoader}. + */ + protected static > R createRpc(O options, + Class> factoryClass) { + ServiceRpcFactory factory = Iterables.getFirst(ServiceLoader.load(factoryClass), null); + return factory == null ? null : factory.create(options); + } } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java index a16d11217b..e8e6761530 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java @@ -1 +1 @@ -/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.gcloud.spi; import com.google.gcloud.ServiceOptions; import java.io.Serializable; public interface ServiceRpcFactory extends Serializable { S create(O options); } \ No newline at end of file +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.gcloud.spi; import com.google.gcloud.ServiceOptions; import java.io.Serializable; /** * A base interface for all service RPC factories. * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. */ public interface ServiceRpcFactory extends Serializable { S create(O options); } \ No newline at end of file diff --git a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcProvider.java b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcProvider.java deleted file mode 100644 index 41a2bf2d58..0000000000 --- a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcProvider.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.gcloud.spi; - -import com.google.common.collect.Iterables; -import com.google.gcloud.ServiceOptions; - -import java.util.ServiceLoader; - -public class ServiceRpcProvider { - - public static > R get(O options, - Class> factoryClass) { - ServiceRpcFactory factory = Iterables.getFirst(ServiceLoader.load(factoryClass), null); - return factory == null ? null : factory.create(options); - } -} - From cc9b6dd22525c950009f71ffe89896a88847c724 Mon Sep 17 00:00:00 2001 From: aozarov Date: Tue, 26 May 2015 14:32:10 -0700 Subject: [PATCH 004/663] fix typo --- google-cloud-core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index e22b159d21..aa8d4304f1 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -10,7 +10,7 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services. - [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs) - [Examples] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/examples/package-summary.html) -This moudle provides common functionality and is required by the other service specific modules. +This module provides common functionality and is required by the other service specific modules. Quickstart ---------- From dcf17f3cc9c835fa35f58699c5bdbc5aa7834f5e Mon Sep 17 00:00:00 2001 From: aozarov Date: Thu, 28 May 2015 15:50:02 -0700 Subject: [PATCH 005/663] complete work on signURL --- google-cloud-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 78baf824c0..fa2e1c1897 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -28,13 +28,13 @@ com.google.http-client google-http-client - 1.19.0 + 1.20.0 compile com.google.oauth-client google-oauth-client - 1.19.0 + 1.20.0 compile From 01d7f7d288629ae630039b323e43a1d505f685b9 Mon Sep 17 00:00:00 2001 From: Jeremy Boynes Date: Wed, 3 Jun 2015 09:55:52 -0700 Subject: [PATCH 006/663] Replace CR characters with newlines --- .../java/com/google/gcloud/BaseService.java | 32 ++++++++++++++++++- .../main/java/com/google/gcloud/Service.java | 22 ++++++++++++- .../google/gcloud/spi/ServiceRpcFactory.java | 31 +++++++++++++++++- 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java index 4d96ac5b86..02bfd76771 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java @@ -1 +1,31 @@ -/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.gcloud; public abstract class BaseService implements Service { private final O options; protected BaseService(O options) { this.options = options; } @Override public O options() { return options; } } \ No newline at end of file +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +public abstract class BaseService implements Service { + + private final O options; + + protected BaseService(O options) { + this.options = options; + } + + @Override + public O options() { + return options; + } +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Service.java b/google-cloud-core/src/main/java/com/google/gcloud/Service.java index 02d810186b..8a43b9cf22 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Service.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Service.java @@ -1 +1,21 @@ -/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.gcloud; public interface Service { O options(); } \ No newline at end of file +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +public interface Service { + O options(); +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java index e8e6761530..9bab3f81ce 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java @@ -1 +1,30 @@ -/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.gcloud.spi; import com.google.gcloud.ServiceOptions; import java.io.Serializable; /** * A base interface for all service RPC factories. * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. */ public interface ServiceRpcFactory extends Serializable { S create(O options); } \ No newline at end of file +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud.spi; + +import com.google.gcloud.ServiceOptions; + +import java.io.Serializable; + +/** + * A base interface for all service RPC factories. + * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. + */ +public interface ServiceRpcFactory extends Serializable { + + S create(O options); +} From 5e309a964e922ed3c7c0261ba67d9c787b85441c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Fri, 5 Jun 2015 17:15:11 -0700 Subject: [PATCH 007/663] Minor cleanups. No behaviour or API changes are intended, except for a few types which were made public because they are referenced in the signatures of public methods. * Use the NameT convention for some type variables for improved readability. * Avoid using raw types where possible. * Limit the scope of @SuppressWarnings where possible. * Split some lines that were over the 100-character limit. --- .../com/google/gcloud/AuthCredentials.java | 7 ++- .../main/java/com/google/gcloud/Service.java | 4 +- .../com/google/gcloud/ServiceOptions.java | 45 +++++++++++-------- .../google/gcloud/spi/ServiceRpcFactory.java | 7 ++- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 6cdb737ddd..13d91836ae 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -181,10 +181,9 @@ public static AuthCredentials createForComputeEngine() /** * Returns the Application Default Credentials. * - *

- * Returns the Application Default Credentials which are credentials that identify and authorize - * the whole application. This is the built-in service account if running on Google Compute Engine - * or the credentials file from the path in the environment variable + *

Returns the Application Default Credentials which are credentials that identify and + * authorize the whole application. This is the built-in service account if running on + * Google Compute Engine or the credentials file from the path in the environment variable * GOOGLE_APPLICATION_CREDENTIALS. *

* diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Service.java b/google-cloud-core/src/main/java/com/google/gcloud/Service.java index 8a43b9cf22..19759fb20e 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Service.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Service.java @@ -16,6 +16,6 @@ package com.google.gcloud; -public interface Service { - O options(); +public interface Service> { + OptionsT options(); } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index a974a1f191..cd529ba141 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -45,7 +45,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public abstract class ServiceOptions> implements Serializable { +public abstract class ServiceOptions< + ServiceRpcT, + OptionsT extends ServiceOptions> + implements Serializable { private static final String DEFAULT_HOST = "https://www.googleapis.com"; private static final long serialVersionUID = 1203687993961393350L; @@ -56,7 +59,7 @@ public abstract class ServiceOptions> implemen private final HttpTransportFactory httpTransportFactory; private final AuthCredentials authCredentials; private final RetryParams retryParams; - private final ServiceRpcFactory serviceRpcFactory; + private final ServiceRpcFactory serviceRpcFactory; public interface HttpTransportFactory extends Serializable { HttpTransport create(); @@ -88,19 +91,21 @@ public HttpTransport create() { - protected abstract static class Builder, - B extends Builder> { + protected abstract static class Builder< + ServiceRpcT, + OptionsT extends ServiceOptions, + B extends Builder> { private String projectId; private String host; private HttpTransportFactory httpTransportFactory; private AuthCredentials authCredentials; private RetryParams retryParams; - private ServiceRpcFactory serviceRpcFactory; + private ServiceRpcFactory serviceRpcFactory; protected Builder() {} - protected Builder(ServiceOptions options) { + protected Builder(ServiceOptions options) { projectId = options.projectId; host = options.host; httpTransportFactory = options.httpTransportFactory; @@ -109,7 +114,7 @@ protected Builder(ServiceOptions options) { serviceRpcFactory = options.serviceRpcFactory; } - protected abstract ServiceOptions build(); + protected abstract ServiceOptions build(); @SuppressWarnings("unchecked") protected B self() { @@ -141,13 +146,13 @@ public B retryParams(RetryParams retryParams) { return self(); } - public B serviceRpcFactory(ServiceRpcFactory serviceRpcFactory) { + public B serviceRpcFactory(ServiceRpcFactory serviceRpcFactory) { this.serviceRpcFactory = serviceRpcFactory; return self(); } } - protected ServiceOptions(Builder builder) { + protected ServiceOptions(Builder builder) { projectId = checkNotNull(builder.projectId != null ? builder.projectId : defaultProject()); host = firstNonNull(builder.host, DEFAULT_HOST); httpTransportFactory = @@ -222,7 +227,7 @@ protected static String googleCloudProjectId() { String section = null; Pattern projectPattern = Pattern.compile("^project\\s*=\\s*(.*)$"); Pattern sectionPattern = Pattern.compile("^\\[(.*)\\]$"); - while((line = reader.readLine()) != null) { + while ((line = reader.readLine()) != null) { if (line.isEmpty() || line.startsWith(";")) { continue; } @@ -245,7 +250,7 @@ protected static String googleCloudProjectId() { } private static boolean isWindows() { - return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).indexOf("windows") > -1; + return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"); } protected static String getAppEngineProjectId() { @@ -288,7 +293,7 @@ public RetryParams retryParams() { return retryParams != null ? retryParams : RetryParams.noRetries(); } - public ServiceRpcFactory serviceRpcFactory() { + public ServiceRpcFactory serviceRpcFactory() { return serviceRpcFactory; } @@ -297,13 +302,12 @@ public HttpRequestInitializer httpRequestInitializer() { return authCredentials().httpRequestInitializer(httpTransport, scopes()); } - @Override - public int hashCode() { + protected int baseHashCode() { return Objects.hash(projectId, host, httpTransportFactory, authCredentials, retryParams, serviceRpcFactory); } - protected boolean isEquals(ServiceOptions other) { + protected boolean baseEquals(ServiceOptions other) { return Objects.equals(projectId, other.projectId) && Objects.equals(host, other.host) && Objects.equals(httpTransportFactory, other.httpTransportFactory) @@ -312,14 +316,17 @@ protected boolean isEquals(ServiceOptions other) { && Objects.equals(serviceRpcFactory, other.serviceRpcFactory); } - public abstract Builder toBuilder(); + public abstract Builder toBuilder(); /** * Creates a service RPC using a factory loaded by {@link ServiceLoader}. */ - protected static > R createRpc(O options, - Class> factoryClass) { - ServiceRpcFactory factory = Iterables.getFirst(ServiceLoader.load(factoryClass), null); + protected static + > + ServiceRpcT createRpc(OptionsT options, + Class> factoryClass) { + ServiceRpcFactory factory = + Iterables.getFirst(ServiceLoader.load(factoryClass), null); return factory == null ? null : factory.create(options); } } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java index 9bab3f81ce..89e08cda9e 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java @@ -24,7 +24,10 @@ * A base interface for all service RPC factories. * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. */ -public interface ServiceRpcFactory extends Serializable { +public interface ServiceRpcFactory< + ServiceRpcT, + OptionsT extends ServiceOptions> + extends Serializable { - S create(O options); + ServiceRpcT create(OptionsT options); } From 5349f4c2bfc94ba494f8d894c7e78deefd93a57e Mon Sep 17 00:00:00 2001 From: Eamonn McManus Date: Sun, 7 Jun 2015 14:42:13 -0700 Subject: [PATCH 008/663] Adjust type variable usage in BaseService to fix compile error. --- .../src/main/java/com/google/gcloud/BaseService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java index 02bfd76771..982d305829 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java @@ -16,16 +16,17 @@ package com.google.gcloud; -public abstract class BaseService implements Service { +public abstract class BaseService> + implements Service { - private final O options; + private final OptionsT options; - protected BaseService(O options) { + protected BaseService(OptionsT options) { this.options = options; } @Override - public O options() { + public OptionsT options() { return options; } } From d16ecea91fa00416ce3f9932e254f862c8c41fcb Mon Sep 17 00:00:00 2001 From: aozarov Date: Mon, 29 Jun 2015 11:54:15 -0700 Subject: [PATCH 009/663] update to 0.0.6 and push to maven --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index fa2e1c1897..30e1a665ba 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -12,7 +12,7 @@ com.google.gcloud gcloud-java-pom - 0.0.5 + 0.0.6 From 55d7ba72e8c0f0aa791fea88216745d284e59841 Mon Sep 17 00:00:00 2001 From: aozarov Date: Mon, 29 Jun 2015 16:37:25 -0700 Subject: [PATCH 010/663] using a -SNAPSHOT until release is ready --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 30e1a665ba..3617ec2f7e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -12,7 +12,7 @@ com.google.gcloud gcloud-java-pom - 0.0.6 + 0.0.7-SNAPSHOT From 2f51238e3ec96507e84ce08a1e3ce5887b504326 Mon Sep 17 00:00:00 2001 From: aozarov Date: Mon, 29 Jun 2015 16:54:45 -0700 Subject: [PATCH 011/663] replace LATEST with specific version in README files --- google-cloud-core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index aa8d4304f1..8618ab1240 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,7 +19,7 @@ Add this to your pom.xml file com.google.gcloud gcloud-java-core - LATEST + 0.0.6 ``` From 58cd91a89fddd6ba6e4d74615ddf68a1bb651269 Mon Sep 17 00:00:00 2001 From: aozarov Date: Mon, 6 Jul 2015 14:44:09 -0700 Subject: [PATCH 012/663] create site and maven artifacts only once and ignore pull requests --- google-cloud-core/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3617ec2f7e..b577c4d29b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -5,7 +5,6 @@ gcloud-java-core jar GCloud Java core - https://github.com/GoogleCloudPlatform/gcloud-java Core module for the gcloud-java. From 2f9884b70b193ad0ab251ea614278978bd4e0e4f Mon Sep 17 00:00:00 2001 From: aozarov Date: Thu, 30 Jul 2015 15:18:41 -0700 Subject: [PATCH 013/663] 1. Fix issue #121 and replace default_project_id environment name with GCLOUD_PROJECT 2. Fix a null pointer bug with listing 3. Update maven dependencies --- .../src/main/java/com/google/gcloud/ServiceOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index cd529ba141..59c2d57fb3 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -52,7 +52,7 @@ public abstract class ServiceOptions< private static final String DEFAULT_HOST = "https://www.googleapis.com"; private static final long serialVersionUID = 1203687993961393350L; - private static final String PROJECT_ENV_NAME = "default_project_id"; + private static final String PROJECT_ENV_NAME = "GCLOUD_PROJECT"; private final String projectId; private final String host; From 5dc6fd3fa80a1576e9bceb2140d54773d247e0b0 Mon Sep 17 00:00:00 2001 From: aozarov Date: Mon, 24 Aug 2015 17:17:20 -0700 Subject: [PATCH 014/663] Support running against gcloud datastore emulator (support DATASTORE_HOST) --- .../src/main/java/com/google/gcloud/ServiceOptions.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 59c2d57fb3..206e1fecaa 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -154,7 +154,7 @@ public B serviceRpcFactory(ServiceRpcFactory serviceRpcFa protected ServiceOptions(Builder builder) { projectId = checkNotNull(builder.projectId != null ? builder.projectId : defaultProject()); - host = firstNonNull(builder.host, DEFAULT_HOST); + host = firstNonNull(builder.host, defaultHost()); httpTransportFactory = firstNonNull(builder.httpTransportFactory, DefaultHttpTransportFactory.INSTANCE); authCredentials = firstNonNull(builder.authCredentials, defaultAuthCredentials()); @@ -191,6 +191,10 @@ protected static String appEngineAppId() { return System.getProperty("com.google.appengine.application.id"); } + protected String defaultHost() { + return DEFAULT_HOST; + } + protected String defaultProject() { String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); if (projectId == null) { From 7482b94175553dad076cc5c1a64b76c481342799 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 25 Aug 2015 16:28:56 -0700 Subject: [PATCH 015/663] Updating version to 0.0.8-SNAPSHOT after releasing 0.0.7 on maven --- google-cloud-core/README.md | 2 +- google-cloud-core/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 8618ab1240..42cb3e368a 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,7 +19,7 @@ Add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.0.6 + 0.0.7 ``` diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b577c4d29b..df0869d00f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.0.7-SNAPSHOT + 0.0.8-SNAPSHOT From a76d80c1526204e5fe4c5d54daeae6db164d03bb Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 25 Sep 2015 14:51:18 +0200 Subject: [PATCH 016/663] Add AuthCredentials.createForJson. More javadoc. --- .../com/google/gcloud/AuthCredentials.java | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 13d91836ae..ffc54df77a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -30,6 +30,7 @@ import com.google.auth.oauth2.GoogleCredentials; import java.io.IOException; +import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectStreamException; import java.io.Serializable; @@ -133,7 +134,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE try { computeCredential = getComputeCredential(); } catch (GeneralSecurityException e) { - throw new IOException(e); + throw new IOException(e); } } @@ -156,7 +157,7 @@ private static class ApplicationDefaultAuthCredentials extends AuthCredentials { private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); - googleCredentials = GoogleCredentials.getApplicationDefault(); + googleCredentials = GoogleCredentials.getApplicationDefault(); } @Override @@ -183,8 +184,8 @@ public static AuthCredentials createForComputeEngine() * *

Returns the Application Default Credentials which are credentials that identify and * authorize the whole application. This is the built-in service account if running on - * Google Compute Engine or the credentials file from the path in the environment variable - * GOOGLE_APPLICATION_CREDENTIALS. + * Google Compute Engine or the credentials file can be read from the path in the environment + * variable GOOGLE_APPLICATION_CREDENTIALS. *

* * @return the credentials instance. @@ -194,10 +195,41 @@ public static AuthCredentials createApplicationDefaults() throws IOException { return new ApplicationDefaultAuthCredentials(); } + /** + * Creates Service Account Credentials given an account id and a private key. + * + *

For details on how to obtain Service Account Credentials see + * Service + * Account Authentication. + *

+ * + * @param account id of the Service Account + * @param privateKey private key associated to the account + * @return the credentials instance. + */ public static ServiceAccountAuthCredentials createFor(String account, PrivateKey privateKey) { return new ServiceAccountAuthCredentials(account, privateKey); } + /** + * Creates Service Account Credentials given a stream for credentials in JSON format. + * + *

For details on how to obtain Service Account Credentials in JSON format see + * Service + * Account Authentication. + *

+ * + * @param jsonCredentialStream stream for Service Account Credentials in JSON format + * @return the credentials instance. + * @throws IOException if the credentials cannot be created from the stream. + */ + public static ServiceAccountAuthCredentials createForJson(InputStream jsonCredentialStream) + throws IOException { + GoogleCredential tempCredentials = GoogleCredential.fromStream(jsonCredentialStream); + return new ServiceAccountAuthCredentials(tempCredentials.getServiceAccountId(), + tempCredentials.getServiceAccountPrivateKey()); + } + public static AuthCredentials noCredentials() { return ServiceAccountAuthCredentials.NO_CREDENTIALS; } From 4a5715470c922c07849bf49c4519447bb6918b93 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 25 Sep 2015 10:43:36 -0700 Subject: [PATCH 017/663] Add third RetryResult (instead of using null) to denote 'proceed' --- .../com/google/gcloud/ExceptionHandler.java | 34 +++++-------- .../google/gcloud/ExceptionHandlerTest.java | 51 ++++++++++++++++++- 2 files changed, 63 insertions(+), 22 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java index 412462ae15..9e472965cb 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java @@ -16,7 +16,6 @@ package com.google.gcloud; -import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.VisibleForTesting; @@ -48,18 +47,7 @@ public final class ExceptionHandler implements Serializable { public interface Interceptor extends Serializable { enum RetryResult { - - RETRY(true), ABORT(false); - - private final boolean booleanValue; - - RetryResult(boolean booleanValue) { - this.booleanValue = booleanValue; - } - - boolean booleanValue() { - return booleanValue; - } + ABORT, RETRY, PROCEED; } /** @@ -68,7 +56,7 @@ boolean booleanValue() { * @param exception the exception that is being evaluated * @return {@link RetryResult} to indicate if the exception should be ignored ( * {@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}), or evaluation - * should proceed ({@code null}). + * should proceed ({@link RetryResult#PROCEED}). */ RetryResult beforeEval(Exception exception); @@ -79,7 +67,7 @@ boolean booleanValue() { * @param retryResult the result of the evaluation so far. * @return {@link RetryResult} to indicate if the exception should be ignored ( * {@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}), or evaluation - * should proceed ({@code null}). + * should proceed ({@link RetryResult#PROCEED}). */ RetryResult afterEval(Exception exception, RetryResult retryResult); } @@ -157,7 +145,7 @@ static final class RetryInfo implements Serializable { RetryInfo(Class exception, Interceptor.RetryResult retry) { this.exception = checkNotNull(exception); - this.retry = retry; + this.retry = checkNotNull(retry); } @Override @@ -253,18 +241,22 @@ public Set> getNonRetriableExceptions() { boolean shouldRetry(Exception ex) { for (Interceptor interceptor : interceptors) { - Interceptor.RetryResult retryResult = interceptor.beforeEval(ex); - if (retryResult != null) { - return retryResult.booleanValue(); + Interceptor.RetryResult retryResult = checkNotNull(interceptor.beforeEval(ex)); + if (retryResult != Interceptor.RetryResult.PROCEED) { + return interceptor.beforeEval(ex) == Interceptor.RetryResult.RETRY; } } RetryInfo retryInfo = findMostSpecificRetryInfo(this.retryInfo, ex.getClass()); Interceptor.RetryResult retryResult = retryInfo == null ? Interceptor.RetryResult.ABORT : retryInfo.retry; for (Interceptor interceptor : interceptors) { - retryResult = firstNonNull(interceptor.afterEval(ex, retryResult), retryResult); + Interceptor.RetryResult interceptorRetry = + checkNotNull(interceptor.afterEval(ex, retryResult)); + if (interceptorRetry != Interceptor.RetryResult.PROCEED) { + retryResult = interceptorRetry; + } } - return retryResult.booleanValue(); + return retryResult == Interceptor.RetryResult.RETRY; } /** diff --git a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java index 3844f9de36..999cd06fac 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java @@ -158,11 +158,60 @@ public RetryResult beforeEval(Exception exception) { assertTrue(handler.shouldRetry(new RuntimeException())); assertTrue(handler.shouldRetry(new NullPointerException())); - before.set(null); + before.set(RetryResult.PROCEED); assertFalse(handler.shouldRetry(new IOException())); assertTrue(handler.shouldRetry(new ClosedByInterruptException())); assertTrue(handler.shouldRetry(new InterruptedException())); assertTrue(handler.shouldRetry(new RuntimeException())); assertFalse(handler.shouldRetry(new NullPointerException())); } + + @Test + public void testNullRetryResult() { + @SuppressWarnings("serial") + Interceptor interceptor1 = new Interceptor() { + + @Override + public RetryResult beforeEval(Exception exception) { + return null; + } + + @Override + public RetryResult afterEval(Exception exception, RetryResult retryResult) { + return RetryResult.PROCEED; + } + + }; + + @SuppressWarnings("serial") + Interceptor interceptor2 = new Interceptor() { + + @Override + public RetryResult beforeEval(Exception exception) { + return RetryResult.PROCEED; + } + + @Override + public RetryResult afterEval(Exception exception, RetryResult retryResult) { + return null; + } + + }; + + ExceptionHandler handler1 = ExceptionHandler.builder().interceptor(interceptor1).build(); + try { + handler1.shouldRetry(new Exception()); + fail("Expected null pointer exception due to null RetryResult from beforeEval"); + } catch (NullPointerException e) { + // expected + } + + ExceptionHandler handler2 = ExceptionHandler.builder().interceptor(interceptor2).build(); + try { + handler2.shouldRetry(new Exception()); + fail("Expected null pointer exception due to null RetryResult from afterEval"); + } catch (NullPointerException e) { + // expected + } + } } From c40fb389a23f133893383c5313f023ed34d2c4f1 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 25 Sep 2015 14:06:17 -0700 Subject: [PATCH 018/663] Rename RetryResult enum values, and update datastore and storage interceptor. --- .../com/google/gcloud/ExceptionHandler.java | 20 ++++---- .../google/gcloud/ExceptionHandlerTest.java | 46 +++++++++---------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java index 9e472965cb..a0fab3dca5 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java @@ -47,7 +47,7 @@ public final class ExceptionHandler implements Serializable { public interface Interceptor extends Serializable { enum RetryResult { - ABORT, RETRY, PROCEED; + NO_RETRY, RETRY, CONTINUE_EVALUATION; } /** @@ -55,8 +55,8 @@ enum RetryResult { * * @param exception the exception that is being evaluated * @return {@link RetryResult} to indicate if the exception should be ignored ( - * {@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}), or evaluation - * should proceed ({@link RetryResult#PROCEED}). + * {@link RetryResult#RETRY}), propagated ({@link RetryResult#NO_RETRY}), or evaluation + * should proceed ({@link RetryResult#CONTINUE_EVALUATION}). */ RetryResult beforeEval(Exception exception); @@ -66,8 +66,8 @@ enum RetryResult { * @param exception the exception that is being evaluated * @param retryResult the result of the evaluation so far. * @return {@link RetryResult} to indicate if the exception should be ignored ( - * {@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}), or evaluation - * should proceed ({@link RetryResult#PROCEED}). + * {@link RetryResult#RETRY}), propagated ({@link RetryResult#NO_RETRY}), or evaluation + * should proceed ({@link RetryResult#CONTINUE_EVALUATION}). */ RetryResult afterEval(Exception exception, RetryResult retryResult); } @@ -177,7 +177,7 @@ private ExceptionHandler(Builder builder) { addRetryInfo(new RetryInfo(exception, Interceptor.RetryResult.RETRY), retryInfo); } for (Class exception : nonRetriableExceptions) { - addRetryInfo(new RetryInfo(exception, Interceptor.RetryResult.ABORT), retryInfo); + addRetryInfo(new RetryInfo(exception, Interceptor.RetryResult.NO_RETRY), retryInfo); } } @@ -242,17 +242,17 @@ public Set> getNonRetriableExceptions() { boolean shouldRetry(Exception ex) { for (Interceptor interceptor : interceptors) { Interceptor.RetryResult retryResult = checkNotNull(interceptor.beforeEval(ex)); - if (retryResult != Interceptor.RetryResult.PROCEED) { - return interceptor.beforeEval(ex) == Interceptor.RetryResult.RETRY; + if (retryResult != Interceptor.RetryResult.CONTINUE_EVALUATION) { + return retryResult == Interceptor.RetryResult.RETRY; } } RetryInfo retryInfo = findMostSpecificRetryInfo(this.retryInfo, ex.getClass()); Interceptor.RetryResult retryResult = - retryInfo == null ? Interceptor.RetryResult.ABORT : retryInfo.retry; + retryInfo == null ? Interceptor.RetryResult.NO_RETRY : retryInfo.retry; for (Interceptor interceptor : interceptors) { Interceptor.RetryResult interceptorRetry = checkNotNull(interceptor.afterEval(ex, retryResult)); - if (interceptorRetry != Interceptor.RetryResult.PROCEED) { + if (interceptorRetry != Interceptor.RetryResult.CONTINUE_EVALUATION) { retryResult = interceptorRetry; } } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java index 999cd06fac..5ce05ad900 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java @@ -23,6 +23,8 @@ import com.google.gcloud.ExceptionHandler.Interceptor; import com.google.gcloud.ExceptionHandler.Interceptor.RetryResult; +import org.junit.rules.ExpectedException; +import org.junit.Rule; import org.junit.Test; import java.io.FileNotFoundException; @@ -36,6 +38,9 @@ */ public class ExceptionHandlerTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Test public void testVerifyCaller() { class A implements Callable { @@ -128,13 +133,13 @@ public void testShouldTry() { assertFalse(handler.shouldRetry(new RuntimeException())); assertTrue(handler.shouldRetry(new NullPointerException())); - final AtomicReference before = new AtomicReference<>(RetryResult.ABORT); + final AtomicReference before = new AtomicReference<>(RetryResult.NO_RETRY); @SuppressWarnings("serial") Interceptor interceptor = new Interceptor() { @Override public RetryResult afterEval(Exception exception, RetryResult retryResult) { - return retryResult == RetryResult.ABORT ? RetryResult.RETRY : RetryResult.ABORT; + return retryResult == RetryResult.NO_RETRY ? RetryResult.RETRY : RetryResult.NO_RETRY; } @Override @@ -158,7 +163,7 @@ public RetryResult beforeEval(Exception exception) { assertTrue(handler.shouldRetry(new RuntimeException())); assertTrue(handler.shouldRetry(new NullPointerException())); - before.set(RetryResult.PROCEED); + before.set(RetryResult.CONTINUE_EVALUATION); assertFalse(handler.shouldRetry(new IOException())); assertTrue(handler.shouldRetry(new ClosedByInterruptException())); assertTrue(handler.shouldRetry(new InterruptedException())); @@ -167,9 +172,9 @@ public RetryResult beforeEval(Exception exception) { } @Test - public void testNullRetryResult() { + public void testNullRetryResultFromBeforeEval() { @SuppressWarnings("serial") - Interceptor interceptor1 = new Interceptor() { + Interceptor interceptor = new Interceptor() { @Override public RetryResult beforeEval(Exception exception) { @@ -178,17 +183,24 @@ public RetryResult beforeEval(Exception exception) { @Override public RetryResult afterEval(Exception exception, RetryResult retryResult) { - return RetryResult.PROCEED; + return RetryResult.CONTINUE_EVALUATION; } }; + ExceptionHandler handler = ExceptionHandler.builder().interceptor(interceptor).build(); + thrown.expect(NullPointerException.class); + handler.shouldRetry(new Exception()); + } + + @Test + public void testNullRetryResultFromAfterEval() { @SuppressWarnings("serial") - Interceptor interceptor2 = new Interceptor() { + Interceptor interceptor = new Interceptor() { @Override public RetryResult beforeEval(Exception exception) { - return RetryResult.PROCEED; + return RetryResult.CONTINUE_EVALUATION; } @Override @@ -198,20 +210,8 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { }; - ExceptionHandler handler1 = ExceptionHandler.builder().interceptor(interceptor1).build(); - try { - handler1.shouldRetry(new Exception()); - fail("Expected null pointer exception due to null RetryResult from beforeEval"); - } catch (NullPointerException e) { - // expected - } - - ExceptionHandler handler2 = ExceptionHandler.builder().interceptor(interceptor2).build(); - try { - handler2.shouldRetry(new Exception()); - fail("Expected null pointer exception due to null RetryResult from afterEval"); - } catch (NullPointerException e) { - // expected - } + ExceptionHandler handler = ExceptionHandler.builder().interceptor(interceptor).build(); + thrown.expect(NullPointerException.class); + handler.shouldRetry(new Exception()); } } From 0e3b9c147008b51684f782c82eecefaa68eafca6 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 1 Oct 2015 15:32:19 -0700 Subject: [PATCH 019/663] fix joda-time version --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index df0869d00f..7b94cead0f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -74,7 +74,7 @@ joda-time joda-time - RELEASE + 2.8.2 compile From a798898b4c220020b9707492f71061456d6a3af4 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 8 Oct 2015 13:22:26 -0700 Subject: [PATCH 020/663] update version to 0.0.9 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7b94cead0f..7b2c3b4d00 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.0.8-SNAPSHOT + 0.0.9 From f4d2916f36077fe9d62809d173e9ea24705b45e3 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Thu, 8 Oct 2015 20:54:19 +0000 Subject: [PATCH 021/663] Updating version in README files. --- google-cloud-core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 42cb3e368a..80b4bf5975 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,7 +19,7 @@ Add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.0.7 + 0.0.9 ``` From fb2cf48e9536cd0713626ce6eae7c75450c65b6a Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 8 Oct 2015 14:35:19 -0700 Subject: [PATCH 022/663] Link to specific package of javadoc from README --- google-cloud-core/README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 42cb3e368a..a928ab5977 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -1,17 +1,15 @@ -Google Cloud Java Client -========================== +Google Cloud Java Client -- Core Services +========================================= -Java idiomatic client for [Google Cloud Platform][cloud-platform] services. +This module provides common functionality required by service-specific modules of this library. [![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java) [![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master) - [Homepage] (https://googlecloudplatform.github.io/gcloud-java/) -- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs) +- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/package-summary.html) - [Examples] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/examples/package-summary.html) -This module provides common functionality and is required by the other service specific modules. - Quickstart ---------- Add this to your pom.xml file From 15d10878a9bd435b35c2cfdbbc84e4de2296cb38 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 8 Oct 2015 15:30:42 -0700 Subject: [PATCH 023/663] Updates to pom.xml by script --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7b2c3b4d00..82d9db0662 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.0.9 + 0.0.10-SNAPSHOT From 6f7ced39a5aeb0addf53d62bbdc9fa759fce3cf5 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 9 Oct 2015 16:26:18 +0200 Subject: [PATCH 024/663] Add connectTimeout and readTimeout to ServiceOptions --- .../com/google/gcloud/ServiceOptions.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 206e1fecaa..af98116830 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -22,6 +22,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.api.client.extensions.appengine.http.UrlFetchTransport; +import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; @@ -60,6 +61,8 @@ public abstract class ServiceOptions< private final AuthCredentials authCredentials; private final RetryParams retryParams; private final ServiceRpcFactory serviceRpcFactory; + private final int connectTimeout; + private final int readTimeout; public interface HttpTransportFactory extends Serializable { HttpTransport create(); @@ -102,6 +105,8 @@ protected abstract static class Builder< private AuthCredentials authCredentials; private RetryParams retryParams; private ServiceRpcFactory serviceRpcFactory; + private int connectTimeout = -1; + private int readTimeout = -1; protected Builder() {} @@ -150,6 +155,16 @@ public B serviceRpcFactory(ServiceRpcFactory serviceRpcFa this.serviceRpcFactory = serviceRpcFactory; return self(); } + + public B connectTimeout(int connectTimeout) { + this.connectTimeout = connectTimeout; + return self(); + } + + public B readTimeout(int readTimeout) { + this.readTimeout = readTimeout; + return self(); + } } protected ServiceOptions(Builder builder) { @@ -160,6 +175,8 @@ protected ServiceOptions(Builder builder) { authCredentials = firstNonNull(builder.authCredentials, defaultAuthCredentials()); retryParams = builder.retryParams; serviceRpcFactory = builder.serviceRpcFactory; + connectTimeout = builder.connectTimeout; + readTimeout = builder.readTimeout; } private static AuthCredentials defaultAuthCredentials() { @@ -303,7 +320,20 @@ public ServiceRpcFactory serviceRpcFactory() { public HttpRequestInitializer httpRequestInitializer() { HttpTransport httpTransport = httpTransportFactory.create(); - return authCredentials().httpRequestInitializer(httpTransport, scopes()); + final HttpRequestInitializer baseRequestInitializer = + authCredentials().httpRequestInitializer(httpTransport, scopes()); + return new HttpRequestInitializer() { + @Override + public void initialize(HttpRequest httpRequest) throws IOException { + baseRequestInitializer.initialize(httpRequest); + if (connectTimeout >= 0) { + httpRequest.setConnectTimeout(connectTimeout); + } + if (readTimeout >= 0) { + httpRequest.setReadTimeout(readTimeout); + } + } + }; } protected int baseHashCode() { From 1f9a2bd86ac6e99597a9272fc86359db20eab9dd Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 9 Oct 2015 08:49:00 -0700 Subject: [PATCH 025/663] Make links to examples more specific --- google-cloud-core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 0c0fe93641..2b89014e41 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -1,4 +1,4 @@ -Google Cloud Java Client -- Core Services +Google Cloud Java Client -- Core ========================================= This module provides common functionality required by service-specific modules of this library. From b5cd36e66ea1fad1f26e9271678372fb5d216755 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 9 Oct 2015 20:27:07 +0200 Subject: [PATCH 026/663] Add javadoc to ServiceOptions.Builder methods --- .../com/google/gcloud/ServiceOptions.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index af98116830..b19ef19b4e 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -126,41 +126,85 @@ protected B self() { return (B) this; } + /** + * Sets project id. + * + * @return the builder. + */ public B projectId(String projectId) { this.projectId = projectId; return self(); } + /** + * Sets service host. + * + * @return the builder. + */ public B host(String host) { this.host = host; return self(); } + /** + * Sets the transport factory. + * + * @return the builder. + */ public B httpTransportFactory(HttpTransportFactory httpTransportFactory) { this.httpTransportFactory = httpTransportFactory; return self(); } + /** + * Sets the service authentication credentials. + * + * @return the builder. + */ public B authCredentials(AuthCredentials authCredentials) { this.authCredentials = authCredentials; return self(); } + /** + * Sets configuration parameters for request retries. + * + * @return the builder. + */ public B retryParams(RetryParams retryParams) { this.retryParams = retryParams; return self(); } + /** + * Sets the factory for rpc services. + * + * @return the builder + */ public B serviceRpcFactory(ServiceRpcFactory serviceRpcFactory) { this.serviceRpcFactory = serviceRpcFactory; return self(); } + /** + * Sets the timeout in milliseconds to establish a connection. + * + * @param connectTimeout connection timeout in milliseconds. 0 for an infinite timeout, a + * negative number for the default value (20000). + * @return the builder. + */ public B connectTimeout(int connectTimeout) { this.connectTimeout = connectTimeout; return self(); } + /** + * Sets the timeout in milliseconds to read data from an established connection. + * + * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a + * negative number for the default value (20000). + * @return the builder. + */ public B readTimeout(int readTimeout) { this.readTimeout = readTimeout; return self(); From 8114f1af5f2115891bbe14b94bda04a172f82121 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 9 Oct 2015 20:39:09 +0200 Subject: [PATCH 027/663] Add timeout getters and javadocs to StorageOptions --- .../com/google/gcloud/ServiceOptions.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index b19ef19b4e..c70975502a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -338,30 +338,52 @@ protected static String getAppEngineProjectId() { protected abstract Set scopes(); + /** + * Returns the project id. + */ public String projectId() { return projectId; } + /** + * Returns the service host. + */ public String host() { return host; } + /** + * Returns the transport factory. + */ public HttpTransportFactory httpTransportFactory() { return httpTransportFactory; } + /** + * Returns the authentication credentials. + */ public AuthCredentials authCredentials() { return authCredentials; } + /** + * Returns configuration parameters for request retries. + */ public RetryParams retryParams() { return retryParams != null ? retryParams : RetryParams.noRetries(); } + /** + * Returns the factory for rpc services. + */ public ServiceRpcFactory serviceRpcFactory() { return serviceRpcFactory; } + /** + * Returns a request initializer responsible for initializing requests according to service + * options. + */ public HttpRequestInitializer httpRequestInitializer() { HttpTransport httpTransport = httpTransportFactory.create(); final HttpRequestInitializer baseRequestInitializer = @@ -380,6 +402,22 @@ public void initialize(HttpRequest httpRequest) throws IOException { }; } + /** + * Returns the timeout in milliseconds to establish a connection. 0 is an infinite timeout, a + * negative number is the default value (20000). + */ + public int connectTimeout() { + return connectTimeout; + } + + /** + * Returns the timeout in milliseconds to read from an established connection. 0 is an infinite + * timeout, a negative number is the default value (20000). + */ + public int readTimeout() { + return readTimeout; + } + protected int baseHashCode() { return Objects.hash(projectId, host, httpTransportFactory, authCredentials, retryParams, serviceRpcFactory); From e5f8cf8ba05ce3cd34e28f8fff268c1521f6dc79 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 12 Oct 2015 19:05:15 +0200 Subject: [PATCH 028/663] More detailed javadoc for options.retryParams and RetryParams --- .../java/com/google/gcloud/RetryParams.java | 19 ++++++++++++------- .../com/google/gcloud/ServiceOptions.java | 7 ++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java b/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java index 0d38aea77a..24983326cc 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java @@ -66,7 +66,6 @@ public final class RetryParams implements Serializable { private static final RetryParams NO_RETRIES = builder().retryMaxAttempts(1).retryMinAttempts(1).build(); - /** * RetryParams builder. */ @@ -206,47 +205,53 @@ public static RetryParams getDefaultInstance() { return DEFAULT_INSTANCE; } + /** + * Returns an instance of {@code RetryParams} where `retryMaxAttempts` and `retryMinAttempts` are + * set to `1`. + */ public static RetryParams noRetries() { return NO_RETRIES; } /** - * Returns the retryMinAttempts. + * Returns the retryMinAttempts. Default value is {@value #DEFAULT_RETRY_MIN_ATTEMPTS}. */ public int getRetryMinAttempts() { return retryMinAttempts; } /** - * Returns the retryMaxAttempts. + * Returns the retryMaxAttempts. Default value is {@value #DEFAULT_RETRY_MAX_ATTEMPTS}. */ public int getRetryMaxAttempts() { return retryMaxAttempts; } /** - * Returns the initialRetryDelayMillis. + * Returns the initialRetryDelayMillis. Default value is + * {@value #DEFAULT_INITIAL_RETRY_DELAY_MILLIS}. */ public long getInitialRetryDelayMillis() { return initialRetryDelayMillis; } /** - * Returns the maxRetryDelayMillis. + * Returns the maxRetryDelayMillis. Default values is {@value #DEFAULT_MAX_RETRY_DELAY_MILLIS}. */ public long getMaxRetryDelayMillis() { return maxRetryDelayMillis; } /** - * Returns the maxRetryDelayBackoffFactor. + * Returns the maxRetryDelayBackoffFactor. Default values is + * {@value #DEFAULT_RETRY_DELAY_BACKOFF_FACTOR}. */ public double getRetryDelayBackoffFactor() { return retryDelayBackoffFactor; } /** - * Returns the totalRetryPeriodMillis. + * Returns the totalRetryPeriodMillis. Default value is {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}. */ public long getTotalRetryPeriodMillis() { return totalRetryPeriodMillis; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index c70975502a..b80378ccd7 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -16,7 +16,6 @@ package com.google.gcloud; - import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkNotNull; import static java.nio.charset.StandardCharsets.UTF_8; @@ -167,7 +166,8 @@ public B authCredentials(AuthCredentials authCredentials) { } /** - * Sets configuration parameters for request retries. + * Sets configuration parameters for request retries. If no configuration is set + * {@link RetryParams#noRetries()} is used. * * @return the builder. */ @@ -367,7 +367,8 @@ public AuthCredentials authCredentials() { } /** - * Returns configuration parameters for request retries. + * Returns configuration parameters for request retries. By default requests are not retried: + * {@link RetryParams#noRetries()} is used. */ public RetryParams retryParams() { return retryParams != null ? retryParams : RetryParams.noRetries(); From 33dad3470bb2003af163c09a0f6ee6ab79c551a2 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 12 Oct 2015 10:14:30 -0700 Subject: [PATCH 029/663] Standardize readme files --- google-cloud-core/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 2b89014e41..e8b0191e7e 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -5,10 +5,10 @@ This module provides common functionality required by service-specific modules o [![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java) [![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master) +[![Maven](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg)](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg) - [Homepage] (https://googlecloudplatform.github.io/gcloud-java/) - [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/package-summary.html) -- [Examples] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/examples/package-summary.html) Quickstart ---------- @@ -21,6 +21,11 @@ Add this to your pom.xml file ``` +Java Versions +------------- + +Java 7 or above is required for using this client. + Contributing ------------ @@ -28,11 +33,6 @@ Contributions to this library are always welcome and highly encouraged. See [CONTRIBUTING] for more information on how to get started. -Java Versions -------------- - -Java 7 or above is required for using this client. - Versioning ---------- From 448b871aec39005bcabe30d60780cc71d6689e1a Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 13 Oct 2015 12:44:05 +0200 Subject: [PATCH 030/663] Rename TimeSource to Clock and move it to ServiceOptions --- .../com/google/gcloud/ServiceOptions.java | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index b80378ccd7..ab56c78e10 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -62,6 +62,7 @@ public abstract class ServiceOptions< private final ServiceRpcFactory serviceRpcFactory; private final int connectTimeout; private final int readTimeout; + private final Clock clock; public interface HttpTransportFactory extends Serializable { HttpTransport create(); @@ -91,7 +92,40 @@ public HttpTransport create() { } } + /** + * A class providing access to the current time in milliseconds. This class is mainly used for + * testing and will be replaced by Java8's {@code java.time.Clock}. + * + * Implementations should implement {@code Serializable} wherever possible and must document + * whether or not they do support serialization. + */ + public static abstract class Clock { + + private static ServiceOptions.Clock DEFAULT_TIME_SOURCE = new DefaultClock(); + + /** + * Returns current time in milliseconds according to this clock. + */ + public abstract long millis(); + + /** + * Returns the default clock. Default clock uses {@link System#currentTimeMillis()} to get time + * in milliseconds. + */ + public static ServiceOptions.Clock defaultClock() { + return DEFAULT_TIME_SOURCE; + } + + private static class DefaultClock extends ServiceOptions.Clock implements Serializable { + private static final long serialVersionUID = -5077300394286703864L; + + @Override + public long millis() { + return System.currentTimeMillis(); + } + } + } protected abstract static class Builder< ServiceRpcT, @@ -106,6 +140,7 @@ protected abstract static class Builder< private ServiceRpcFactory serviceRpcFactory; private int connectTimeout = -1; private int readTimeout = -1; + private Clock clock; protected Builder() {} @@ -125,6 +160,18 @@ protected B self() { return (B) this; } + /** + * Sets the service's clock. The clock is mainly used for testing purpose. {@link Clock} will be + * replaced by Java8's {@code java.time.Clock}. + * + * @param clock the clock to set + * @return the builder. + */ + public B clock(Clock clock) { + this.clock = clock; + return self(); + } + /** * Sets project id. * @@ -221,6 +268,7 @@ protected ServiceOptions(Builder builder) { serviceRpcFactory = builder.serviceRpcFactory; connectTimeout = builder.connectTimeout; readTimeout = builder.readTimeout; + clock = firstNonNull(builder.clock, Clock.defaultClock()); } private static AuthCredentials defaultAuthCredentials() { @@ -419,9 +467,17 @@ public int readTimeout() { return readTimeout; } + /** + * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to + * get current time. + */ + public Clock clock() { + return clock; + } + protected int baseHashCode() { return Objects.hash(projectId, host, httpTransportFactory, authCredentials, retryParams, - serviceRpcFactory); + serviceRpcFactory, connectTimeout, readTimeout, clock); } protected boolean baseEquals(ServiceOptions other) { @@ -430,7 +486,10 @@ protected boolean baseEquals(ServiceOptions other) { && Objects.equals(httpTransportFactory, other.httpTransportFactory) && Objects.equals(authCredentials, other.authCredentials) && Objects.equals(retryParams, other.retryParams) - && Objects.equals(serviceRpcFactory, other.serviceRpcFactory); + && Objects.equals(serviceRpcFactory, other.serviceRpcFactory) + && Objects.equals(connectTimeout, other.connectTimeout) + && Objects.equals(readTimeout, other.readTimeout) + && Objects.equals(clock, clock); } public abstract Builder toBuilder(); From 099240d7b6df35cd25bff45ded7bb13fa133142b Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 13 Oct 2015 18:18:47 +0200 Subject: [PATCH 031/663] Add readResolve to StorageOptions.DefaultClock --- .../src/main/java/com/google/gcloud/ServiceOptions.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index ab56c78e10..b1510ae6a9 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.ObjectStreamException; import java.io.Serializable; import java.lang.reflect.Method; import java.net.HttpURLConnection; @@ -124,6 +125,10 @@ private static class DefaultClock extends ServiceOptions.Clock implements Serial public long millis() { return System.currentTimeMillis(); } + + private Object readResolve() throws ObjectStreamException { + return DEFAULT_TIME_SOURCE; + } } } From 42d1d6729ca481168581d60bfff3aceb96f330f2 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 15 Oct 2015 13:38:29 -0700 Subject: [PATCH 032/663] update verison to 0.0.10 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 82d9db0662..42d8798f7d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.0.10-SNAPSHOT + 0.0.10 From 40ff36bcba44b538165563aa9a27980417bf7951 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Thu, 15 Oct 2015 20:52:37 +0000 Subject: [PATCH 033/663] Updating version in README files. --- google-cloud-core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index e8b0191e7e..2a3be300f4 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -17,7 +17,7 @@ Add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.0.9 + 0.0.10 ``` From 6ed6177e8fffb3ea7d4f7f05036273b2d3a0df31 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 15 Oct 2015 15:06:11 -0700 Subject: [PATCH 034/663] update version to 0.0.11-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 42d8798f7d..2275c7f076 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.0.10 + 0.0.11-SNAPSHOT From f22996d7f9848e7f9c5b5700a3ae81d1197767af Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 16 Oct 2015 15:11:20 +0200 Subject: [PATCH 035/663] Move State interface out of channels, move to core module and make it generic --- .../com/google/gcloud/RestorableState.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java b/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java new file mode 100644 index 0000000000..9cd3ee5c3c --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java @@ -0,0 +1,32 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +/** + * A common interface for restorable states. Implementations of {@code RestorableState} are capable + * of saving the state of an object to restore it for later use. + * + * Implementations of this class must implement {@link java.io.Serializable} to ensure that the + * state of a the object can be correctly serialized. + */ +public interface RestorableState { + + /** + * Returns an object whose internal state reflects the one saved in the invocation object. + */ + T restore(); +} From 7f7b76da53cc72b1c22fd27c520b9a8974f1fe40 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 16 Oct 2015 14:47:39 -0700 Subject: [PATCH 036/663] Don't allow user to set project id or namespace to null --- .../src/main/java/com/google/gcloud/ServiceOptions.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 206e1fecaa..066116e59c 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -122,7 +122,8 @@ protected B self() { } public B projectId(String projectId) { - this.projectId = projectId; + this.projectId = + checkNotNull(projectId, "Project ID cannot be set to null. Leave unset for default."); return self(); } From 4058745e60155549fa3da58e46f83afeea383e92 Mon Sep 17 00:00:00 2001 From: aozarov Date: Mon, 26 Oct 2015 10:41:38 -0700 Subject: [PATCH 037/663] Remove Serializable from AuthCredentials, ServiceFactory and ServiceRpcFactory and set factories on ServiceOptions --- .../com/google/gcloud/AuthCredentials.java | 172 ++++++++++++++---- .../java/com/google/gcloud/BaseService.java | 2 +- .../java/com/google/gcloud/Restorable.java | 15 ++ .../com/google/gcloud/RestorableState.java | 2 +- .../main/java/com/google/gcloud/Service.java | 2 +- .../com/google/gcloud/ServiceFactory.java | 28 +++ .../com/google/gcloud/ServiceOptions.java | 152 +++++++++++----- .../google/gcloud/spi/ServiceRpcFactory.java | 9 +- 8 files changed, 284 insertions(+), 98 deletions(-) create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/Restorable.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index ffc54df77a..73c66279ea 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -31,8 +31,6 @@ import java.io.IOException; import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectStreamException; import java.io.Serializable; import java.security.GeneralSecurityException; import java.security.PrivateKey; @@ -42,15 +40,34 @@ /** * Credentials for accessing Google Cloud services. */ -public abstract class AuthCredentials implements Serializable { - - private static final long serialVersionUID = 236297804453464604L; +public abstract class AuthCredentials implements Restorable { private static class AppEngineAuthCredentials extends AuthCredentials { - private static final long serialVersionUID = 7931300552744202954L; - private static final AuthCredentials INSTANCE = new AppEngineAuthCredentials(); + private static final AppEngineAuthCredentialsState STATE = + new AppEngineAuthCredentialsState(); + + private static class AppEngineAuthCredentialsState + implements RestorableState, Serializable { + + private static final long serialVersionUID = 3558563960848658928L; + + @Override + public AuthCredentials restore() { + return INSTANCE; + } + + @Override + public int hashCode() { + return getClass().getName().hashCode(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof AppEngineAuthCredentialsState; + } + } @Override protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, @@ -58,19 +75,56 @@ protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, return new AppIdentityCredential(scopes); } - private Object readResolve() throws ObjectStreamException { - return INSTANCE; + @Override + public RestorableState capture() { + return STATE; } } public static class ServiceAccountAuthCredentials extends AuthCredentials { - private static final long serialVersionUID = 8007708734318445901L; private final String account; private final PrivateKey privateKey; private static final AuthCredentials NO_CREDENTIALS = new ServiceAccountAuthCredentials(); + private static class ServiceAccountAuthCredentialsState + implements RestorableState, Serializable { + + private static final long serialVersionUID = -7302180782414633639L; + + private final String account; + private final PrivateKey privateKey; + + private ServiceAccountAuthCredentialsState(String account, PrivateKey privateKey) { + this.account = account; + this.privateKey = privateKey; + } + + @Override + public AuthCredentials restore() { + if (account == null && privateKey == null) { + return NO_CREDENTIALS; + } + return new ServiceAccountAuthCredentials(account, privateKey); + } + + @Override + public int hashCode() { + return Objects.hash(account, privateKey); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ServiceAccountAuthCredentialsState)) { + return false; + } + ServiceAccountAuthCredentialsState other = (ServiceAccountAuthCredentialsState) obj; + return Objects.equals(account, other.account) + && Objects.equals(privateKey, other.privateKey); + } + } + ServiceAccountAuthCredentials(String account, PrivateKey privateKey) { this.account = checkNotNull(account); this.privateKey = checkNotNull(privateKey); @@ -104,59 +158,94 @@ public PrivateKey privateKey() { } @Override - public int hashCode() { - return Objects.hash(account, privateKey); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ServiceAccountAuthCredentials)) { - return false; - } - ServiceAccountAuthCredentials other = (ServiceAccountAuthCredentials) obj; - return Objects.equals(account, other.account) - && Objects.equals(privateKey, other.privateKey); + public RestorableState capture() { + return new ServiceAccountAuthCredentialsState(account, privateKey); } } private static class ComputeEngineAuthCredentials extends AuthCredentials { - private static final long serialVersionUID = -5217355402127260144L; + private ComputeCredential computeCredential; - private transient ComputeCredential computeCredential; + private static final ComputeEngineAuthCredentialsState STATE = + new ComputeEngineAuthCredentialsState(); - ComputeEngineAuthCredentials() throws IOException, GeneralSecurityException { - computeCredential = getComputeCredential(); - } + private static class ComputeEngineAuthCredentialsState + implements RestorableState, Serializable { + + private static final long serialVersionUID = -6168594072854417404L; + + @Override + public AuthCredentials restore() { + try { + return new ComputeEngineAuthCredentials(); + } catch (IOException | GeneralSecurityException e) { + throw new IllegalStateException( + "Could not restore " + ComputeEngineAuthCredentials.class.getSimpleName(), e); + } + } + + @Override + public int hashCode() { + return getClass().getName().hashCode(); + } - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); - try { - computeCredential = getComputeCredential(); - } catch (GeneralSecurityException e) { - throw new IOException(e); + @Override + public boolean equals(Object obj) { + return obj instanceof ComputeEngineAuthCredentialsState; } } + ComputeEngineAuthCredentials() throws IOException, GeneralSecurityException { + computeCredential = getComputeCredential(); + } + @Override protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, Set scopes) { return computeCredential; } + + @Override + public RestorableState capture() { + return STATE; + } } private static class ApplicationDefaultAuthCredentials extends AuthCredentials { - private static final long serialVersionUID = -8306873864136099893L; + private GoogleCredentials googleCredentials; - private transient GoogleCredentials googleCredentials; + private static final ApplicationDefaultAuthCredentialsState STATE = + new ApplicationDefaultAuthCredentialsState(); - ApplicationDefaultAuthCredentials() throws IOException { - googleCredentials = GoogleCredentials.getApplicationDefault(); + private static class ApplicationDefaultAuthCredentialsState + implements RestorableState, Serializable { + + private static final long serialVersionUID = -8839085552021212257L; + + @Override + public AuthCredentials restore() { + try { + return new ApplicationDefaultAuthCredentials(); + } catch (IOException e) { + throw new IllegalStateException( + "Could not restore " + ApplicationDefaultAuthCredentials.class.getSimpleName(), e); + } + } + + @Override + public int hashCode() { + return getClass().getName().hashCode(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof ApplicationDefaultAuthCredentialsState; + } } - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); + ApplicationDefaultAuthCredentials() throws IOException { googleCredentials = GoogleCredentials.getApplicationDefault(); } @@ -165,6 +254,11 @@ protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, Set scopes) { return new HttpCredentialsAdapter(googleCredentials); } + + @Override + public RestorableState capture() { + return STATE; + } } protected abstract HttpRequestInitializer httpRequestInitializer(HttpTransport transport, diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java index 982d305829..7600d25411 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java @@ -16,7 +16,7 @@ package com.google.gcloud; -public abstract class BaseService> +public abstract class BaseService> implements Service { private final OptionsT options; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java new file mode 100644 index 0000000000..aba9735909 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java @@ -0,0 +1,15 @@ +package com.google.gcloud; + +/** + * Implementation of this interface can persist their state and restore from it. + */ +public interface Restorable> { + + /** + * Capture the state of this object. + * + * @return a {@link RestorableState} instance that contains the state for this object and can + * restore it afterwards. + */ + RestorableState capture(); +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java b/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java index 9cd3ee5c3c..0c60411cb2 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java @@ -23,7 +23,7 @@ * Implementations of this class must implement {@link java.io.Serializable} to ensure that the * state of a the object can be correctly serialized. */ -public interface RestorableState { +public interface RestorableState> { /** * Returns an object whose internal state reflects the one saved in the invocation object. diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Service.java b/google-cloud-core/src/main/java/com/google/gcloud/Service.java index 19759fb20e..2748c55058 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Service.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Service.java @@ -16,6 +16,6 @@ package com.google.gcloud; -public interface Service> { +public interface Service> { OptionsT options(); } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java new file mode 100644 index 0000000000..b59fc1e9a1 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java @@ -0,0 +1,28 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +/** + * A base interface for all service factories. + * + * Implementation must provide a public no-arg constructor. + * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. + */ +public interface ServiceFactory { + + ServiceT create(ServiceOptionsT serviceOptions); +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index b1510ae6a9..70da7831c1 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -28,14 +28,7 @@ import com.google.common.collect.Iterables; import com.google.gcloud.spi.ServiceRpcFactory; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.ObjectStreamException; -import java.io.Serializable; +import java.io.*; import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; @@ -47,8 +40,9 @@ import java.util.regex.Pattern; public abstract class ServiceOptions< + ServiceT extends Service, ServiceRpcT, - OptionsT extends ServiceOptions> + OptionsT extends ServiceOptions> implements Serializable { private static final String DEFAULT_HOST = "https://www.googleapis.com"; @@ -57,21 +51,35 @@ public abstract class ServiceOptions< private final String projectId; private final String host; - private final HttpTransportFactory httpTransportFactory; - private final AuthCredentials authCredentials; + private final String httpTransportFactoryClassName; + private final RestorableState authCredentialsState; private final RetryParams retryParams; - private final ServiceRpcFactory serviceRpcFactory; + private final String serviceRpcFactoryClassName; + private final String serviceFactoryClassName; private final int connectTimeout; private final int readTimeout; private final Clock clock; - public interface HttpTransportFactory extends Serializable { + private transient HttpTransportFactory httpTransportFactory; + private transient AuthCredentials authCredentials; + private transient ServiceRpcFactory serviceRpcFactory; + private transient ServiceFactory serviceFactory; + private transient ServiceT service; + private transient ServiceRpcT rpc; + + /** + * A base interface for all {@link HttpTransport} factories. + * + * Implementation must provide a public no-arg constructor. + * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. + */ + public interface HttpTransportFactory { HttpTransport create(); } - private enum DefaultHttpTransportFactory implements HttpTransportFactory { + public static class DefaultHttpTransportFactory implements HttpTransportFactory { - INSTANCE; + private static final HttpTransportFactory INSTANCE = new DefaultHttpTransportFactory(); @Override public HttpTransport create() { @@ -133,15 +141,17 @@ private Object readResolve() throws ObjectStreamException { } protected abstract static class Builder< + ServiceT extends Service, ServiceRpcT, - OptionsT extends ServiceOptions, - B extends Builder> { + OptionsT extends ServiceOptions, + B extends Builder> { private String projectId; private String host; private HttpTransportFactory httpTransportFactory; private AuthCredentials authCredentials; private RetryParams retryParams; + private ServiceFactory serviceFactory; private ServiceRpcFactory serviceRpcFactory; private int connectTimeout = -1; private int readTimeout = -1; @@ -149,22 +159,34 @@ protected abstract static class Builder< protected Builder() {} - protected Builder(ServiceOptions options) { + protected Builder(ServiceOptions options) { projectId = options.projectId; host = options.host; httpTransportFactory = options.httpTransportFactory; authCredentials = options.authCredentials; retryParams = options.retryParams; + serviceFactory = options.serviceFactory; serviceRpcFactory = options.serviceRpcFactory; + connectTimeout = options.connectTimeout; + readTimeout = options.readTimeout; + clock = options.clock; } - protected abstract ServiceOptions build(); + protected abstract ServiceOptions build(); @SuppressWarnings("unchecked") protected B self() { return (B) this; } + /** + * Sets the service factory. + */ + public B serviceFactory(ServiceFactory serviceFactory) { + this.serviceFactory = serviceFactory; + return self(); + } + /** * Sets the service's clock. The clock is mainly used for testing purpose. {@link Clock} will be * replaced by Java8's {@code java.time.Clock}. @@ -263,14 +285,23 @@ public B readTimeout(int readTimeout) { } } - protected ServiceOptions(Builder builder) { + protected ServiceOptions(Class> serviceFactoryClass, + Class> rpcFactoryClass, + Builder builder) { projectId = checkNotNull(builder.projectId != null ? builder.projectId : defaultProject()); host = firstNonNull(builder.host, defaultHost()); - httpTransportFactory = - firstNonNull(builder.httpTransportFactory, DefaultHttpTransportFactory.INSTANCE); + httpTransportFactory = firstNonNull(builder.httpTransportFactory, + getFromServiceLoader(HttpTransportFactory.class, DefaultHttpTransportFactory.INSTANCE)); + httpTransportFactoryClassName = httpTransportFactory.getClass().getName(); authCredentials = firstNonNull(builder.authCredentials, defaultAuthCredentials()); + authCredentialsState = authCredentials.capture(); retryParams = builder.retryParams; - serviceRpcFactory = builder.serviceRpcFactory; + serviceFactory = firstNonNull(builder.serviceFactory, + getFromServiceLoader(serviceFactoryClass, defaultServiceFactory())); + serviceFactoryClassName = serviceFactory.getClass().getName(); + serviceRpcFactory = firstNonNull(builder.serviceRpcFactory, + getFromServiceLoader(rpcFactoryClass, defaultRpcFactory())); + serviceRpcFactoryClassName = serviceRpcFactory.getClass().getName(); connectTimeout = builder.connectTimeout; readTimeout = builder.readTimeout; clock = firstNonNull(builder.clock, Clock.defaultClock()); @@ -389,10 +420,22 @@ protected static String getAppEngineProjectId() { } } - protected abstract Set scopes(); + public ServiceT service() { + if (service == null) { + service = serviceFactory.create((OptionsT) this); + } + return service; + } + + public ServiceRpcT rpc() { + if (rpc == null) { + rpc = serviceRpcFactory.create((OptionsT) this); + } + return rpc; + } /** - * Returns the project id. + * Returns the project id. */ public String projectId() { return projectId; @@ -427,13 +470,6 @@ public RetryParams retryParams() { return retryParams != null ? retryParams : RetryParams.noRetries(); } - /** - * Returns the factory for rpc services. - */ - public ServiceRpcFactory serviceRpcFactory() { - return serviceRpcFactory; - } - /** * Returns a request initializer responsible for initializing requests according to service * options. @@ -474,40 +510,56 @@ public int readTimeout() { /** * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to - * get current time. + * get current time. */ public Clock clock() { return clock; } protected int baseHashCode() { - return Objects.hash(projectId, host, httpTransportFactory, authCredentials, retryParams, - serviceRpcFactory, connectTimeout, readTimeout, clock); + return Objects.hash(projectId, host, httpTransportFactoryClassName, authCredentialsState, + retryParams, serviceFactoryClassName, serviceRpcFactoryClassName, connectTimeout, + readTimeout, clock); } - protected boolean baseEquals(ServiceOptions other) { + protected boolean baseEquals(ServiceOptions other) { return Objects.equals(projectId, other.projectId) && Objects.equals(host, other.host) - && Objects.equals(httpTransportFactory, other.httpTransportFactory) - && Objects.equals(authCredentials, other.authCredentials) + && Objects.equals(httpTransportFactoryClassName, other.httpTransportFactoryClassName) + && Objects.equals(authCredentialsState, other.authCredentialsState) && Objects.equals(retryParams, other.retryParams) - && Objects.equals(serviceRpcFactory, other.serviceRpcFactory) + && Objects.equals(serviceFactoryClassName, other.serviceFactoryClassName) + && Objects.equals(serviceRpcFactoryClassName, other.serviceRpcFactoryClassName) && Objects.equals(connectTimeout, other.connectTimeout) && Objects.equals(readTimeout, other.readTimeout) && Objects.equals(clock, clock); } - public abstract Builder toBuilder(); + private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException { + input.defaultReadObject(); + httpTransportFactory = newInstance(httpTransportFactoryClassName); + serviceFactory = newInstance(serviceFactoryClassName); + serviceRpcFactory = newInstance(serviceRpcFactoryClassName); + authCredentials = authCredentialsState.restore(); + } - /** - * Creates a service RPC using a factory loaded by {@link ServiceLoader}. - */ - protected static - > - ServiceRpcT createRpc(OptionsT options, - Class> factoryClass) { - ServiceRpcFactory factory = - Iterables.getFirst(ServiceLoader.load(factoryClass), null); - return factory == null ? null : factory.create(options); + private static T newInstance(String className) throws IOException, ClassNotFoundException { + try { + return (T) Class.forName(className).newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + throw new IOException(e); + } + } + + protected abstract > T defaultServiceFactory(); + + protected abstract > T defaultRpcFactory(); + + protected abstract Set scopes(); + + public abstract > B toBuilder(); + + private static T getFromServiceLoader(Class clazz, T defaultInstance) { + return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance); } } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java index 89e08cda9e..d20b690167 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java @@ -18,16 +18,13 @@ import com.google.gcloud.ServiceOptions; -import java.io.Serializable; - /** * A base interface for all service RPC factories. + * + * Implementation must provide a public no-arg constructor. * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. */ -public interface ServiceRpcFactory< - ServiceRpcT, - OptionsT extends ServiceOptions> - extends Serializable { +public interface ServiceRpcFactory { ServiceRpcT create(OptionsT options); } From e82edf703f2d0f478ce1c28186788fc3fba946c7 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 27 Oct 2015 11:18:15 +0100 Subject: [PATCH 038/663] Override artifact id for Dependency Information report --- google-cloud-core/pom.xml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2275c7f076..1062f4d311 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -90,4 +90,25 @@ test + + + + org.apache.maven.plugins + maven-site-plugin + 3.4 + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.8 + + gcloud-java-core + + + + + + + From 55d7aeb1572bf52da87f3852d131aebf577d931f Mon Sep 17 00:00:00 2001 From: aozarov Date: Tue, 27 Oct 2015 12:15:39 -0700 Subject: [PATCH 039/663] use static constant for default factories, add example to Restorable and use mock instead of niceMock --- .../java/com/google/gcloud/Restorable.java | 17 ++++++- .../com/google/gcloud/ServiceOptions.java | 44 +++++++++++-------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java index aba9735909..83ef39a4dd 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java @@ -2,11 +2,26 @@ /** * Implementation of this interface can persist their state and restore from it. + * + *

+ * A typical capture usage: + *

  {@code
+ * X restorableObj; // X instanceof Restorable
+ * RestorableState state = restorableObj.capture();
+ * .. persist state
+ * }
+ * + * A typical restore usage: + *
  {@code
+ * RestorableState state = ... // read from persistence
+ * X restorableObj = state.restore();
+ * ...
+ * }
*/ public interface Restorable> { /** - * Capture the state of this object. + * Captures the state of this object. * * @return a {@link RestorableState} instance that contains the state for this object and can * restore it afterwards. diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 70da7831c1..4a68aa7894 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -1,17 +1,15 @@ /* * Copyright 2015 Google Inc. All Rights Reserved. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package com.google.gcloud; @@ -28,7 +26,15 @@ import com.google.common.collect.Iterables; import com.google.gcloud.spi.ServiceRpcFactory; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.ObjectInputStream; +import java.io.ObjectStreamException; +import java.io.Serializable; import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; @@ -70,8 +76,8 @@ public abstract class ServiceOptions< /** * A base interface for all {@link HttpTransport} factories. * - * Implementation must provide a public no-arg constructor. - * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. + * Implementation must provide a public no-arg constructor. Loading of a factory implementation is + * done via {@link java.util.ServiceLoader}. */ public interface HttpTransportFactory { HttpTransport create(); @@ -264,7 +270,7 @@ public B serviceRpcFactory(ServiceRpcFactory serviceRpcFa * Sets the timeout in milliseconds to establish a connection. * * @param connectTimeout connection timeout in milliseconds. 0 for an infinite timeout, a - * negative number for the default value (20000). + * negative number for the default value (20000). * @return the builder. */ public B connectTimeout(int connectTimeout) { @@ -275,8 +281,8 @@ public B connectTimeout(int connectTimeout) { /** * Sets the timeout in milliseconds to read data from an established connection. * - * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a - * negative number for the default value (20000). + * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a negative number + * for the default value (20000). * @return the builder. */ public B readTimeout(int readTimeout) { @@ -362,10 +368,10 @@ protected static String googleCloudProjectId() { } catch (IOException ignore) { // ignore } - File configDir; + File configDir; if (System.getenv().containsKey("CLOUDSDK_CONFIG")) { configDir = new File(System.getenv("CLOUDSDK_CONFIG")); - } else if (isWindows() && System.getenv().containsKey("APPDATA")) { + } else if (isWindows() && System.getenv().containsKey("APPDATA")) { configDir = new File(System.getenv("APPDATA"), "gcloud"); } else { configDir = new File(System.getProperty("user.home"), ".config/gcloud"); @@ -509,8 +515,8 @@ public int readTimeout() { } /** - * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to - * get current time. + * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to get + * current time. */ public Clock clock() { return clock; From 44740431799c61873ba0285ac45996cca35ec5de Mon Sep 17 00:00:00 2001 From: aozarov Date: Tue, 27 Oct 2015 12:24:53 -0700 Subject: [PATCH 040/663] add and fix copyright headers --- .../main/java/com/google/gcloud/Restorable.java | 16 ++++++++++++++++ .../java/com/google/gcloud/ServiceOptions.java | 16 +++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java index 83ef39a4dd..51391e33bd 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.gcloud; /** diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 4a68aa7894..f22c4d51e3 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -1,15 +1,17 @@ /* * Copyright 2015 Google Inc. All Rights Reserved. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.google.gcloud; From ca318bac03df7cd028bd59db0426033a12d2943d Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 27 Oct 2015 22:39:50 +0100 Subject: [PATCH 041/663] Copy report configuration to submodules poms --- google-cloud-core/pom.xml | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1062f4d311..6d25aa42ce 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -97,13 +97,90 @@ maven-site-plugin 3.4 + true + + org.apache.maven.plugins + maven-changelog-plugin + 2.3 + org.apache.maven.plugins maven-project-info-reports-plugin 2.8 + + + + index + dependency-info + dependencies + dependency-convergence + project-team + mailing-list + cim + issue-tracking + license + scm + dependency-management + distribution-management + summary + modules + + + + true + true + true + true gcloud-java-core + jar + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.10 + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + html + + javadoc + + + + + true + protected + true + ${project.build.directory}/javadoc + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.18.1 + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.16 + + checkstyle.xml + false + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.7 + + true From b16fc41c7eb3b34e2f7e52e7f37c399043c29495 Mon Sep 17 00:00:00 2001 From: aozarov Date: Tue, 27 Oct 2015 17:28:50 -0700 Subject: [PATCH 042/663] fix checkstyle issues --- .../src/main/java/com/google/gcloud/RetryParams.java | 3 ++- .../main/java/com/google/gcloud/ServiceOptions.java | 10 +++++----- .../java/com/google/gcloud/ExceptionHandlerTest.java | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java b/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java index 24983326cc..461dbac77f 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java @@ -251,7 +251,8 @@ public double getRetryDelayBackoffFactor() { } /** - * Returns the totalRetryPeriodMillis. Default value is {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}. + * Returns the totalRetryPeriodMillis. Default value is + * {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}. */ public long getTotalRetryPeriodMillis() { return totalRetryPeriodMillis; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index f22c4d51e3..8555b8d61e 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -48,9 +48,9 @@ import java.util.regex.Pattern; public abstract class ServiceOptions< - ServiceT extends Service, - ServiceRpcT, - OptionsT extends ServiceOptions> + ServiceT extends Service, + ServiceRpcT, + OptionsT extends ServiceOptions> implements Serializable { private static final String DEFAULT_HOST = "https://www.googleapis.com"; @@ -116,9 +116,9 @@ public HttpTransport create() { * Implementations should implement {@code Serializable} wherever possible and must document * whether or not they do support serialization. */ - public static abstract class Clock { + public abstract static class Clock { - private static ServiceOptions.Clock DEFAULT_TIME_SOURCE = new DefaultClock(); + private static final ServiceOptions.Clock DEFAULT_TIME_SOURCE = new DefaultClock(); /** * Returns current time in milliseconds according to this clock. diff --git a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java index 5ce05ad900..c182515dbb 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java @@ -23,9 +23,9 @@ import com.google.gcloud.ExceptionHandler.Interceptor; import com.google.gcloud.ExceptionHandler.Interceptor.RetryResult; -import org.junit.rules.ExpectedException; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.io.FileNotFoundException; import java.io.IOException; From 51dfaf015d9d08927a0fa490b6008e8a8dc44be9 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 28 Oct 2015 10:31:48 -0700 Subject: [PATCH 043/663] Remove todos from core and datastore --- .../src/main/java/com/google/gcloud/ServiceOptions.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 8555b8d61e..c58a71c8b7 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -411,8 +411,6 @@ private static boolean isWindows() { } protected static String getAppEngineProjectId() { - // TODO(ozarov): An alternative to reflection would be to depend on AE api jar: - // http://mvnrepository.com/artifact/com.google.appengine/appengine-api-1.0-sdk/1.2.0 try { Class factoryClass = Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory"); From 7ccf39f23c4c1ddfddde95acaa840405b72e71e7 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 28 Oct 2015 11:56:29 -0700 Subject: [PATCH 044/663] Condense modules' pom.xml for site generation --- google-cloud-core/pom.xml | 101 ++------------------------------------ 1 file changed, 3 insertions(+), 98 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6d25aa42ce..e849594226 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -13,6 +13,9 @@ gcloud-java-pom 0.0.11-SNAPSHOT + + gcloud-java-core + com.google.auth @@ -90,102 +93,4 @@ test - - - - org.apache.maven.plugins - maven-site-plugin - 3.4 - - true - - - org.apache.maven.plugins - maven-changelog-plugin - 2.3 - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.8 - - - - index - dependency-info - dependencies - dependency-convergence - project-team - mailing-list - cim - issue-tracking - license - scm - dependency-management - distribution-management - summary - modules - - - - - true - true - true - true - gcloud-java-core - jar - - - - org.apache.maven.plugins - maven-dependency-plugin - 2.10 - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - - html - - javadoc - - - - - true - protected - true - ${project.build.directory}/javadoc - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.18.1 - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.16 - - checkstyle.xml - false - - - - org.codehaus.mojo - cobertura-maven-plugin - 2.7 - - true - - - - - - - From 12506518c03965c38f79e48bf608201da1aacdd1 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 29 Oct 2015 16:19:30 +0100 Subject: [PATCH 045/663] Add applicationName to Options, set user agent accordingly in Storage --- .../com/google/gcloud/ServiceOptions.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index c58a71c8b7..1be1f16115 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -40,10 +40,14 @@ import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Enumeration; import java.util.Locale; import java.util.Objects; import java.util.ServiceLoader; import java.util.Set; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -56,6 +60,11 @@ public abstract class ServiceOptions< private static final String DEFAULT_HOST = "https://www.googleapis.com"; private static final long serialVersionUID = 1203687993961393350L; private static final String PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + private static final String MANIFEST_ARTIFACT_ID_KEY = "artifactId"; + private static final String MANIFEST_VERSION_KEY = "Implementation-Version"; + private static final String ARTIFACT_ID = "gcloud-java-core"; + private static final String APPLICATION_BASE_NAME = "gcloud-java"; + private static final String APPLICATION_NAME = getApplicationName(); private final String projectId; private final String host; @@ -522,6 +531,13 @@ public Clock clock() { return clock; } + /** + * Returns the application's name as a string in the format {@code gcloud-java/[version]}. + */ + public String applicationName() { + return APPLICATION_NAME; + } + protected int baseHashCode() { return Objects.hash(projectId, host, httpTransportFactoryClassName, authCredentialsState, retryParams, serviceFactoryClassName, serviceRpcFactoryClassName, connectTimeout, @@ -568,4 +584,23 @@ private static T newInstance(String className) throws IOException, ClassNotF private static T getFromServiceLoader(Class clazz, T defaultInstance) { return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance); } + + private static String getApplicationName() { + String version = null; + try { + Enumeration resources = + ServiceOptions.class.getClassLoader().getResources(JarFile.MANIFEST_NAME); + while (resources.hasMoreElements() && version == null) { + Manifest manifest = new Manifest(resources.nextElement().openStream()); + Attributes manifestAttributes = manifest.getMainAttributes(); + String artifactId = manifestAttributes.getValue(MANIFEST_ARTIFACT_ID_KEY); + if (artifactId != null && artifactId.equals(ARTIFACT_ID)) { + version = manifestAttributes.getValue(MANIFEST_VERSION_KEY); + } + } + } catch (IOException e) { + // ignore + } + return version != null ? APPLICATION_BASE_NAME + "/" + version : APPLICATION_BASE_NAME; + } } From ed4b6e128d9a90b2c1e91e7fb661a0e38a187531 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 3 Nov 2015 18:06:36 +0100 Subject: [PATCH 046/663] Rename ListResult and move to core module --- .../main/java/com/google/gcloud/BasePage.java | 77 +++++++++++++++++++ .../src/main/java/com/google/gcloud/Page.java | 34 ++++++++ .../java/com/google/gcloud/BasePageTest.java | 48 ++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/BasePage.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/Page.java create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BasePage.java b/google-cloud-core/src/main/java/com/google/gcloud/BasePage.java new file mode 100644 index 0000000000..ce62b334a7 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/BasePage.java @@ -0,0 +1,77 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import java.io.Serializable; +import java.util.Collections; +import java.util.Iterator; +import java.util.Objects; + +/** + * Base implementation for Google Cloud paginated results. + */ +public class BasePage implements Page, Serializable { + + private static final long serialVersionUID = -6937287874908527950L; + + private final String cursor; + private final Iterable results; + private final NextPageFetcher pageFetcher; + + public interface NextPageFetcher extends Serializable { + Page nextPage(); + } + + public BasePage(NextPageFetcher pageFetcher, String cursor, Iterable results) { + this.pageFetcher = pageFetcher; + this.cursor = cursor; + this.results = results; + } + + @Override + public String nextPageCursor() { + return cursor; + } + + @Override + public Page nextPage() { + if (cursor == null || pageFetcher == null) { + return null; + } + return pageFetcher.nextPage(); + } + + @Override + public Iterator iterator() { + return results == null ? Collections.emptyIterator() : results.iterator(); + } + + @Override + public int hashCode() { + return Objects.hash(cursor, results); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof BasePage)) { + return false; + } + BasePage other = (BasePage) obj; + return Objects.equals(cursor, other.cursor) + && Objects.equals(results, other.results); + } +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Page.java b/google-cloud-core/src/main/java/com/google/gcloud/Page.java new file mode 100644 index 0000000000..21d465bb79 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/Page.java @@ -0,0 +1,34 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +/** + * Interface for Google Cloud paginated results. + */ +public interface Page extends Iterable { + + /** + * Returns the cursor for the nextPage or {@code null} if no more results. + */ + String nextPageCursor(); + + /** + * Returns the next page of results or {@code null} if no more result. + */ + Page nextPage(); + +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java new file mode 100644 index 0000000000..888d7ace7a --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import com.google.gcloud.BasePage; + +import org.junit.Test; + +import java.util.Collections; + +public class BasePageTest { + + @Test + public void testPage() throws Exception { + ImmutableList values = ImmutableList.of("1", "2"); + final BasePage nextResult = + new BasePage<>(null, "c", Collections.emptyList()); + BasePage.NextPageFetcher fetcher = new BasePage.NextPageFetcher() { + + @Override + public BasePage nextPage() { + return nextResult; + } + }; + BasePage result = new BasePage<>(fetcher, "c", values); + assertEquals(nextResult, result.nextPage()); + assertEquals("c", result.nextPageCursor()); + assertEquals(values, ImmutableList.copyOf(result.iterator())); + + } +} From bfe446bf22c27a3b8b2e5a763a50d1c06a10a428 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 4 Nov 2015 12:04:01 +0100 Subject: [PATCH 047/663] Remove implements Serializable from BasePage and implements Iterable from Page - Add values() method to page, to return results - Add javadoc to BasePage to highlight that Iterable must be serializable - Delete BlobPage and BlobPageTest classes - Add BlobPageFetcher and LazyBlobIterable to Bucket class - Implement Bucket.list using BasePage, BlobPageFetcher and LazyBlobIterable - Update StorageExaple to iterate through pages --- .../main/java/com/google/gcloud/BasePage.java | 21 +++++++++++-------- .../src/main/java/com/google/gcloud/Page.java | 19 ++++++++++++++++- .../java/com/google/gcloud/BasePageTest.java | 4 +--- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BasePage.java b/google-cloud-core/src/main/java/com/google/gcloud/BasePage.java index ce62b334a7..f041b5cf5d 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BasePage.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BasePage.java @@ -18,30 +18,38 @@ import java.io.Serializable; import java.util.Collections; -import java.util.Iterator; import java.util.Objects; /** * Base implementation for Google Cloud paginated results. */ -public class BasePage implements Page, Serializable { +public class BasePage implements Page, Serializable { - private static final long serialVersionUID = -6937287874908527950L; + private static final long serialVersionUID = 3914827379823557934L; private final String cursor; private final Iterable results; private final NextPageFetcher pageFetcher; - public interface NextPageFetcher extends Serializable { + public interface NextPageFetcher extends Serializable { Page nextPage(); } + /** + * Creates a {@code BasePage} object. In order for the object to be serializable the {@code + * results} parameter must be serializable. + */ public BasePage(NextPageFetcher pageFetcher, String cursor, Iterable results) { this.pageFetcher = pageFetcher; this.cursor = cursor; this.results = results; } + @Override + public Iterable values() { + return results == null ? Collections.EMPTY_LIST : results; + } + @Override public String nextPageCursor() { return cursor; @@ -55,11 +63,6 @@ public Page nextPage() { return pageFetcher.nextPage(); } - @Override - public Iterator iterator() { - return results == null ? Collections.emptyIterator() : results.iterator(); - } - @Override public int hashCode() { return Objects.hash(cursor, results); diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Page.java b/google-cloud-core/src/main/java/com/google/gcloud/Page.java index 21d465bb79..1b77545627 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Page.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Page.java @@ -18,8 +18,25 @@ /** * Interface for Google Cloud paginated results. + * + *

+ * A typical {@code Page} usage: + *

 {@code
+ * Page page = ...; // get a Page instance
+ * while (page != null) {
+ *   for (T value : page.values()) {
+ *     // do something with value
+ *   }
+ *   page = page.nextPage();
+ * }
+ * }
*/ -public interface Page extends Iterable { +public interface Page { + + /** + * Returns the values contained in this page. + */ + Iterable values(); /** * Returns the cursor for the nextPage or {@code null} if no more results. diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java index 888d7ace7a..06e7c61675 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java @@ -19,7 +19,6 @@ import static org.junit.Assert.assertEquals; import com.google.common.collect.ImmutableList; -import com.google.gcloud.BasePage; import org.junit.Test; @@ -42,7 +41,6 @@ public BasePage nextPage() { BasePage result = new BasePage<>(fetcher, "c", values); assertEquals(nextResult, result.nextPage()); assertEquals("c", result.nextPageCursor()); - assertEquals(values, ImmutableList.copyOf(result.iterator())); - + assertEquals(values, ImmutableList.copyOf(result.values().iterator())); } } From 108aa41eae301b57ad36e85e3ab0304532caf2da Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 4 Nov 2015 19:36:50 +0100 Subject: [PATCH 048/663] Rename BasePage to PageImpl --- .../google/gcloud/{BasePage.java => PageImpl.java} | 10 +++++----- .../gcloud/{BasePageTest.java => PageImplTest.java} | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) rename google-cloud-core/src/main/java/com/google/gcloud/{BasePage.java => PageImpl.java} (87%) rename google-cloud-core/src/test/java/com/google/gcloud/{BasePageTest.java => PageImplTest.java} (79%) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BasePage.java b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java similarity index 87% rename from google-cloud-core/src/main/java/com/google/gcloud/BasePage.java rename to google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java index f041b5cf5d..3925079c8d 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BasePage.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java @@ -23,7 +23,7 @@ /** * Base implementation for Google Cloud paginated results. */ -public class BasePage implements Page, Serializable { +public class PageImpl implements Page, Serializable { private static final long serialVersionUID = 3914827379823557934L; @@ -36,10 +36,10 @@ public interface NextPageFetcher extends Serializable { } /** - * Creates a {@code BasePage} object. In order for the object to be serializable the {@code + * Creates a {@code PageImpl} object. In order for the object to be serializable the {@code * results} parameter must be serializable. */ - public BasePage(NextPageFetcher pageFetcher, String cursor, Iterable results) { + public PageImpl(NextPageFetcher pageFetcher, String cursor, Iterable results) { this.pageFetcher = pageFetcher; this.cursor = cursor; this.results = results; @@ -70,10 +70,10 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (!(obj instanceof BasePage)) { + if (!(obj instanceof PageImpl)) { return false; } - BasePage other = (BasePage) obj; + PageImpl other = (PageImpl) obj; return Objects.equals(cursor, other.cursor) && Objects.equals(results, other.results); } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java b/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java similarity index 79% rename from google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java rename to google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java index 06e7c61675..78aa3feaa2 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BasePageTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java @@ -24,21 +24,21 @@ import java.util.Collections; -public class BasePageTest { +public class PageImplTest { @Test public void testPage() throws Exception { ImmutableList values = ImmutableList.of("1", "2"); - final BasePage nextResult = - new BasePage<>(null, "c", Collections.emptyList()); - BasePage.NextPageFetcher fetcher = new BasePage.NextPageFetcher() { + final PageImpl nextResult = + new PageImpl<>(null, "c", Collections.emptyList()); + PageImpl.NextPageFetcher fetcher = new PageImpl.NextPageFetcher() { @Override - public BasePage nextPage() { + public PageImpl nextPage() { return nextResult; } }; - BasePage result = new BasePage<>(fetcher, "c", values); + PageImpl result = new PageImpl<>(fetcher, "c", values); assertEquals(nextResult, result.nextPage()); assertEquals("c", result.nextPageCursor()); assertEquals(values, ImmutableList.copyOf(result.values().iterator())); From 25967a0d14c9a3d442f0e20fab91a62e69f57dd0 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 4 Nov 2015 17:04:25 -0800 Subject: [PATCH 049/663] Create BaseServiceException in gcloud-java-core --- .../google/gcloud/BaseServiceException.java | 51 +++++++++++++++++++ .../gcloud/BaseServiceExceptionTest.java | 45 ++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java new file mode 100644 index 0000000000..45c047d471 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java @@ -0,0 +1,51 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +/** + * Base service exception. + */ +public class BaseServiceException extends RuntimeException { + + private static final long serialVersionUID = 5028833760039966178L; + + private final int code; + private final boolean retryable; + + public BaseServiceException(int code, String message, boolean retryable) { + super(message); + this.code = code; + this.retryable = retryable; + } + + public BaseServiceException(int code, String message, boolean retryable, Exception cause) { + super(message, cause); + this.code = code; + this.retryable = retryable; + } + + /** + * Returns the code associated with this exception. + */ + public int code() { + return code; + } + + public boolean retryable() { + return retryable; + } +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java new file mode 100644 index 0000000000..f30fd3abfb --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Tests for {@link BaseServiceException}. + */ +public class BaseServiceExceptionTest { + + private final int code = 1; + private final String message = "some message"; + private final boolean retryable = true; + + @Test + public void testBaseServiceException() { + BaseServiceException serviceException = new BaseServiceException(code, message, retryable); + assertEquals(serviceException.code(), code); + assertEquals(serviceException.getMessage(), message); + assertEquals(serviceException.getCause(), null); + + Exception cause = new RuntimeException(); + serviceException = new BaseServiceException(code, message, retryable, cause); + assertEquals(serviceException.code(), code); + assertEquals(serviceException.getMessage(), message); + assertEquals(serviceException.getCause(), cause); + } +} From e8160551cdfd4e220fb1fcf31af46fe01a587642 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 4 Nov 2015 19:06:58 -0800 Subject: [PATCH 050/663] Rename enum, fix docs, and make accessors package private --- .../main/java/com/google/gcloud/BaseServiceException.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java index 45c047d471..cd09334267 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java @@ -17,7 +17,7 @@ package com.google.gcloud; /** - * Base service exception. + * Base class for all service exceptions. */ public class BaseServiceException extends RuntimeException { @@ -45,6 +45,9 @@ public int code() { return code; } + /** + * Returns {@code true} when it is safe to retry the operation that caused this exception. + */ public boolean retryable() { return retryable; } From 42525cefae2a843bfcd15d6fc7faec55402bc050 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 5 Nov 2015 16:56:16 +0100 Subject: [PATCH 051/663] Add sbt/gradle dependencies to READMEs, change update_docs_version.sh --- google-cloud-core/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 2a3be300f4..032127540d 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -12,7 +12,7 @@ This module provides common functionality required by service-specific modules o Quickstart ---------- -Add this to your pom.xml file +If you are using Maven, add this to your pom.xml file ```xml com.google.gcloud @@ -20,6 +20,14 @@ Add this to your pom.xml file 0.0.10 ``` +If you are using Gradle, add this to your dependencies +```Groovy +compile 'com.google.gcloud:gcloud-java-core:jar:0.0.10' +``` +If you are using SBT, add this to your dependencies +```Scala +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.10" +``` Java Versions ------------- From 9763cd7cb058ee2067aa2276fa7b3eec6ad2eb01 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 5 Nov 2015 16:19:53 -0800 Subject: [PATCH 052/663] update location where we look for config file when using gcloud SDK to get project ID --- .../java/com/google/gcloud/ServiceOptions.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 1be1f16115..8988978332 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -30,6 +30,7 @@ import java.io.BufferedReader; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; @@ -387,8 +388,18 @@ protected static String googleCloudProjectId() { } else { configDir = new File(System.getProperty("user.home"), ".config/gcloud"); } - try (BufferedReader reader = - new BufferedReader(new FileReader(new File(configDir, "properties")))) { + FileReader fileReader; + try { + fileReader = new FileReader(new File(configDir, "configurations/config_default")); + } catch (FileNotFoundException newConfigFileNotFoundEx) { + try { + fileReader = new FileReader(new File(configDir, "properties")); + } catch (FileNotFoundException oldConfigFileNotFoundEx) { + // return null if we can't find config file + return null; + } + } + try (BufferedReader reader = new BufferedReader(fileReader)) { String line; String section = null; Pattern projectPattern = Pattern.compile("^project\\s*=\\s*(.*)$"); From cc9236fdaf059f0398c83283ea3da1a1aab0bae0 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 6 Nov 2015 11:31:14 +0100 Subject: [PATCH 053/663] Add iterateAll method to Page, update example and snippet --- .../src/main/java/com/google/gcloud/Page.java | 22 ++++++++++-- .../main/java/com/google/gcloud/PageImpl.java | 35 +++++++++++++++++++ .../java/com/google/gcloud/PageImplTest.java | 31 ++++++++++++---- 3 files changed, 78 insertions(+), 10 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Page.java b/google-cloud-core/src/main/java/com/google/gcloud/Page.java index 1b77545627..2819b56a17 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Page.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Page.java @@ -16,11 +16,22 @@ package com.google.gcloud; +import java.util.Iterator; + /** * Interface for Google Cloud paginated results. * *

- * A typical {@code Page} usage: + * Use {@code Page} to iterate through all values (also in next pages): + *

 {@code
+ * Page page = ...; // get a Page instance
+ * Iterator iterator = page.iterateAll();
+ * while (iterator.hasNext()) {
+ *   T value = iterator.next();
+ *   // do something with value
+ * }}
+ *

+ * Or handle pagination explicitly: *

 {@code
  * Page page = ...; // get a Page instance
  * while (page != null) {
@@ -28,8 +39,7 @@
  *     // do something with value
  *   }
  *   page = page.nextPage();
- * }
- * }
+ * }} */ public interface Page { @@ -38,6 +48,12 @@ public interface Page { */ Iterable values(); + /** + * Returns an iterator for all values, possibly also in the next pages. Once current page's values + * are traversed the iterator fetches next page, if any. + */ + Iterator iterateAll(); + /** * Returns the cursor for the nextPage or {@code null} if no more results. */ diff --git a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java index 3925079c8d..5f70b22ec5 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java @@ -16,8 +16,11 @@ package com.google.gcloud; +import com.google.common.collect.AbstractIterator; + import java.io.Serializable; import java.util.Collections; +import java.util.Iterator; import java.util.Objects; /** @@ -35,6 +38,33 @@ public interface NextPageFetcher extends Serializable { Page nextPage(); } + static class PageIterator extends AbstractIterator { + + private Iterator currentPageIterator; + private Page currentPage; + + PageIterator(Page currentPage) { + this.currentPageIterator = currentPage.values().iterator(); + this.currentPage = currentPage; + } + + @Override + protected T computeNext() { + if (currentPageIterator.hasNext()) { + return currentPageIterator.next(); + } + Page nextPage = currentPage.nextPage(); + if (nextPage != null) { + currentPage = nextPage; + currentPageIterator = currentPage.values().iterator(); + if (currentPageIterator.hasNext()) { + return currentPageIterator.next(); + } + } + return endOfData(); + } + } + /** * Creates a {@code PageImpl} object. In order for the object to be serializable the {@code * results} parameter must be serializable. @@ -50,6 +80,11 @@ public Iterable values() { return results == null ? Collections.EMPTY_LIST : results; } + @Override + public Iterator iterateAll() { + return new PageIterator(this); + } + @Override public String nextPageCursor() { return cursor; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java b/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java index 78aa3feaa2..fb289186de 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java @@ -26,21 +26,38 @@ public class PageImplTest { + private static final ImmutableList VALUES = ImmutableList.of("1", "2"); + private static final ImmutableList NEXT_VALUES = ImmutableList.of("3", "4"); + private static final ImmutableList ALL_VALUES = ImmutableList.builder() + .addAll(VALUES) + .addAll(NEXT_VALUES) + .build(); + @Test - public void testPage() throws Exception { - ImmutableList values = ImmutableList.of("1", "2"); - final PageImpl nextResult = - new PageImpl<>(null, "c", Collections.emptyList()); + public void testPage() { + final PageImpl nextResult = new PageImpl<>(null, "c", NEXT_VALUES); PageImpl.NextPageFetcher fetcher = new PageImpl.NextPageFetcher() { - @Override public PageImpl nextPage() { return nextResult; } }; - PageImpl result = new PageImpl<>(fetcher, "c", values); + PageImpl result = new PageImpl<>(fetcher, "c", VALUES); assertEquals(nextResult, result.nextPage()); assertEquals("c", result.nextPageCursor()); - assertEquals(values, ImmutableList.copyOf(result.values().iterator())); + assertEquals(VALUES, result.values()); + } + + @Test + public void testIterateAll() { + final PageImpl nextResult = new PageImpl<>(null, "c", NEXT_VALUES); + PageImpl.NextPageFetcher fetcher = new PageImpl.NextPageFetcher() { + @Override + public PageImpl nextPage() { + return nextResult; + } + }; + PageImpl result = new PageImpl<>(fetcher, "c", VALUES); + assertEquals(ALL_VALUES, ImmutableList.copyOf(result.iterateAll())); } } From dd2b75be523f5a2524605e028b8188c5e5196f1c Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 6 Nov 2015 17:41:50 -0800 Subject: [PATCH 054/663] update auth dependency --- google-cloud-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e849594226..f12267db49 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -20,12 +20,12 @@ com.google.auth google-auth-library-credentials - 0.1.0 + 0.3.0 com.google.auth google-auth-library-oauth2-http - 0.1.0 + 0.3.0 com.google.http-client From 75b9824bb31bde2e2436cb8e79003e3a401ed1d2 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 6 Nov 2015 18:10:50 -0800 Subject: [PATCH 055/663] Auth cleanup --- .../com/google/gcloud/AuthCredentials.java | 113 +----------------- .../com/google/gcloud/ServiceOptions.java | 35 +++--- 2 files changed, 17 insertions(+), 131 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 73c66279ea..990d30eca6 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -19,12 +19,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; -import com.google.api.client.googleapis.compute.ComputeCredential; -import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential; -import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; -import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.jackson.JacksonFactory; import com.google.auth.http.HttpCredentialsAdapter; import com.google.auth.oauth2.GoogleCredentials; @@ -32,7 +28,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.Serializable; -import java.security.GeneralSecurityException; import java.security.PrivateKey; import java.util.Objects; import java.util.Set; @@ -42,45 +37,6 @@ */ public abstract class AuthCredentials implements Restorable { - private static class AppEngineAuthCredentials extends AuthCredentials { - - private static final AuthCredentials INSTANCE = new AppEngineAuthCredentials(); - private static final AppEngineAuthCredentialsState STATE = - new AppEngineAuthCredentialsState(); - - private static class AppEngineAuthCredentialsState - implements RestorableState, Serializable { - - private static final long serialVersionUID = 3558563960848658928L; - - @Override - public AuthCredentials restore() { - return INSTANCE; - } - - @Override - public int hashCode() { - return getClass().getName().hashCode(); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof AppEngineAuthCredentialsState; - } - } - - @Override - protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, - Set scopes) { - return new AppIdentityCredential(scopes); - } - - @Override - public RestorableState capture() { - return STATE; - } - } - public static class ServiceAccountAuthCredentials extends AuthCredentials { private final String account; @@ -163,55 +119,6 @@ public RestorableState capture() { } } - private static class ComputeEngineAuthCredentials extends AuthCredentials { - - private ComputeCredential computeCredential; - - private static final ComputeEngineAuthCredentialsState STATE = - new ComputeEngineAuthCredentialsState(); - - private static class ComputeEngineAuthCredentialsState - implements RestorableState, Serializable { - - private static final long serialVersionUID = -6168594072854417404L; - - @Override - public AuthCredentials restore() { - try { - return new ComputeEngineAuthCredentials(); - } catch (IOException | GeneralSecurityException e) { - throw new IllegalStateException( - "Could not restore " + ComputeEngineAuthCredentials.class.getSimpleName(), e); - } - } - - @Override - public int hashCode() { - return getClass().getName().hashCode(); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof ComputeEngineAuthCredentialsState; - } - } - - ComputeEngineAuthCredentials() throws IOException, GeneralSecurityException { - computeCredential = getComputeCredential(); - } - - @Override - protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, - Set scopes) { - return computeCredential; - } - - @Override - public RestorableState capture() { - return STATE; - } - } - private static class ApplicationDefaultAuthCredentials extends AuthCredentials { private GoogleCredentials googleCredentials; @@ -264,21 +171,12 @@ public RestorableState capture() { protected abstract HttpRequestInitializer httpRequestInitializer(HttpTransport transport, Set scopes); - public static AuthCredentials createForAppEngine() { - return AppEngineAuthCredentials.INSTANCE; - } - - public static AuthCredentials createForComputeEngine() - throws IOException, GeneralSecurityException { - return new ComputeEngineAuthCredentials(); - } - /** * Returns the Application Default Credentials. * *

Returns the Application Default Credentials which are credentials that identify and * authorize the whole application. This is the built-in service account if running on - * Google Compute Engine or the credentials file can be read from the path in the environment + * Google App/Compute Engine or the credentials file can be read from the path in the environment * variable GOOGLE_APPLICATION_CREDENTIALS. *

* @@ -327,13 +225,4 @@ public static ServiceAccountAuthCredentials createForJson(InputStream jsonCreden public static AuthCredentials noCredentials() { return ServiceAccountAuthCredentials.NO_CREDENTIALS; } - - static ComputeCredential getComputeCredential() throws IOException, GeneralSecurityException { - NetHttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); - // Try to connect using Google Compute Engine service account credentials. - ComputeCredential credential = new ComputeCredential(transport, new JacksonFactory()); - // Force token refresh to detect if we are running on Google Compute Engine. - credential.refreshToken(); - return credential; - } } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 8988978332..876317162a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -21,10 +21,13 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.api.client.extensions.appengine.http.UrlFetchTransport; +import com.google.api.client.googleapis.compute.ComputeCredential; +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.client.json.jackson.JacksonFactory; import com.google.common.collect.Iterables; import com.google.gcloud.spi.ServiceRpcFactory; @@ -41,6 +44,7 @@ import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; +import java.security.GeneralSecurityException; import java.util.Enumeration; import java.util.Locale; import java.util.Objects; @@ -111,12 +115,22 @@ public HttpTransport create() { } // Consider Compute try { - return AuthCredentials.getComputeCredential().getTransport(); + return getComputeHttpTransport(); } catch (Exception e) { // Maybe not on GCE } return new NetHttpTransport(); } + + private static HttpTransport getComputeHttpTransport() + throws IOException, GeneralSecurityException { + NetHttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); + // Try to connect using Google Compute Engine service account credentials. + ComputeCredential credential = new ComputeCredential(transport, new JacksonFactory()); + // Force token refresh to detect if we are running on Google Compute Engine. + credential.refreshToken(); + return transport; + } } /** @@ -326,28 +340,11 @@ protected ServiceOptions(Class> ser } private static AuthCredentials defaultAuthCredentials() { - // Consider App Engine. This will not be needed once issue #21 is fixed. - if (appEngineAppId() != null) { - try { - return AuthCredentials.createForAppEngine(); - } catch (Exception ignore) { - // Maybe not on App Engine - } - } - try { return AuthCredentials.createApplicationDefaults(); } catch (Exception ex) { - // fallback to old-style - } - - // Consider old-style Compute. This will not be needed once issue #21 is fixed. - try { - return AuthCredentials.createForComputeEngine(); - } catch (Exception ignore) { - // Maybe not on GCE + return AuthCredentials.noCredentials(); } - return AuthCredentials.noCredentials(); } protected static String appEngineAppId() { From b47bb25ab0b3dd4cb0cbf328fb8f530bfe8f20d6 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Sat, 7 Nov 2015 23:50:45 +0100 Subject: [PATCH 056/663] Add loop for empty pages in PageImpl.iterateAll --- .../main/java/com/google/gcloud/PageImpl.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java index 5f70b22ec5..5e83b53b33 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java @@ -50,18 +50,14 @@ static class PageIterator extends AbstractIterator { @Override protected T computeNext() { - if (currentPageIterator.hasNext()) { - return currentPageIterator.next(); - } - Page nextPage = currentPage.nextPage(); - if (nextPage != null) { - currentPage = nextPage; - currentPageIterator = currentPage.values().iterator(); - if (currentPageIterator.hasNext()) { - return currentPageIterator.next(); + while (!currentPageIterator.hasNext()) { + currentPage = currentPage.nextPage(); + if (currentPage == null) { + return endOfData(); } + currentPageIterator = currentPage.values().iterator(); } - return endOfData(); + return currentPageIterator.next(); } } From 58a7979e9f8bf8feb97c00f483c80f72fda78959 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 9 Nov 2015 08:19:46 -0800 Subject: [PATCH 057/663] Modify project id lookup order and revert style changes --- .../com/google/gcloud/ServiceOptions.java | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 876317162a..298a1223ac 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -364,19 +364,6 @@ protected String defaultProject() { } protected static String googleCloudProjectId() { - try { - URL url = new URL("http://metadata/computeMetadata/v1/project/project-id"); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestProperty("X-Google-Metadata-Request", "True"); - InputStream input = connection.getInputStream(); - if (connection.getResponseCode() == 200) { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, UTF_8))) { - return reader.readLine(); - } - } - } catch (IOException ignore) { - // ignore - } File configDir; if (System.getenv().containsKey("CLOUDSDK_CONFIG")) { configDir = new File(System.getenv("CLOUDSDK_CONFIG")); @@ -385,38 +372,52 @@ protected static String googleCloudProjectId() { } else { configDir = new File(System.getProperty("user.home"), ".config/gcloud"); } - FileReader fileReader; + FileReader fileReader = null; try { fileReader = new FileReader(new File(configDir, "configurations/config_default")); } catch (FileNotFoundException newConfigFileNotFoundEx) { try { fileReader = new FileReader(new File(configDir, "properties")); } catch (FileNotFoundException oldConfigFileNotFoundEx) { - // return null if we can't find config file - return null; + // ignore } } - try (BufferedReader reader = new BufferedReader(fileReader)) { - String line; - String section = null; - Pattern projectPattern = Pattern.compile("^project\\s*=\\s*(.*)$"); - Pattern sectionPattern = Pattern.compile("^\\[(.*)\\]$"); - while ((line = reader.readLine()) != null) { - if (line.isEmpty() || line.startsWith(";")) { - continue; - } - line = line.trim(); - Matcher matcher = sectionPattern.matcher(line); - if (matcher.matches()) { - section = matcher.group(1); - } else if (section == null || section.equals("core")) { - matcher = projectPattern.matcher(line); + if (fileReader != null) { + try (BufferedReader reader = new BufferedReader(fileReader)) { + String line; + String section = null; + Pattern projectPattern = Pattern.compile("^project\\s*=\\s*(.*)$"); + Pattern sectionPattern = Pattern.compile("^\\[(.*)\\]$"); + while ((line = reader.readLine()) != null) { + if (line.isEmpty() || line.startsWith(";")) { + continue; + } + line = line.trim(); + Matcher matcher = sectionPattern.matcher(line); if (matcher.matches()) { - return matcher.group(1); + section = matcher.group(1); + } else if (section == null || section.equals("core")) { + matcher = projectPattern.matcher(line); + if (matcher.matches()) { + return matcher.group(1); + } } } + } catch (IOException ex) { + // ignore } - } catch (IOException ex) { + } + try { + URL url = new URL("http://metadata/computeMetadata/v1/project/project-id"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestProperty("X-Google-Metadata-Request", "True"); + InputStream input = connection.getInputStream(); + if (connection.getResponseCode() == 200) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, UTF_8))) { + return reader.readLine(); + } + } + } catch (IOException ignore) { // ignore } // return null if can't determine From eac8222a7943945f01501eecd055bfabc8a582b6 Mon Sep 17 00:00:00 2001 From: aozarov Date: Tue, 10 Nov 2015 09:09:24 -0800 Subject: [PATCH 058/663] scope appliation default credentials --- .../src/main/java/com/google/gcloud/AuthCredentials.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 73c66279ea..800fcf3406 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -252,7 +252,7 @@ public boolean equals(Object obj) { @Override protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, Set scopes) { - return new HttpCredentialsAdapter(googleCredentials); + return new HttpCredentialsAdapter(googleCredentials.createScoped(scopes)); } @Override From 9a14f642b0f94db51d6bf65bb771e760d9880694 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 10 Nov 2015 09:45:33 -0800 Subject: [PATCH 059/663] Revert 2de9135149e57cec18b070028452db1efef03125 --- google-cloud-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f12267db49..e849594226 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -20,12 +20,12 @@ com.google.auth google-auth-library-credentials - 0.3.0 + 0.1.0 com.google.auth google-auth-library-oauth2-http - 0.3.0 + 0.1.0 com.google.http-client From 43582c235776cb13f939be9ff1f45b20a779090a Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 10 Nov 2015 12:59:34 -0800 Subject: [PATCH 060/663] Allow services to avoid setting project ID --- .../java/com/google/gcloud/ServiceOptions.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 8988978332..d91b3c35c8 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -306,7 +306,10 @@ public B readTimeout(int readTimeout) { protected ServiceOptions(Class> serviceFactoryClass, Class> rpcFactoryClass, Builder builder) { - projectId = checkNotNull(builder.projectId != null ? builder.projectId : defaultProject()); + projectId = builder.projectId != null ? builder.projectId : defaultProject(); + if (projectIdRequired()) { + checkNotNull(projectId); + } host = firstNonNull(builder.host, defaultHost()); httpTransportFactory = firstNonNull(builder.httpTransportFactory, getFromServiceLoader(HttpTransportFactory.class, DefaultHttpTransportFactory.INSTANCE)); @@ -325,6 +328,16 @@ protected ServiceOptions(Class> ser clock = firstNonNull(builder.clock, Clock.defaultClock()); } + /** + * Returns whether a service requires a project ID. This method may be overridden in + * service-specific Options objects. + * + * @return true if a project ID is required to use the service, false if not. + */ + public boolean projectIdRequired() { + return true; + } + private static AuthCredentials defaultAuthCredentials() { // Consider App Engine. This will not be needed once issue #21 is fixed. if (appEngineAppId() != null) { @@ -462,6 +475,8 @@ public ServiceRpcT rpc() { /** * Returns the project id. + * + * Return value can be null (for services that don't require a project id). */ public String projectId() { return projectId; From c1f836070545824560a1dc6045f53429d1156489 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 10 Nov 2015 13:18:01 -0800 Subject: [PATCH 061/663] Update version to 0.0.11 in preparation for 0.0.11 release --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e849594226..0dd04b1e83 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.0.11-SNAPSHOT + 0.0.11 gcloud-java-core From a535aaf268f958cc5ee5dbabad9275473197889b Mon Sep 17 00:00:00 2001 From: travis-ci Date: Tue, 10 Nov 2015 22:15:04 +0000 Subject: [PATCH 062/663] Updating version in README files. --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 032127540d..f84fb33993 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -17,16 +17,16 @@ If you are using Maven, add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.0.10 + 0.0.11 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:jar:0.0.10' +compile 'com.google.gcloud:gcloud-java-core:jar:0.0.11' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.10" +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.11" ``` Java Versions From 6c7ea9d6dd6b04c382ee637aebf378622aa2a5db Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 10 Nov 2015 14:35:11 -0800 Subject: [PATCH 063/663] Update version to 0.0.12-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 0dd04b1e83..e13933bd2b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.0.11 + 0.0.12-SNAPSHOT gcloud-java-core From 6bb68d154fd29166d5c25307d3637772244a25d5 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 10 Nov 2015 15:02:44 -0800 Subject: [PATCH 064/663] Make projectIdRequired() method protected. Also supply nice error message if project could not be determined and is required --- .../src/main/java/com/google/gcloud/ServiceOptions.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index d91b3c35c8..0793470ade 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -17,7 +17,7 @@ package com.google.gcloud; import static com.google.common.base.MoreObjects.firstNonNull; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkArgument; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.api.client.extensions.appengine.http.UrlFetchTransport; @@ -308,7 +308,10 @@ protected ServiceOptions(Class> ser Builder builder) { projectId = builder.projectId != null ? builder.projectId : defaultProject(); if (projectIdRequired()) { - checkNotNull(projectId); + checkArgument( + projectId != null, + "A project ID is required for this service but could not be determined from the builder or " + + "the environment. Please set a project ID using the builder."); } host = firstNonNull(builder.host, defaultHost()); httpTransportFactory = firstNonNull(builder.httpTransportFactory, @@ -334,7 +337,7 @@ protected ServiceOptions(Class> ser * * @return true if a project ID is required to use the service, false if not. */ - public boolean projectIdRequired() { + protected boolean projectIdRequired() { return true; } From 25499ae0e28fc8ec4ec0e16c167bbe81a7de7eeb Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 11 Nov 2015 21:50:51 +0100 Subject: [PATCH 065/663] Make RetryParams conform with our code style --- .../java/com/google/gcloud/RetryHelper.java | 14 ++++---- .../java/com/google/gcloud/RetryParams.java | 30 ++++++++-------- .../com/google/gcloud/RetryHelperTest.java | 2 +- .../com/google/gcloud/RetryParamsTest.java | 34 +++++++++---------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java index 7b47209cd3..90f403758e 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java @@ -194,9 +194,9 @@ private V doRetry() throws RetryHelperException { } exception = e; } - if (attemptNumber >= params.getRetryMaxAttempts() - || attemptNumber >= params.getRetryMinAttempts() - && stopwatch.elapsed(MILLISECONDS) >= params.getTotalRetryPeriodMillis()) { + if (attemptNumber >= params.retryMaxAttempts() + || attemptNumber >= params.retryMinAttempts() + && stopwatch.elapsed(MILLISECONDS) >= params.totalRetryPeriodMillis()) { throw new RetriesExhaustedException(this + ": Too many failures, giving up", exception); } long sleepDurationMillis = getSleepDuration(params, attemptNumber); @@ -215,9 +215,9 @@ private V doRetry() throws RetryHelperException { @VisibleForTesting static long getSleepDuration(RetryParams retryParams, int attemptsSoFar) { - long initialDelay = retryParams.getInitialRetryDelayMillis(); - double backoffFactor = retryParams.getRetryDelayBackoffFactor(); - long maxDelay = retryParams.getMaxRetryDelayMillis(); + long initialDelay = retryParams.initialRetryDelayMillis(); + double backoffFactor = retryParams.retryDelayBackoffFactor(); + long maxDelay = retryParams.maxRetryDelayMillis(); long retryDelay = getExponentialValue(initialDelay, backoffFactor, maxDelay, attemptsSoFar); return (long) ((random() / 2.0 + .75) * retryDelay); } @@ -228,7 +228,7 @@ private static long getExponentialValue(long initialDelay, double backoffFactor, } public static V runWithRetries(Callable callable) throws RetryHelperException { - return runWithRetries(callable, RetryParams.getDefaultInstance(), + return runWithRetries(callable, RetryParams.defaultInstance(), ExceptionHandler.getDefaultInstance()); } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java b/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java index 461dbac77f..ab3644c6d7 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java @@ -38,8 +38,8 @@ * {@code RetryParams}, first create a {@link RetryParams.Builder}. The builder is mutable and each * of the parameters can be set (any unset parameters will fallback to the defaults). The * {@code Builder} can be then used to create an immutable {@code RetryParams} object. For default - * {@code RetryParams} use {@link #getDefaultInstance}. Default settings are subject to change - * release to release. If you require specific settings, explicitly create an instance of + * {@code RetryParams} use {@link #defaultInstance}. Default settings are subject to change release + * to release. If you require specific settings, explicitly create an instance of * {@code RetryParams} with all the required settings. * * @see RetryHelper @@ -91,12 +91,12 @@ private Builder() { retryDelayBackoffFactor = DEFAULT_RETRY_DELAY_BACKOFF_FACTOR; totalRetryPeriodMillis = DEFAULT_TOTAL_RETRY_PERIOD_MILLIS; } else { - retryMinAttempts = retryParams.getRetryMinAttempts(); - retryMaxAttempts = retryParams.getRetryMaxAttempts(); - initialRetryDelayMillis = retryParams.getInitialRetryDelayMillis(); - maxRetryDelayMillis = retryParams.getMaxRetryDelayMillis(); - retryDelayBackoffFactor = retryParams.getRetryDelayBackoffFactor(); - totalRetryPeriodMillis = retryParams.getTotalRetryPeriodMillis(); + retryMinAttempts = retryParams.retryMinAttempts(); + retryMaxAttempts = retryParams.retryMaxAttempts(); + initialRetryDelayMillis = retryParams.initialRetryDelayMillis(); + maxRetryDelayMillis = retryParams.maxRetryDelayMillis(); + retryDelayBackoffFactor = retryParams.retryDelayBackoffFactor(); + totalRetryPeriodMillis = retryParams.totalRetryPeriodMillis(); } } @@ -201,7 +201,7 @@ private RetryParams(Builder builder) { /** * Returns an instance with the default parameters. */ - public static RetryParams getDefaultInstance() { + public static RetryParams defaultInstance() { return DEFAULT_INSTANCE; } @@ -216,14 +216,14 @@ public static RetryParams noRetries() { /** * Returns the retryMinAttempts. Default value is {@value #DEFAULT_RETRY_MIN_ATTEMPTS}. */ - public int getRetryMinAttempts() { + public int retryMinAttempts() { return retryMinAttempts; } /** * Returns the retryMaxAttempts. Default value is {@value #DEFAULT_RETRY_MAX_ATTEMPTS}. */ - public int getRetryMaxAttempts() { + public int retryMaxAttempts() { return retryMaxAttempts; } @@ -231,14 +231,14 @@ public int getRetryMaxAttempts() { * Returns the initialRetryDelayMillis. Default value is * {@value #DEFAULT_INITIAL_RETRY_DELAY_MILLIS}. */ - public long getInitialRetryDelayMillis() { + public long initialRetryDelayMillis() { return initialRetryDelayMillis; } /** * Returns the maxRetryDelayMillis. Default values is {@value #DEFAULT_MAX_RETRY_DELAY_MILLIS}. */ - public long getMaxRetryDelayMillis() { + public long maxRetryDelayMillis() { return maxRetryDelayMillis; } @@ -246,7 +246,7 @@ public long getMaxRetryDelayMillis() { * Returns the maxRetryDelayBackoffFactor. Default values is * {@value #DEFAULT_RETRY_DELAY_BACKOFF_FACTOR}. */ - public double getRetryDelayBackoffFactor() { + public double retryDelayBackoffFactor() { return retryDelayBackoffFactor; } @@ -254,7 +254,7 @@ public double getRetryDelayBackoffFactor() { * Returns the totalRetryPeriodMillis. Default value is * {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}. */ - public long getTotalRetryPeriodMillis() { + public long totalRetryPeriodMillis() { return totalRetryPeriodMillis; } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java b/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java index dfd933bcae..bf11e744db 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java @@ -118,7 +118,7 @@ public void testTriesAtLeastMinTimes() { @Override public Integer call() throws IOException { timesCalled++; assertEquals(timesCalled, RetryHelper.getContext().getAttemptNumber()); - assertEquals(10, RetryHelper.getContext().getRetryParams().getRetryMaxAttempts()); + assertEquals(10, RetryHelper.getContext().getRetryParams().retryMaxAttempts()); if (timesCalled <= timesToFail) { throw new IOException(); } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java b/google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java index d1d5e3c076..eae4469392 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java @@ -41,15 +41,15 @@ public class RetryParamsTest { @Test public void testDefaults() { - RetryParams params1 = RetryParams.getDefaultInstance(); + RetryParams params1 = RetryParams.defaultInstance(); RetryParams params2 = RetryParams.builder().build(); for (RetryParams params : Arrays.asList(params1, params2)) { - assertEquals(DEFAULT_INITIAL_RETRY_DELAY_MILLIS, params.getInitialRetryDelayMillis()); - assertEquals(DEFAULT_MAX_RETRY_DELAY_MILLIS, params.getMaxRetryDelayMillis()); - assertEquals(DEFAULT_RETRY_DELAY_BACKOFF_FACTOR, params.getRetryDelayBackoffFactor(), 0); - assertEquals(DEFAULT_RETRY_MAX_ATTEMPTS, params.getRetryMaxAttempts()); - assertEquals(DEFAULT_RETRY_MIN_ATTEMPTS, params.getRetryMinAttempts()); - assertEquals(DEFAULT_TOTAL_RETRY_PERIOD_MILLIS, params.getTotalRetryPeriodMillis()); + assertEquals(DEFAULT_INITIAL_RETRY_DELAY_MILLIS, params.initialRetryDelayMillis()); + assertEquals(DEFAULT_MAX_RETRY_DELAY_MILLIS, params.maxRetryDelayMillis()); + assertEquals(DEFAULT_RETRY_DELAY_BACKOFF_FACTOR, params.retryDelayBackoffFactor(), 0); + assertEquals(DEFAULT_RETRY_MAX_ATTEMPTS, params.retryMaxAttempts()); + assertEquals(DEFAULT_RETRY_MIN_ATTEMPTS, params.retryMinAttempts()); + assertEquals(DEFAULT_TOTAL_RETRY_PERIOD_MILLIS, params.totalRetryPeriodMillis()); } } @@ -65,12 +65,12 @@ public void testSetAndCopy() { RetryParams params1 = builder.build(); RetryParams params2 = new RetryParams.Builder(params1).build(); for (RetryParams params : Arrays.asList(params1, params2)) { - assertEquals(101, params.getInitialRetryDelayMillis()); - assertEquals(102, params.getMaxRetryDelayMillis()); - assertEquals(103, params.getRetryDelayBackoffFactor(), 0); - assertEquals(107, params.getRetryMinAttempts()); - assertEquals(108, params.getRetryMaxAttempts()); - assertEquals(109, params.getTotalRetryPeriodMillis()); + assertEquals(101, params.initialRetryDelayMillis()); + assertEquals(102, params.maxRetryDelayMillis()); + assertEquals(103, params.retryDelayBackoffFactor(), 0); + assertEquals(107, params.retryMinAttempts()); + assertEquals(108, params.retryMaxAttempts()); + assertEquals(109, params.totalRetryPeriodMillis()); } } @@ -79,19 +79,19 @@ public void testBadSettings() { RetryParams.Builder builder = RetryParams.builder(); builder.initialRetryDelayMillis(-1); builder = assertFailure(builder); - builder.maxRetryDelayMillis(RetryParams.getDefaultInstance().getInitialRetryDelayMillis() - 1); + builder.maxRetryDelayMillis(RetryParams.defaultInstance().initialRetryDelayMillis() - 1); builder = assertFailure(builder); builder.retryDelayBackoffFactor(-1); builder = assertFailure(builder); builder.retryMinAttempts(-1); builder = assertFailure(builder); - builder.retryMaxAttempts(RetryParams.getDefaultInstance().getRetryMinAttempts() - 1); + builder.retryMaxAttempts(RetryParams.defaultInstance().retryMinAttempts() - 1); builder = assertFailure(builder); builder.totalRetryPeriodMillis(-1); builder = assertFailure(builder); // verify that it is OK for min and max to be equal - builder.retryMaxAttempts(RetryParams.getDefaultInstance().getRetryMinAttempts()); - builder.maxRetryDelayMillis(RetryParams.getDefaultInstance().getInitialRetryDelayMillis()); + builder.retryMaxAttempts(RetryParams.defaultInstance().retryMinAttempts()); + builder.maxRetryDelayMillis(RetryParams.defaultInstance().initialRetryDelayMillis()); builder.build(); } From 70c9bbd830fa8aaf28ca2025c6feea89d9d29e09 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 11 Nov 2015 21:55:39 +0100 Subject: [PATCH 066/663] Make ExceptionHandler conform with our code style --- .../src/main/java/com/google/gcloud/ExceptionHandler.java | 6 +++--- .../src/main/java/com/google/gcloud/RetryHelper.java | 2 +- .../test/java/com/google/gcloud/ExceptionHandlerTest.java | 2 +- .../src/test/java/com/google/gcloud/RetryHelperTest.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java index a0fab3dca5..c1f0685944 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java @@ -231,11 +231,11 @@ void verifyCaller(Callable callable) { } } - public Set> getRetriableExceptions() { + public Set> retriableExceptions() { return retriableExceptions; } - public Set> getNonRetriableExceptions() { + public Set> nonRetriableExceptions() { return nonRetriableExceptions; } @@ -262,7 +262,7 @@ boolean shouldRetry(Exception ex) { /** * Returns an instance which retry any checked exception and abort on any runtime exception. */ - public static ExceptionHandler getDefaultInstance() { + public static ExceptionHandler defaultInstance() { return DEFAULT_INSTANCE; } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java index 90f403758e..9b9c1f6a31 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java @@ -229,7 +229,7 @@ private static long getExponentialValue(long initialDelay, double backoffFactor, public static V runWithRetries(Callable callable) throws RetryHelperException { return runWithRetries(callable, RetryParams.defaultInstance(), - ExceptionHandler.getDefaultInstance()); + ExceptionHandler.defaultInstance()); } public static V runWithRetries(Callable callable, RetryParams params, diff --git a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java index c182515dbb..cedc995ddb 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java @@ -82,7 +82,7 @@ public Object call() throws Error { } // using default exception handler (retry upon any non-runtime exceptions) - ExceptionHandler handler = ExceptionHandler.getDefaultInstance(); + ExceptionHandler handler = ExceptionHandler.defaultInstance(); assertValidCallable(new A(), handler); assertValidCallable(new B(), handler); assertValidCallable(new C(), handler); diff --git a/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java b/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java index bf11e744db..9a7cc2104f 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java @@ -124,7 +124,7 @@ public void testTriesAtLeastMinTimes() { } return timesCalled; } - }, params, ExceptionHandler.getDefaultInstance()); + }, params, ExceptionHandler.defaultInstance()); assertEquals(timesToFail + 1, attempted); assertNull(RetryHelper.getContext()); } From ebd88cc2a710c73afa1f698873cb73093abdf32a Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 12 Nov 2015 15:17:53 -0800 Subject: [PATCH 067/663] Create version 0.0.12 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e13933bd2b..c893471300 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.0.12-SNAPSHOT + 0.0.12 gcloud-java-core From 040a174efed35513046d32c5143104a616e8caf1 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Thu, 12 Nov 2015 23:43:27 +0000 Subject: [PATCH 068/663] Updating version in README files. --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f84fb33993..714c43f5c6 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -17,16 +17,16 @@ If you are using Maven, add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.0.11 + 0.0.12 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:jar:0.0.11' +compile 'com.google.gcloud:gcloud-java-core:jar:0.0.12' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.11" +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.12" ``` Java Versions From bd36e8fb5fa84254b0f547f8ddc3d2a9c8b3b5cf Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 12 Nov 2015 16:10:30 -0800 Subject: [PATCH 069/663] Update version to 0.0.13-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c893471300..7e184db2db 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.0.12 + 0.0.13-SNAPSHOT gcloud-java-core From 35069d63118e1cd84a6e874b87015238d6bc72dc Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 13 Nov 2015 11:33:43 -0800 Subject: [PATCH 070/663] Fix code to get app engine ID --- .../src/main/java/com/google/gcloud/ServiceOptions.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 0793470ade..c76b62780a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -450,9 +450,11 @@ protected static String getAppEngineProjectId() { try { Class factoryClass = Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory"); + Class serviceClass = + Class.forName("com.google.appengine.api.appidentity.AppIdentityService"); Method method = factoryClass.getMethod("getAppIdentityService"); Object appIdentityService = method.invoke(null); - method = appIdentityService.getClass().getMethod("getServiceAccountName"); + method = serviceClass.getMethod("getServiceAccountName"); String serviceAccountName = (String) method.invoke(appIdentityService); int indexOfAtSign = serviceAccountName.indexOf('@'); return serviceAccountName.substring(0, indexOfAtSign); From c7f008fea5b2d29b54f4d3098885146cb5a810d9 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 17 Nov 2015 17:15:27 +0100 Subject: [PATCH 071/663] Add support for signUrl when default credentials are used - Add a method to convert ApplicationDefaultCredentials to ServiceAccountAuthCredentials - Add type check and conversion to Storage.signUrl --- .../main/java/com/google/gcloud/AuthCredentials.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 800fcf3406..afd785981a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -28,6 +28,7 @@ import com.google.api.client.json.jackson.JacksonFactory; import com.google.auth.http.HttpCredentialsAdapter; import com.google.auth.oauth2.GoogleCredentials; +import com.google.auth.oauth2.ServiceAccountCredentials; import java.io.IOException; import java.io.InputStream; @@ -212,7 +213,7 @@ public RestorableState capture() { } } - private static class ApplicationDefaultAuthCredentials extends AuthCredentials { + public static class ApplicationDefaultAuthCredentials extends AuthCredentials { private GoogleCredentials googleCredentials; @@ -255,6 +256,15 @@ protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, return new HttpCredentialsAdapter(googleCredentials.createScoped(scopes)); } + public ServiceAccountAuthCredentials toServiceAccountCredentials() { + if (googleCredentials instanceof ServiceAccountCredentials) { + ServiceAccountCredentials credentials = (ServiceAccountCredentials) googleCredentials; + return new ServiceAccountAuthCredentials(credentials.getClientEmail(), + credentials.getPrivateKey()); + } + return null; + } + @Override public RestorableState capture() { return STATE; From 8977535ae1cdf96357fef01216af888428964062 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 18 Nov 2015 15:28:48 -0800 Subject: [PATCH 072/663] Use version auth library verison 0.3.1 to avoid NPE --- google-cloud-core/pom.xml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e849594226..ea10f51458 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -20,12 +20,29 @@ com.google.auth google-auth-library-credentials - 0.1.0 + 0.3.1 com.google.auth google-auth-library-oauth2-http - 0.1.0 + 0.3.1 + + + com.google.guava + guava-jdk5 + + + + + com.google.auth + google-auth-library-appengine + 0.3.1 + + + com.google.guava + guava-jdk5 + + com.google.http-client From 0a33589a6de1e987937e73bf3b5e1fd3062cf67b Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 20 Nov 2015 11:18:18 -0800 Subject: [PATCH 073/663] Add links to gcloud-common docs in READMEs --- google-cloud-core/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 714c43f5c6..4d6760d625 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -29,6 +29,11 @@ If you are using SBT, add this to your dependencies libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.12" ``` +Troubleshooting +--------------- + +To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/troubleshooting). + Java Versions ------------- @@ -39,7 +44,9 @@ Contributing Contributions to this library are always welcome and highly encouraged. -See [CONTRIBUTING] for more information on how to get started. +See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/contributing) for more information on how to get started. + +Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information. Versioning ---------- @@ -57,5 +64,6 @@ Apache 2.0 - See [LICENSE] for more information. [CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md +[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md [LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE [cloud-platform]: https://cloud.google.com/ From 2226efc84b1c52280ec7b7ffb38425caec174eca Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 20 Nov 2015 17:07:29 -0800 Subject: [PATCH 074/663] use anchors in links --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 4d6760d625..96b7a4e820 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -32,7 +32,7 @@ libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.12" Troubleshooting --------------- -To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/troubleshooting). +To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting). Java Versions ------------- @@ -44,7 +44,7 @@ Contributing Contributions to this library are always welcome and highly encouraged. -See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/contributing) for more information on how to get started. +See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information. @@ -64,6 +64,6 @@ Apache 2.0 - See [LICENSE] for more information. [CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md -[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md +[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct [LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE [cloud-platform]: https://cloud.google.com/ From 819e43121f2d221cc7d26f2ccbdc308994c5c207 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 23 Nov 2015 13:09:42 -0800 Subject: [PATCH 075/663] Add back AppEngineCredentials --- google-cloud-core/pom.xml | 11 ----- .../com/google/gcloud/AuthCredentials.java | 46 ++++++++++++++++++- .../com/google/gcloud/ServiceOptions.java | 9 ++++ 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e2ac0ddd81..c0248004d3 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -33,17 +33,6 @@ - - com.google.auth - google-auth-library-appengine - 0.3.1 - - - com.google.guava - guava-jdk5 - - - com.google.http-client google-http-client diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 09cdcc16f7..3303e4f8a6 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; +import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential; import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.json.jackson.JacksonFactory; @@ -38,6 +39,45 @@ */ public abstract class AuthCredentials implements Restorable { + private static class AppEngineAuthCredentials extends AuthCredentials { + + private static final AuthCredentials INSTANCE = new AppEngineAuthCredentials(); + private static final AppEngineAuthCredentialsState STATE = + new AppEngineAuthCredentialsState(); + + private static class AppEngineAuthCredentialsState + implements RestorableState, Serializable { + + private static final long serialVersionUID = 3558563960848658928L; + + @Override + public AuthCredentials restore() { + return INSTANCE; + } + + @Override + public int hashCode() { + return getClass().getName().hashCode(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof AppEngineAuthCredentialsState; + } + } + + @Override + protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, + Set scopes) { + return new AppIdentityCredential(scopes); + } + + @Override + public RestorableState capture() { + return STATE; + } + } + public static class ServiceAccountAuthCredentials extends AuthCredentials { private final String account; @@ -181,12 +221,16 @@ public RestorableState capture() { protected abstract HttpRequestInitializer httpRequestInitializer(HttpTransport transport, Set scopes); + public static AuthCredentials createForAppEngine() { + return AppEngineAuthCredentials.INSTANCE; + } + /** * Returns the Application Default Credentials. * *

Returns the Application Default Credentials which are credentials that identify and * authorize the whole application. This is the built-in service account if running on - * Google App/Compute Engine or the credentials file can be read from the path in the environment + * Google Compute Engine or the credentials file can be read from the path in the environment * variable GOOGLE_APPLICATION_CREDENTIALS. *

* diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index e5dba231d3..a5601e35a6 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -356,6 +356,15 @@ protected boolean projectIdRequired() { } private static AuthCredentials defaultAuthCredentials() { + // Consider App Engine. + if (appEngineAppId() != null) { + try { + return AuthCredentials.createForAppEngine(); + } catch (Exception ignore) { + // Maybe not on App Engine + } + } + try { return AuthCredentials.createApplicationDefaults(); } catch (Exception ex) { From 5a0cb7f3a25a8702e796b7093edd79c66a67c43d Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 24 Nov 2015 13:20:16 -0800 Subject: [PATCH 076/663] Use NetHttpTransport when running on Compute --- .../com/google/gcloud/ServiceOptions.java | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index a5601e35a6..25fda29c36 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -21,13 +21,10 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.api.client.extensions.appengine.http.UrlFetchTransport; -import com.google.api.client.googleapis.compute.ComputeCredential; -import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; -import com.google.api.client.json.jackson.JacksonFactory; import com.google.common.collect.Iterables; import com.google.gcloud.spi.ServiceRpcFactory; @@ -44,7 +41,6 @@ import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; -import java.security.GeneralSecurityException; import java.util.Enumeration; import java.util.Locale; import java.util.Objects; @@ -113,24 +109,8 @@ public HttpTransport create() { // Maybe not on App Engine } } - // Consider Compute - try { - return getComputeHttpTransport(); - } catch (Exception e) { - // Maybe not on GCE - } return new NetHttpTransport(); } - - private static HttpTransport getComputeHttpTransport() - throws IOException, GeneralSecurityException { - NetHttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); - // Try to connect using Google Compute Engine service account credentials. - ComputeCredential credential = new ComputeCredential(transport, new JacksonFactory()); - // Force token refresh to detect if we are running on Google Compute Engine. - credential.refreshToken(); - return transport; - } } /** From fafd44efa66719f0dac6141f629c351a077095d8 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 30 Nov 2015 20:29:57 -0800 Subject: [PATCH 077/663] Remove dependency on http initializer in AuthCredentials and remove dependency on com.google.api.client.googleapis.auth.oauth2.GoogleCredential --- .../com/google/gcloud/AuthCredentials.java | 114 +++++++++++++----- .../com/google/gcloud/ServiceOptions.java | 4 +- 2 files changed, 85 insertions(+), 33 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 3303e4f8a6..779a60fb8a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -18,21 +18,17 @@ import static com.google.common.base.Preconditions.checkNotNull; -import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; -import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential; -import com.google.api.client.http.HttpRequestInitializer; -import com.google.api.client.http.HttpTransport; -import com.google.api.client.json.jackson.JacksonFactory; -import com.google.auth.http.HttpCredentialsAdapter; +import com.google.auth.oauth2.AccessToken; import com.google.auth.oauth2.GoogleCredentials; import com.google.auth.oauth2.ServiceAccountCredentials; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; +import java.lang.reflect.Method; import java.security.PrivateKey; +import java.util.Collection; import java.util.Objects; -import java.util.Set; /** * Credentials for accessing Google Cloud services. @@ -42,8 +38,66 @@ public abstract class AuthCredentials implements Restorable { private static class AppEngineAuthCredentials extends AuthCredentials { private static final AuthCredentials INSTANCE = new AppEngineAuthCredentials(); - private static final AppEngineAuthCredentialsState STATE = - new AppEngineAuthCredentialsState(); + private static final AppEngineAuthCredentialsState STATE = new AppEngineAuthCredentialsState(); + + private static class AppEngineCredentials extends GoogleCredentials { + + private final Object appIdentityService; + private final Collection scopes; + private final boolean scopesRequired; + + AppEngineCredentials() { + try { + Class factoryClass = + Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory"); + Method method = factoryClass.getMethod("getAppIdentityService"); + this.appIdentityService = method.invoke(null); + this.scopes = null; + this.scopesRequired = true; + } catch (Exception e) { + throw new RuntimeException("Could not create AppEngineCredentials using reflection."); + } + } + + AppEngineCredentials(Collection scopes, Object appIdentityService) { + this.appIdentityService = appIdentityService; + this.scopes = scopes; + this.scopesRequired = (scopes == null || scopes.isEmpty()); + } + + /** + * Refresh the access token by getting it from the App Identity service + */ + @Override + public AccessToken refreshAccessToken() throws IOException { + if (createScopedRequired()) { + throw new IOException("AppEngineCredentials requires createScoped call before use."); + } + try { + Class serviceClass = + Class.forName("com.google.appengine.api.appidentity.AppIdentityService"); + Class tokenResultClass = Class.forName( + "com.google.appengine.api.appidentity.AppIdentityService$GetAccessTokenResult"); + Method getAccessTokenResult = serviceClass.getMethod("getAccessToken", Iterable.class); + Object accessTokenResult = getAccessTokenResult.invoke(appIdentityService, scopes); + Method getAccessToken = tokenResultClass.getMethod("getAccessToken"); + String accessToken = (String) getAccessToken.invoke(accessTokenResult); + return new AccessToken(accessToken, null); + } catch (Exception e) { + throw new RuntimeException("Could not get the access token using reflection."); + } + } + + @Override + public boolean createScopedRequired() { + return scopesRequired; + } + + @Override + public GoogleCredentials createScoped(Collection scopes) { + return new AppEngineCredentials(scopes, appIdentityService); + } + } private static class AppEngineAuthCredentialsState implements RestorableState, Serializable { @@ -67,9 +121,8 @@ public boolean equals(Object obj) { } @Override - protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, - Set scopes) { - return new AppIdentityCredential(scopes); + protected GoogleCredentials credentials() { + return new AppEngineCredentials(); } @Override @@ -133,17 +186,10 @@ public boolean equals(Object obj) { } @Override - protected HttpRequestInitializer httpRequestInitializer( - HttpTransport transport, Set scopes) { - GoogleCredential.Builder builder = new GoogleCredential.Builder() - .setTransport(transport) - .setJsonFactory(new JacksonFactory()); - if (privateKey != null) { - builder.setServiceAccountPrivateKey(privateKey); - builder.setServiceAccountId(account); - builder.setServiceAccountScopes(scopes); - } - return builder.build(); + protected GoogleCredentials credentials() { + return (privateKey == null) + ? new GoogleCredentials(null) + : new ServiceAccountCredentials(null, account, privateKey, null, null); } public String account() { @@ -198,9 +244,8 @@ public boolean equals(Object obj) { } @Override - protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport, - Set scopes) { - return new HttpCredentialsAdapter(googleCredentials.createScoped(scopes)); + protected GoogleCredentials credentials() { + return googleCredentials; } public ServiceAccountAuthCredentials toServiceAccountCredentials() { @@ -218,8 +263,7 @@ public RestorableState capture() { } } - protected abstract HttpRequestInitializer httpRequestInitializer(HttpTransport transport, - Set scopes); + protected abstract GoogleCredentials credentials(); public static AuthCredentials createForAppEngine() { return AppEngineAuthCredentials.INSTANCE; @@ -271,9 +315,17 @@ public static ServiceAccountAuthCredentials createFor(String account, PrivateKey */ public static ServiceAccountAuthCredentials createForJson(InputStream jsonCredentialStream) throws IOException { - GoogleCredential tempCredentials = GoogleCredential.fromStream(jsonCredentialStream); - return new ServiceAccountAuthCredentials(tempCredentials.getServiceAccountId(), - tempCredentials.getServiceAccountPrivateKey()); + GoogleCredentials tempCredentials = GoogleCredentials.fromStream(jsonCredentialStream); + if (tempCredentials instanceof ServiceAccountCredentials) { + ServiceAccountCredentials tempServiceAccountCredentials = + (ServiceAccountCredentials) tempCredentials; + return new ServiceAccountAuthCredentials( + tempServiceAccountCredentials.getClientEmail(), + tempServiceAccountCredentials.getPrivateKey()); + } else { + throw new IOException( + "The given JSON Credentials Stream is not a service account credential."); + } } public static AuthCredentials noCredentials() { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 25fda29c36..bc0e91d0a6 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -25,6 +25,7 @@ import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.auth.http.HttpCredentialsAdapter; import com.google.common.collect.Iterables; import com.google.gcloud.spi.ServiceRpcFactory; @@ -508,9 +509,8 @@ public RetryParams retryParams() { * options. */ public HttpRequestInitializer httpRequestInitializer() { - HttpTransport httpTransport = httpTransportFactory.create(); final HttpRequestInitializer baseRequestInitializer = - authCredentials().httpRequestInitializer(httpTransport, scopes()); + new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes())); return new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { From 68808b09e84f48de6747cf4b763b655002e47fbd Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 1 Dec 2015 09:40:28 -0800 Subject: [PATCH 078/663] Use null instead of NO_CREDENTIALS --- .../com/google/gcloud/AuthCredentials.java | 18 +----------------- .../java/com/google/gcloud/ServiceOptions.java | 18 +++++++++++------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 779a60fb8a..9aaee77ea2 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -136,8 +136,6 @@ public static class ServiceAccountAuthCredentials extends AuthCredentials { private final String account; private final PrivateKey privateKey; - private static final AuthCredentials NO_CREDENTIALS = new ServiceAccountAuthCredentials(); - private static class ServiceAccountAuthCredentialsState implements RestorableState, Serializable { @@ -153,9 +151,6 @@ private ServiceAccountAuthCredentialsState(String account, PrivateKey privateKey @Override public AuthCredentials restore() { - if (account == null && privateKey == null) { - return NO_CREDENTIALS; - } return new ServiceAccountAuthCredentials(account, privateKey); } @@ -180,16 +175,9 @@ public boolean equals(Object obj) { this.privateKey = checkNotNull(privateKey); } - ServiceAccountAuthCredentials() { - account = null; - privateKey = null; - } - @Override protected GoogleCredentials credentials() { - return (privateKey == null) - ? new GoogleCredentials(null) - : new ServiceAccountCredentials(null, account, privateKey, null, null); + return new ServiceAccountCredentials(null, account, privateKey, null, null); } public String account() { @@ -327,8 +315,4 @@ public static ServiceAccountAuthCredentials createForJson(InputStream jsonCreden "The given JSON Credentials Stream is not a service account credential."); } } - - public static AuthCredentials noCredentials() { - return ServiceAccountAuthCredentials.NO_CREDENTIALS; - } } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index bc0e91d0a6..715b0b92ca 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -312,8 +312,9 @@ protected ServiceOptions(Class> ser httpTransportFactory = firstNonNull(builder.httpTransportFactory, getFromServiceLoader(HttpTransportFactory.class, DefaultHttpTransportFactory.INSTANCE)); httpTransportFactoryClassName = httpTransportFactory.getClass().getName(); - authCredentials = firstNonNull(builder.authCredentials, defaultAuthCredentials()); - authCredentialsState = authCredentials.capture(); + authCredentials = + builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials(); + authCredentialsState = authCredentials != null ? authCredentials.capture() : null; retryParams = builder.retryParams; serviceFactory = firstNonNull(builder.serviceFactory, getFromServiceLoader(serviceFactoryClass, defaultServiceFactory())); @@ -349,7 +350,7 @@ private static AuthCredentials defaultAuthCredentials() { try { return AuthCredentials.createApplicationDefaults(); } catch (Exception ex) { - return AuthCredentials.noCredentials(); + return null; } } @@ -509,12 +510,15 @@ public RetryParams retryParams() { * options. */ public HttpRequestInitializer httpRequestInitializer() { - final HttpRequestInitializer baseRequestInitializer = - new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes())); + final HttpRequestInitializer delegate = authCredentials() != null + ? new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes())) + : null; return new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { - baseRequestInitializer.initialize(httpRequest); + if (delegate != null) { + delegate.initialize(httpRequest); + } if (connectTimeout >= 0) { httpRequest.setConnectTimeout(connectTimeout); } @@ -580,7 +584,7 @@ private void readObject(ObjectInputStream input) throws IOException, ClassNotFou httpTransportFactory = newInstance(httpTransportFactoryClassName); serviceFactory = newInstance(serviceFactoryClassName); serviceRpcFactory = newInstance(serviceRpcFactoryClassName); - authCredentials = authCredentialsState.restore(); + authCredentials = authCredentialsState != null ? authCredentialsState.restore() : null; } private static T newInstance(String className) throws IOException, ClassNotFoundException { From b9109803d238f5131c8ee55a982f51dc98d04d6f Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 1 Dec 2015 14:07:31 -0800 Subject: [PATCH 079/663] Make AppEngineAuthCredentials Restorable --- .../com/google/gcloud/AuthCredentials.java | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 9aaee77ea2..7f5d7a8ab8 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -43,6 +43,8 @@ private static class AppEngineAuthCredentials extends AuthCredentials { private static class AppEngineCredentials extends GoogleCredentials { private final Object appIdentityService; + private final Method getAccessToken; + private final Method getAccessTokenResult; private final Collection scopes; private final boolean scopesRequired; @@ -52,6 +54,12 @@ private static class AppEngineCredentials extends GoogleCredentials { Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory"); Method method = factoryClass.getMethod("getAppIdentityService"); this.appIdentityService = method.invoke(null); + Class serviceClass = + Class.forName("com.google.appengine.api.appidentity.AppIdentityService"); + Class tokenResultClass = Class.forName( + "com.google.appengine.api.appidentity.AppIdentityService$GetAccessTokenResult"); + this.getAccessTokenResult = serviceClass.getMethod("getAccessToken", Iterable.class); + this.getAccessToken = tokenResultClass.getMethod("getAccessToken"); this.scopes = null; this.scopesRequired = true; } catch (Exception e) { @@ -59,10 +67,13 @@ private static class AppEngineCredentials extends GoogleCredentials { } } - AppEngineCredentials(Collection scopes, Object appIdentityService) { - this.appIdentityService = appIdentityService; - this.scopes = scopes; - this.scopesRequired = (scopes == null || scopes.isEmpty()); + AppEngineCredentials(Collection scopes, Object appIdentityService, + Method getAccessToken, Method getAccessTokenResult) { + this.appIdentityService = appIdentityService; + this.getAccessToken = getAccessToken; + this.getAccessTokenResult = getAccessTokenResult; + this.scopes = scopes; + this.scopesRequired = (scopes == null || scopes.isEmpty()); } /** @@ -74,13 +85,7 @@ public AccessToken refreshAccessToken() throws IOException { throw new IOException("AppEngineCredentials requires createScoped call before use."); } try { - Class serviceClass = - Class.forName("com.google.appengine.api.appidentity.AppIdentityService"); - Class tokenResultClass = Class.forName( - "com.google.appengine.api.appidentity.AppIdentityService$GetAccessTokenResult"); - Method getAccessTokenResult = serviceClass.getMethod("getAccessToken", Iterable.class); Object accessTokenResult = getAccessTokenResult.invoke(appIdentityService, scopes); - Method getAccessToken = tokenResultClass.getMethod("getAccessToken"); String accessToken = (String) getAccessToken.invoke(accessTokenResult); return new AccessToken(accessToken, null); } catch (Exception e) { @@ -95,7 +100,8 @@ public boolean createScopedRequired() { @Override public GoogleCredentials createScoped(Collection scopes) { - return new AppEngineCredentials(scopes, appIdentityService); + return new AppEngineCredentials( + scopes, appIdentityService, getAccessToken, getAccessTokenResult); } } @@ -121,7 +127,7 @@ public boolean equals(Object obj) { } @Override - protected GoogleCredentials credentials() { + public GoogleCredentials credentials() { return new AppEngineCredentials(); } @@ -176,7 +182,7 @@ public boolean equals(Object obj) { } @Override - protected GoogleCredentials credentials() { + public GoogleCredentials credentials() { return new ServiceAccountCredentials(null, account, privateKey, null, null); } @@ -232,26 +238,17 @@ public boolean equals(Object obj) { } @Override - protected GoogleCredentials credentials() { + public GoogleCredentials credentials() { return googleCredentials; } - public ServiceAccountAuthCredentials toServiceAccountCredentials() { - if (googleCredentials instanceof ServiceAccountCredentials) { - ServiceAccountCredentials credentials = (ServiceAccountCredentials) googleCredentials; - return new ServiceAccountAuthCredentials(credentials.getClientEmail(), - credentials.getPrivateKey()); - } - return null; - } - @Override public RestorableState capture() { return STATE; } } - protected abstract GoogleCredentials credentials(); + public abstract GoogleCredentials credentials(); public static AuthCredentials createForAppEngine() { return AppEngineAuthCredentials.INSTANCE; @@ -310,9 +307,7 @@ public static ServiceAccountAuthCredentials createForJson(InputStream jsonCreden return new ServiceAccountAuthCredentials( tempServiceAccountCredentials.getClientEmail(), tempServiceAccountCredentials.getPrivateKey()); - } else { - throw new IOException( - "The given JSON Credentials Stream is not a service account credential."); } + throw new IOException("The given JSON Credentials Stream is not a service account credential."); } } From 280d4b412a01cedea11403070ff86b1d7b8718e0 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 1 Dec 2015 15:33:03 -0800 Subject: [PATCH 080/663] cleanup + cast fix --- .../com/google/gcloud/AuthCredentials.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 7f5d7a8ab8..f3a0024129 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -46,7 +46,6 @@ private static class AppEngineCredentials extends GoogleCredentials { private final Method getAccessToken; private final Method getAccessTokenResult; private final Collection scopes; - private final boolean scopesRequired; AppEngineCredentials() { try { @@ -61,19 +60,16 @@ private static class AppEngineCredentials extends GoogleCredentials { this.getAccessTokenResult = serviceClass.getMethod("getAccessToken", Iterable.class); this.getAccessToken = tokenResultClass.getMethod("getAccessToken"); this.scopes = null; - this.scopesRequired = true; } catch (Exception e) { - throw new RuntimeException("Could not create AppEngineCredentials using reflection."); + throw new RuntimeException("Could not create AppEngineCredentials.", e); } } - AppEngineCredentials(Collection scopes, Object appIdentityService, - Method getAccessToken, Method getAccessTokenResult) { - this.appIdentityService = appIdentityService; - this.getAccessToken = getAccessToken; - this.getAccessTokenResult = getAccessTokenResult; + AppEngineCredentials(Collection scopes, AppEngineCredentials unscoped) { + this.appIdentityService = unscoped.appIdentityService; + this.getAccessToken = unscoped.getAccessToken; + this.getAccessTokenResult = unscoped.getAccessTokenResult; this.scopes = scopes; - this.scopesRequired = (scopes == null || scopes.isEmpty()); } /** @@ -89,19 +85,18 @@ public AccessToken refreshAccessToken() throws IOException { String accessToken = (String) getAccessToken.invoke(accessTokenResult); return new AccessToken(accessToken, null); } catch (Exception e) { - throw new RuntimeException("Could not get the access token using reflection."); + throw new IOException("Could not get the access token.", e); } } @Override public boolean createScopedRequired() { - return scopesRequired; + return scopes == null || scopes.isEmpty(); } @Override public GoogleCredentials createScoped(Collection scopes) { - return new AppEngineCredentials( - scopes, appIdentityService, getAccessToken, getAccessTokenResult); + return new AppEngineCredentials(scopes, this); } } @@ -308,6 +303,7 @@ public static ServiceAccountAuthCredentials createForJson(InputStream jsonCreden tempServiceAccountCredentials.getClientEmail(), tempServiceAccountCredentials.getPrivateKey()); } - throw new IOException("The given JSON Credentials Stream is not a service account credential."); + throw new IOException( + "The given JSON Credentials Stream is not for a service account credential."); } } From 1fde07068f1026a9e900c00e31fff80051f941cb Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 1 Dec 2015 16:04:32 -0800 Subject: [PATCH 081/663] more style fixes --- .../src/main/java/com/google/gcloud/AuthCredentials.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index f3a0024129..dab6b92837 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -177,7 +177,7 @@ public boolean equals(Object obj) { } @Override - public GoogleCredentials credentials() { + public ServiceAccountCredentials credentials() { return new ServiceAccountCredentials(null, account, privateKey, null, null); } From 7e3d2c641578b93700bb3bb8dcf0efcc613752ae Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 1 Dec 2015 17:07:46 -0800 Subject: [PATCH 082/663] update version to 0.1.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c0248004d3..4fcb0b2765 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.0.13-SNAPSHOT + 0.1.0 gcloud-java-core From 7f19c9074e1b428236a6f8c52bd37d0c1867863f Mon Sep 17 00:00:00 2001 From: travis-ci Date: Wed, 2 Dec 2015 01:19:11 +0000 Subject: [PATCH 083/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 96b7a4e820..3aea0f16ef 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -17,16 +17,16 @@ If you are using Maven, add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.0.12 + 0.1.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:jar:0.0.12' +compile 'com.google.gcloud:gcloud-java-core:jar:0.1.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.12" +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.0" ``` Troubleshooting From d46d98807d95641dd41a1bd752bb152c5e94283a Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 1 Dec 2015 17:25:56 -0800 Subject: [PATCH 084/663] Update version to snapshot --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4fcb0b2765..83c8dbb00e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.1.0 + 0.1.1-SNAPSHOT gcloud-java-core From 6a38b9da895bdd33bcfa7cb01b6759fb9a6bee7a Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 9 Dec 2015 17:54:19 -0800 Subject: [PATCH 085/663] fix checkstyle issues and warnings --- .../src/main/java/com/google/gcloud/PageImpl.java | 1 + .../src/main/java/com/google/gcloud/ServiceFactory.java | 1 + .../src/main/java/com/google/gcloud/ServiceOptions.java | 8 ++++++-- .../java/com/google/gcloud/spi/ServiceRpcFactory.java | 1 + .../src/test/java/com/google/gcloud/PageImplTest.java | 2 -- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java index 5e83b53b33..97c2931e0c 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java @@ -71,6 +71,7 @@ public PageImpl(NextPageFetcher pageFetcher, String cursor, Iterable resul this.results = results; } + @SuppressWarnings("unchecked") @Override public Iterable values() { return results == null ? Collections.EMPTY_LIST : results; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java index b59fc1e9a1..3828bf3026 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java @@ -22,6 +22,7 @@ * Implementation must provide a public no-arg constructor. * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. */ +@SuppressWarnings("rawtypes") public interface ServiceFactory { ServiceT create(ServiceOptionsT serviceOptions); diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 715b0b92ca..9e5d6730f5 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -53,6 +53,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +@SuppressWarnings("rawtypes") public abstract class ServiceOptions< ServiceT extends Service, ServiceRpcT, @@ -305,8 +306,8 @@ protected ServiceOptions(Class> ser if (projectIdRequired()) { checkArgument( projectId != null, - "A project ID is required for this service but could not be determined from the builder or " - + "the environment. Please set a project ID using the builder."); + "A project ID is required for this service but could not be determined from the builder " + + "or the environment. Please set a project ID using the builder."); } host = firstNonNull(builder.host, defaultHost()); httpTransportFactory = firstNonNull(builder.httpTransportFactory, @@ -453,6 +454,7 @@ protected static String getAppEngineProjectId() { } } + @SuppressWarnings("unchecked") public ServiceT service() { if (service == null) { service = serviceFactory.create((OptionsT) this); @@ -460,6 +462,7 @@ public ServiceT service() { return service; } + @SuppressWarnings("unchecked") public ServiceRpcT rpc() { if (rpc == null) { rpc = serviceRpcFactory.create((OptionsT) this); @@ -587,6 +590,7 @@ private void readObject(ObjectInputStream input) throws IOException, ClassNotFou authCredentials = authCredentialsState != null ? authCredentialsState.restore() : null; } + @SuppressWarnings("unchecked") private static T newInstance(String className) throws IOException, ClassNotFoundException { try { return (T) Class.forName(className).newInstance(); diff --git a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java index d20b690167..d19f6047e4 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java @@ -24,6 +24,7 @@ * Implementation must provide a public no-arg constructor. * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. */ +@SuppressWarnings("rawtypes") public interface ServiceRpcFactory { ServiceRpcT create(OptionsT options); diff --git a/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java b/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java index fb289186de..4389171fb4 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java @@ -22,8 +22,6 @@ import org.junit.Test; -import java.util.Collections; - public class PageImplTest { private static final ImmutableList VALUES = ImmutableList.of("1", "2"); From f2236b2f57730e948f6d5784642a6c9886a09334 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 10 Dec 2015 08:59:05 -0800 Subject: [PATCH 086/663] Add generic type to ServiceOption definition + minor fixes --- .../src/main/java/com/google/gcloud/PageImpl.java | 3 +-- .../main/java/com/google/gcloud/ServiceOptions.java | 12 +++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java index 97c2931e0c..1c7a61ec47 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java @@ -71,10 +71,9 @@ public PageImpl(NextPageFetcher pageFetcher, String cursor, Iterable resul this.results = results; } - @SuppressWarnings("unchecked") @Override public Iterable values() { - return results == null ? Collections.EMPTY_LIST : results; + return results == null ? Collections.emptyList() : results; } @Override diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 9e5d6730f5..862d3f7b53 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -53,12 +53,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -@SuppressWarnings("rawtypes") -public abstract class ServiceOptions< - ServiceT extends Service, - ServiceRpcT, - OptionsT extends ServiceOptions> - implements Serializable { +public abstract class ServiceOptions, ServiceRpcT, + OptionsT extends ServiceOptions> implements Serializable { private static final String DEFAULT_HOST = "https://www.googleapis.com"; private static final long serialVersionUID = 1203687993961393350L; @@ -154,9 +150,7 @@ private Object readResolve() throws ObjectStreamException { } } - protected abstract static class Builder< - ServiceT extends Service, - ServiceRpcT, + protected abstract static class Builder, ServiceRpcT, OptionsT extends ServiceOptions, B extends Builder> { From e8e5eb9d241e4e2f05f50bccbaef5b8c237cf888 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 28 Dec 2015 13:55:32 +0100 Subject: [PATCH 087/663] Update version to 0.1.1 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 83c8dbb00e..d86ccc7648 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.1.1-SNAPSHOT + 0.1.1 gcloud-java-core From b91b72fc7fa8943715bd1a8e7d0965974567e3eb Mon Sep 17 00:00:00 2001 From: travis-ci Date: Mon, 28 Dec 2015 13:34:33 +0000 Subject: [PATCH 088/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 3aea0f16ef..edad8ea2c2 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -17,16 +17,16 @@ If you are using Maven, add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.1.0 + 0.1.1 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:jar:0.1.0' +compile 'com.google.gcloud:gcloud-java-core:jar:0.1.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.0" +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.1" ``` Troubleshooting From cf079474b419faf8d749a6f6d0e68b6b2a4f345c Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 28 Dec 2015 16:37:48 +0100 Subject: [PATCH 089/663] Update version to 0.1.2-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d86ccc7648..ee39bcca1f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.1.1 + 0.1.2-SNAPSHOT gcloud-java-core From 5ef516b5c61eb655d635c0b7c4fc57cdf662a980 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 28 Dec 2015 17:15:24 +0100 Subject: [PATCH 090/663] Fix gradle dependency code in all gcloud-java modules --- google-cloud-core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index edad8ea2c2..89834e1c23 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -22,7 +22,7 @@ If you are using Maven, add this to your pom.xml file ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:jar:0.1.1' +compile 'com.google.gcloud:gcloud-java-core:0.1.1' ``` If you are using SBT, add this to your dependencies ```Scala From 1c0d7f71e7a04e453763720a154e71540996b9dd Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 30 Dec 2015 08:59:29 -0800 Subject: [PATCH 091/663] Document generic types --- .../main/java/com/google/gcloud/BaseService.java | 5 +++++ .../src/main/java/com/google/gcloud/Page.java | 2 ++ .../src/main/java/com/google/gcloud/PageImpl.java | 7 +++++++ .../main/java/com/google/gcloud/Restorable.java | 2 ++ .../java/com/google/gcloud/RestorableState.java | 2 ++ .../src/main/java/com/google/gcloud/Service.java | 5 +++++ .../java/com/google/gcloud/ServiceFactory.java | 5 ++++- .../java/com/google/gcloud/ServiceOptions.java | 15 +++++++++++++++ 8 files changed, 42 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java index 7600d25411..a7edc86c0d 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java @@ -16,6 +16,11 @@ package com.google.gcloud; +/** + * Base class for service objects. + * + * @param the {@code ServiceOptions} subclass corresponding to the service. + */ public abstract class BaseService> implements Service { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Page.java b/google-cloud-core/src/main/java/com/google/gcloud/Page.java index 2819b56a17..bb4d1f8b95 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Page.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Page.java @@ -40,6 +40,8 @@ * } * page = page.nextPage(); * }} + * + * @param the value type that the page holds. */ public interface Page { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java index 1c7a61ec47..9524aaa4c6 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java @@ -25,6 +25,8 @@ /** * Base implementation for Google Cloud paginated results. + * + * @param the value type that the page holds. */ public class PageImpl implements Page, Serializable { @@ -34,6 +36,11 @@ public class PageImpl implements Page, Serializable { private final Iterable results; private final NextPageFetcher pageFetcher; + /** + * Interface for fetching the next page of results from the service. + * + * @param the value type that the page holds. + */ public interface NextPageFetcher extends Serializable { Page nextPage(); } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java index 51391e33bd..fdac020331 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java @@ -33,6 +33,8 @@ * X restorableObj = state.restore(); * ... * } + * + * @param the restorable object's type. */ public interface Restorable> { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java b/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java index 0c60411cb2..18e9d8bc50 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java @@ -22,6 +22,8 @@ * * Implementations of this class must implement {@link java.io.Serializable} to ensure that the * state of a the object can be correctly serialized. + * + * @param the restored object's type. */ public interface RestorableState> { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Service.java b/google-cloud-core/src/main/java/com/google/gcloud/Service.java index 2748c55058..b54705b9f0 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Service.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Service.java @@ -16,6 +16,11 @@ package com.google.gcloud; +/** + * Interface for service objects. + * + * @param the {@code ServiceOptions} subclass corresponding to the service. + */ public interface Service> { OptionsT options(); } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java index 3828bf3026..6226fdb504 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java @@ -19,8 +19,11 @@ /** * A base interface for all service factories. * - * Implementation must provide a public no-arg constructor. + *

Implementation must provide a public no-arg constructor. * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. + * + * @param the service subclass. + * @param the {@code ServiceOptions} subclass corresponding to the service. */ @SuppressWarnings("rawtypes") public interface ServiceFactory { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 862d3f7b53..588c041eb6 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -53,6 +53,13 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +/** + * Abstract class representing service options. + * + * @param the service subclass. + * @param the spi-layer class corresponding to the service. + * @param the {@code ServiceOptions} subclass corresponding to the service. + */ public abstract class ServiceOptions, ServiceRpcT, OptionsT extends ServiceOptions> implements Serializable { @@ -150,6 +157,14 @@ private Object readResolve() throws ObjectStreamException { } } + /** + * Builder for {@code ServiceOptions}. + * + * @param the service subclass. + * @param the spi-layer class corresponding to the service. + * @param the {@code ServiceOptions} subclass corresponding to the service. + * @param the {@code ServiceOptions} builder. + */ protected abstract static class Builder, ServiceRpcT, OptionsT extends ServiceOptions, B extends Builder> { From 290b8cab35f47fd8ed1a2888f03a3f1f5e5c230c Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 6 Jan 2016 12:11:55 -0800 Subject: [PATCH 092/663] Docs and code cleanup --- .../com/google/gcloud/AuthCredentials.java | 10 +++--- .../java/com/google/gcloud/BaseService.java | 2 +- .../com/google/gcloud/ExceptionHandler.java | 4 +-- .../src/main/java/com/google/gcloud/Page.java | 2 +- .../main/java/com/google/gcloud/PageImpl.java | 4 +-- .../java/com/google/gcloud/Restorable.java | 2 +- .../com/google/gcloud/RestorableState.java | 2 +- .../main/java/com/google/gcloud/Service.java | 2 +- .../com/google/gcloud/ServiceFactory.java | 4 +-- .../com/google/gcloud/ServiceOptions.java | 32 +++++++++---------- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index dab6b92837..fc5d74d089 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -258,8 +258,8 @@ public static AuthCredentials createForAppEngine() { * variable GOOGLE_APPLICATION_CREDENTIALS. *

* - * @return the credentials instance. - * @throws IOException if the credentials cannot be created in the current environment. + * @return the credentials instance + * @throws IOException if the credentials cannot be created in the current environment */ public static AuthCredentials createApplicationDefaults() throws IOException { return new ApplicationDefaultAuthCredentials(); @@ -275,7 +275,7 @@ public static AuthCredentials createApplicationDefaults() throws IOException { * * @param account id of the Service Account * @param privateKey private key associated to the account - * @return the credentials instance. + * @return the credentials instance */ public static ServiceAccountAuthCredentials createFor(String account, PrivateKey privateKey) { return new ServiceAccountAuthCredentials(account, privateKey); @@ -290,8 +290,8 @@ public static ServiceAccountAuthCredentials createFor(String account, PrivateKey *

* * @param jsonCredentialStream stream for Service Account Credentials in JSON format - * @return the credentials instance. - * @throws IOException if the credentials cannot be created from the stream. + * @return the credentials instance + * @throws IOException if the credentials cannot be created from the stream */ public static ServiceAccountAuthCredentials createForJson(InputStream jsonCredentialStream) throws IOException { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java index a7edc86c0d..c028eaede3 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java @@ -19,7 +19,7 @@ /** * Base class for service objects. * - * @param the {@code ServiceOptions} subclass corresponding to the service. + * @param the {@code ServiceOptions} subclass corresponding to the service */ public abstract class BaseService> implements Service { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java index c1f0685944..39d4c4e75a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java @@ -64,7 +64,7 @@ enum RetryResult { * This method is called after the evaluation and could alter its result. * * @param exception the exception that is being evaluated - * @param retryResult the result of the evaluation so far. + * @param retryResult the result of the evaluation so far * @return {@link RetryResult} to indicate if the exception should be ignored ( * {@link RetryResult#RETRY}), propagated ({@link RetryResult#NO_RETRY}), or evaluation * should proceed ({@link RetryResult#CONTINUE_EVALUATION}). @@ -250,7 +250,7 @@ boolean shouldRetry(Exception ex) { Interceptor.RetryResult retryResult = retryInfo == null ? Interceptor.RetryResult.NO_RETRY : retryInfo.retry; for (Interceptor interceptor : interceptors) { - Interceptor.RetryResult interceptorRetry = + Interceptor.RetryResult interceptorRetry = checkNotNull(interceptor.afterEval(ex, retryResult)); if (interceptorRetry != Interceptor.RetryResult.CONTINUE_EVALUATION) { retryResult = interceptorRetry; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Page.java b/google-cloud-core/src/main/java/com/google/gcloud/Page.java index bb4d1f8b95..53f3a3842a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Page.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Page.java @@ -41,7 +41,7 @@ * page = page.nextPage(); * }} * - * @param the value type that the page holds. + * @param the value type that the page holds */ public interface Page { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java index 9524aaa4c6..9ebf7f0f24 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java @@ -26,7 +26,7 @@ /** * Base implementation for Google Cloud paginated results. * - * @param the value type that the page holds. + * @param the value type that the page holds */ public class PageImpl implements Page, Serializable { @@ -39,7 +39,7 @@ public class PageImpl implements Page, Serializable { /** * Interface for fetching the next page of results from the service. * - * @param the value type that the page holds. + * @param the value type that the page holds */ public interface NextPageFetcher extends Serializable { Page nextPage(); diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java index fdac020331..90633c7004 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java @@ -34,7 +34,7 @@ * ... * } * - * @param the restorable object's type. + * @param the restorable object's type */ public interface Restorable> { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java b/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java index 18e9d8bc50..d6ce736ae8 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java @@ -23,7 +23,7 @@ * Implementations of this class must implement {@link java.io.Serializable} to ensure that the * state of a the object can be correctly serialized. * - * @param the restored object's type. + * @param the restored object's type */ public interface RestorableState> { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Service.java b/google-cloud-core/src/main/java/com/google/gcloud/Service.java index b54705b9f0..60bc26670f 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Service.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Service.java @@ -19,7 +19,7 @@ /** * Interface for service objects. * - * @param the {@code ServiceOptions} subclass corresponding to the service. + * @param the {@code ServiceOptions} subclass corresponding to the service */ public interface Service> { OptionsT options(); diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java index 6226fdb504..1727e9c397 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java @@ -22,8 +22,8 @@ *

Implementation must provide a public no-arg constructor. * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. * - * @param the service subclass. - * @param the {@code ServiceOptions} subclass corresponding to the service. + * @param the service subclass + * @param the {@code ServiceOptions} subclass corresponding to the service */ @SuppressWarnings("rawtypes") public interface ServiceFactory { diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 588c041eb6..6ed1d50ba3 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -56,9 +56,9 @@ /** * Abstract class representing service options. * - * @param the service subclass. - * @param the spi-layer class corresponding to the service. - * @param the {@code ServiceOptions} subclass corresponding to the service. + * @param the service subclass + * @param the spi-layer class corresponding to the service + * @param the {@code ServiceOptions} subclass corresponding to the service */ public abstract class ServiceOptions, ServiceRpcT, OptionsT extends ServiceOptions> implements Serializable { @@ -160,10 +160,10 @@ private Object readResolve() throws ObjectStreamException { /** * Builder for {@code ServiceOptions}. * - * @param the service subclass. - * @param the spi-layer class corresponding to the service. - * @param the {@code ServiceOptions} subclass corresponding to the service. - * @param the {@code ServiceOptions} builder. + * @param the service subclass + * @param the spi-layer class corresponding to the service + * @param the {@code ServiceOptions} subclass corresponding to the service + * @param the {@code ServiceOptions} builder */ protected abstract static class Builder, ServiceRpcT, OptionsT extends ServiceOptions, @@ -215,7 +215,7 @@ public B serviceFactory(ServiceFactory serviceFactory) { * replaced by Java8's {@code java.time.Clock}. * * @param clock the clock to set - * @return the builder. + * @return the builder */ public B clock(Clock clock) { this.clock = clock; @@ -225,7 +225,7 @@ public B clock(Clock clock) { /** * Sets project id. * - * @return the builder. + * @return the builder */ public B projectId(String projectId) { this.projectId = projectId; @@ -235,7 +235,7 @@ public B projectId(String projectId) { /** * Sets service host. * - * @return the builder. + * @return the builder */ public B host(String host) { this.host = host; @@ -245,7 +245,7 @@ public B host(String host) { /** * Sets the transport factory. * - * @return the builder. + * @return the builder */ public B httpTransportFactory(HttpTransportFactory httpTransportFactory) { this.httpTransportFactory = httpTransportFactory; @@ -255,7 +255,7 @@ public B httpTransportFactory(HttpTransportFactory httpTransportFactory) { /** * Sets the service authentication credentials. * - * @return the builder. + * @return the builder */ public B authCredentials(AuthCredentials authCredentials) { this.authCredentials = authCredentials; @@ -266,7 +266,7 @@ public B authCredentials(AuthCredentials authCredentials) { * Sets configuration parameters for request retries. If no configuration is set * {@link RetryParams#noRetries()} is used. * - * @return the builder. + * @return the builder */ public B retryParams(RetryParams retryParams) { this.retryParams = retryParams; @@ -288,7 +288,7 @@ public B serviceRpcFactory(ServiceRpcFactory serviceRpcFa * * @param connectTimeout connection timeout in milliseconds. 0 for an infinite timeout, a * negative number for the default value (20000). - * @return the builder. + * @return the builder */ public B connectTimeout(int connectTimeout) { this.connectTimeout = connectTimeout; @@ -300,7 +300,7 @@ public B connectTimeout(int connectTimeout) { * * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a negative number * for the default value (20000). - * @return the builder. + * @return the builder */ public B readTimeout(int readTimeout) { this.readTimeout = readTimeout; @@ -341,7 +341,7 @@ protected ServiceOptions(Class> ser * Returns whether a service requires a project ID. This method may be overridden in * service-specific Options objects. * - * @return true if a project ID is required to use the service, false if not. + * @return true if a project ID is required to use the service, false if not */ protected boolean projectIdRequired() { return true; From d30438fbaf4596a03531c7049ccfab3f356415a1 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 7 Jan 2016 13:11:00 -0800 Subject: [PATCH 093/663] Refactor page fetchers --- .../main/java/com/google/gcloud/PageImpl.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java index 9524aaa4c6..e2623fca7c 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java @@ -17,10 +17,12 @@ package com.google.gcloud; import com.google.common.collect.AbstractIterator; +import com.google.common.collect.ImmutableMap; import java.io.Serializable; import java.util.Collections; import java.util.Iterator; +import java.util.Map; import java.util.Objects; /** @@ -85,7 +87,7 @@ public Iterable values() { @Override public Iterator iterateAll() { - return new PageIterator(this); + return new PageIterator<>(this); } @Override @@ -115,4 +117,28 @@ public boolean equals(Object obj) { return Objects.equals(cursor, other.cursor) && Objects.equals(results, other.results); } + + /** + * Utility method to construct the options map for the next page request. + * + * @param the value type that the page holds. Instances of {@code T} should be + * {@code Serializable} + * @param pageTokenOption the key for the next page cursor option in the options map + * @param cursor the cursor for the next page + * @param optionMap the previous options map + * @return the options map for the next page request + */ + public static Map nextRequestOptions( + T pageTokenOption, String cursor, Map optionMap) { + ImmutableMap.Builder builder = ImmutableMap.builder(); + if (cursor != null) { + builder.put(pageTokenOption, cursor); + } + for (Map.Entry option : optionMap.entrySet()) { + if (!Objects.equals(option.getKey(), pageTokenOption)) { + builder.put(option.getKey(), option.getValue()); + } + } + return builder.build(); + } } From acb584bbdac9fbad3911cecd9dbf10a3a771da24 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 11 Jan 2016 16:20:55 -0800 Subject: [PATCH 094/663] Set default retry strategy --- .../src/main/java/com/google/gcloud/ServiceOptions.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 6ed1d50ba3..84bb071958 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -264,7 +264,8 @@ public B authCredentials(AuthCredentials authCredentials) { /** * Sets configuration parameters for request retries. If no configuration is set - * {@link RetryParams#noRetries()} is used. + * {@link RetryParams#defaultInstance()} is used. To disable retries, supply + * {@link RetryParams#noRetries()} here. * * @return the builder */ @@ -325,7 +326,7 @@ protected ServiceOptions(Class> ser authCredentials = builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials(); authCredentialsState = authCredentials != null ? authCredentials.capture() : null; - retryParams = builder.retryParams; + retryParams = firstNonNull(builder.retryParams, RetryParams.defaultInstance()); serviceFactory = firstNonNull(builder.serviceFactory, getFromServiceLoader(serviceFactoryClass, defaultServiceFactory())); serviceFactoryClassName = serviceFactory.getClass().getName(); From 091683bf6c547afacbca8b58b8be9a661711f131 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 12 Jan 2016 15:16:57 -0800 Subject: [PATCH 095/663] ServiceOptions tests + fix for default retry params --- .../com/google/gcloud/ServiceOptions.java | 6 +- .../com/google/gcloud/ServiceOptionsTest.java | 234 ++++++++++++++++++ 2 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 84bb071958..31e5438094 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -511,11 +511,11 @@ public AuthCredentials authCredentials() { } /** - * Returns configuration parameters for request retries. By default requests are not retried: - * {@link RetryParams#noRetries()} is used. + * Returns configuration parameters for request retries. By default requests are retried: + * {@link RetryParams#defaultInstance()} is used. */ public RetryParams retryParams() { - return retryParams != null ? retryParams : RetryParams.noRetries(); + return retryParams; } /** diff --git a/google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java new file mode 100644 index 0000000000..9b118197a5 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java @@ -0,0 +1,234 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.google.gcloud.ServiceOptions.Clock; +import com.google.gcloud.ServiceOptions.DefaultHttpTransportFactory; +import com.google.gcloud.ServiceOptions.HttpTransportFactory; +import com.google.gcloud.spi.ServiceRpcFactory; + +import org.easymock.EasyMock; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Set; + +@RunWith(JUnit4.class) +public class ServiceOptionsTest { + private static final String JSON_KEY = + "{\n" + + " \"private_key_id\": \"somekeyid\",\n" + + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" + + "kAgEAAoIBAQC+K2hSuFpAdrJI\\nnCgcDz2M7t7bjdlsadsasad+fvRSW6TjNQZ3p5LLQY1kSZRqBqylRkzteMOyHg" + + "aR\\n0Pmxh3ILCND5men43j3h4eDbrhQBuxfEMalkG92sL+PNQSETY2tnvXryOvmBRwa/\\nQP/9dJfIkIDJ9Fw9N4" + + "Bhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nknddadwkwewcVxHFhcZJO+XWf6ofLUXpRwiTZakGMn8EE1uVa2" + + "LgczOjwWHGi99MFjxSer5m9\\n1tCa3/KEGKiS/YL71JvjwX3mb+cewlkcmweBKZHM2JPTk0ZednFSpVZMtycjkbLa" + + "\\ndYOS8V85AgMBewECggEBAKksaldajfDZDV6nGqbFjMiizAKJolr/M3OQw16K6o3/\\n0S31xIe3sSlgW0+UbYlF" + + "4U8KifhManD1apVSC3csafaspP4RZUHFhtBywLO9pR5c\\nr6S5aLp+gPWFyIp1pfXbWGvc5VY/v9x7ya1VEa6rXvL" + + "sKupSeWAW4tMj3eo/64ge\\nsdaceaLYw52KeBYiT6+vpsnYrEkAHO1fF/LavbLLOFJmFTMxmsNaG0tuiJHgjshB\\" + + "n82DpMCbXG9YcCgI/DbzuIjsdj2JC1cascSP//3PmefWysucBQe7Jryb6NQtASmnv\\nCdDw/0jmZTEjpe4S1lxfHp" + + "lAhHFtdgYTvyYtaLZiVVkCgYEA8eVpof2rceecw/I6\\n5ng1q3Hl2usdWV/4mZMvR0fOemacLLfocX6IYxT1zA1FF" + + "JlbXSRsJMf/Qq39mOR2\\nSpW+hr4jCoHeRVYLgsbggtrevGmILAlNoqCMpGZ6vDmJpq6ECV9olliDvpPgWOP+\\nm" + + "YPDreFBGxWvQrADNbRt2dmGsrsCgYEAyUHqB2wvJHFqdmeBsaacewzV8x9WgmeX\\ngUIi9REwXlGDW0Mz50dxpxcK" + + "CAYn65+7TCnY5O/jmL0VRxU1J2mSWyWTo1C+17L0\\n3fUqjxL1pkefwecxwecvC+gFFYdJ4CQ/MHHXU81Lwl1iWdF" + + "Cd2UoGddYaOF+KNeM\\nHC7cmqra+JsCgYEAlUNywzq8nUg7282E+uICfCB0LfwejuymR93CtsFgb7cRd6ak\\nECR" + + "8FGfCpH8ruWJINllbQfcHVCX47ndLZwqv3oVFKh6pAS/vVI4dpOepP8++7y1u\\ncoOvtreXCX6XqfrWDtKIvv0vjl" + + "HBhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nkndj5uNl5SiuVxHFhcZJO+XWf6ofLUregtevZakGMn8EE1uVa" + + "2AY7eafmoU/nZPT\\n00YB0TBATdCbn/nBSuKDESkhSg9s2GEKQZG5hBmL5uCMfo09z3SfxZIhJdlerreP\\nJ7gSi" + + "dI12N+EZxYd4xIJh/HFDgp7RRO87f+WJkofMQKBgGTnClK1VMaCRbJZPriw\\nEfeFCoOX75MxKwXs6xgrw4W//AYG" + + "GUjDt83lD6AZP6tws7gJ2IwY/qP7+lyhjEqN\\nHtfPZRGFkGZsdaksdlaksd323423d+15/UvrlRSFPNj1tWQmNKk" + + "XyRDW4IG1Oa2p\\nrALStNBx5Y9t0/LQnFI4w3aG\\n-----END PRIVATE KEY-----\\n\",\n" + + " \"client_email\": \"someclientid@developer.gserviceaccount.com\",\n" + + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" + + " \"type\": \"service_account\"\n" + + "}"; + private static final InputStream JSON_KEY_STREAM = new ByteArrayInputStream(JSON_KEY.getBytes()); + private static AuthCredentials authCredentials; + static { + try { + authCredentials = AuthCredentials.createForJson(JSON_KEY_STREAM); + } catch (IOException e) { + fail("Couldn't create fake JSON credentials."); + } + } + private static final HttpTransportFactory MOCK_HTTP_TRANSPORT_FACTORY = + EasyMock.createMock(HttpTransportFactory.class); + private static final TestServiceOptions OPTIONS = + TestServiceOptions.builder() + .authCredentials(authCredentials) + .connectTimeout(1234) + .host("host") + .httpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) + .projectId("project-id") + .readTimeout(5678) + .retryParams(RetryParams.noRetries()) + .build(); + private static final TestServiceOptions DEFAULT_OPTIONS = + TestServiceOptions.builder().projectId("project-id").build(); + private static final TestServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); + + interface TestService extends Service {} + + static class TestServiceImpl + extends BaseService implements TestService { + TestServiceImpl(TestServiceOptions options) { + super(options); + } + } + + interface TestServiceFactory extends ServiceFactory {} + + static class DefaultTestServiceFactory implements TestServiceFactory { + private static final TestServiceFactory INSTANCE = new DefaultTestServiceFactory(); + + @Override + public TestService create(TestServiceOptions options) { + return new TestServiceImpl(options); + } + } + + interface TestServiceRpcFactory + extends ServiceRpcFactory {} + + static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory { + private static final TestServiceRpcFactory INSTANCE = new DefaultTestServiceRpcFactory(); + + @Override + public TestServiceRpc create(TestServiceOptions options) { + return new DefaultTestServiceRpc(options); + } + } + + interface TestServiceRpc {} + + static class DefaultTestServiceRpc implements TestServiceRpc { + DefaultTestServiceRpc(TestServiceOptions options) {} + } + + static class TestServiceOptions extends ServiceOptions { + static class Builder + extends ServiceOptions.Builder { + private Builder() {} + + private Builder(TestServiceOptions options) { + super(options); + } + + @Override + protected TestServiceOptions build() { + return new TestServiceOptions(this); + } + } + + protected TestServiceOptions(Builder builder) { + super(TestServiceFactory.class, TestServiceRpcFactory.class, builder); + } + + public static TestServiceOptions defaultInstance() { + return builder().build(); + } + + @Override + protected TestServiceFactory defaultServiceFactory() { + return DefaultTestServiceFactory.INSTANCE; + } + + @Override + protected TestServiceRpcFactory defaultRpcFactory() { + return DefaultTestServiceRpcFactory.INSTANCE; + } + + @Override + protected Set scopes() { + return null; + } + + @Override + public Builder toBuilder() { + return new Builder(this); + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof TestServiceOptions && baseEquals((TestServiceOptions) obj); + } + + @Override + public int hashCode() { + return baseHashCode(); + } + } + + @Test + public void testBuilder() { + assertEquals(authCredentials, OPTIONS.authCredentials()); + assertEquals(Clock.defaultClock(), OPTIONS.clock()); + assertEquals(1234, OPTIONS.connectTimeout()); + assertEquals("host", OPTIONS.host()); + assertEquals(MOCK_HTTP_TRANSPORT_FACTORY, OPTIONS.httpTransportFactory()); + assertEquals("project-id", OPTIONS.projectId()); + assertEquals(5678, OPTIONS.readTimeout()); + assertEquals(RetryParams.noRetries(), OPTIONS.retryParams()); + + assertEquals(Clock.defaultClock(), DEFAULT_OPTIONS.clock()); + assertEquals(-1, DEFAULT_OPTIONS.connectTimeout()); + assertEquals("https://www.googleapis.com", DEFAULT_OPTIONS.host()); + assertTrue(DEFAULT_OPTIONS.httpTransportFactory() instanceof DefaultHttpTransportFactory); + assertEquals(-1, DEFAULT_OPTIONS.readTimeout()); + assertEquals(RetryParams.defaultInstance(), DEFAULT_OPTIONS.retryParams()); + } + + @Test + public void testGetProjectIdRequired() { + assertTrue(OPTIONS.projectIdRequired()); + } + + @Test + public void testService() { + assertTrue(OPTIONS.service() instanceof TestServiceImpl); + } + + @Test + public void testRpc() { + assertTrue(OPTIONS.rpc() instanceof DefaultTestServiceRpc); + } + + @Test + public void testBaseEquals() { + assertEquals(OPTIONS, OPTIONS_COPY); + assertNotEquals(DEFAULT_OPTIONS, OPTIONS); + } + + @Test + public void testBaseHashCode() { + assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); + assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); + } +} From 753bb4d634c866db9325bcb929940642bd6a506c Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 12 Jan 2016 15:46:53 -0800 Subject: [PATCH 096/663] Fix ServiceOptions tests --- .../com/google/gcloud/ServiceOptionsTest.java | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java index 9b118197a5..d0e3db2d2a 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -76,9 +77,11 @@ public class ServiceOptionsTest { } private static final HttpTransportFactory MOCK_HTTP_TRANSPORT_FACTORY = EasyMock.createMock(HttpTransportFactory.class); + private static final Clock TEST_CLOCK = new TestClock(); private static final TestServiceOptions OPTIONS = TestServiceOptions.builder() .authCredentials(authCredentials) + .clock(TEST_CLOCK) .connectTimeout(1234) .host("host") .httpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) @@ -90,18 +93,25 @@ public class ServiceOptionsTest { TestServiceOptions.builder().projectId("project-id").build(); private static final TestServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); - interface TestService extends Service {} + private static class TestClock extends Clock { + @Override + public long millis() { + return 123456789L; + } + } - static class TestServiceImpl + private interface TestService extends Service {} + + private static class TestServiceImpl extends BaseService implements TestService { - TestServiceImpl(TestServiceOptions options) { + private TestServiceImpl(TestServiceOptions options) { super(options); } } - interface TestServiceFactory extends ServiceFactory {} + private interface TestServiceFactory extends ServiceFactory {} - static class DefaultTestServiceFactory implements TestServiceFactory { + private static class DefaultTestServiceFactory implements TestServiceFactory { private static final TestServiceFactory INSTANCE = new DefaultTestServiceFactory(); @Override @@ -110,10 +120,10 @@ public TestService create(TestServiceOptions options) { } } - interface TestServiceRpcFactory + private interface TestServiceRpcFactory extends ServiceRpcFactory {} - static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory { + private static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory { private static final TestServiceRpcFactory INSTANCE = new DefaultTestServiceRpcFactory(); @Override @@ -122,14 +132,15 @@ public TestServiceRpc create(TestServiceOptions options) { } } - interface TestServiceRpc {} + private interface TestServiceRpc {} - static class DefaultTestServiceRpc implements TestServiceRpc { + private static class DefaultTestServiceRpc implements TestServiceRpc { DefaultTestServiceRpc(TestServiceOptions options) {} } - static class TestServiceOptions extends ServiceOptions { - static class Builder + private static class TestServiceOptions + extends ServiceOptions { + private static class Builder extends ServiceOptions.Builder { private Builder() {} @@ -143,14 +154,10 @@ protected TestServiceOptions build() { } } - protected TestServiceOptions(Builder builder) { + private TestServiceOptions(Builder builder) { super(TestServiceFactory.class, TestServiceRpcFactory.class, builder); } - public static TestServiceOptions defaultInstance() { - return builder().build(); - } - @Override protected TestServiceFactory defaultServiceFactory() { return DefaultTestServiceFactory.INSTANCE; @@ -171,7 +178,7 @@ public Builder toBuilder() { return new Builder(this); } - public static Builder builder() { + private static Builder builder() { return new Builder(); } @@ -188,21 +195,21 @@ public int hashCode() { @Test public void testBuilder() { - assertEquals(authCredentials, OPTIONS.authCredentials()); - assertEquals(Clock.defaultClock(), OPTIONS.clock()); + assertSame(authCredentials, OPTIONS.authCredentials()); + assertSame(TEST_CLOCK, OPTIONS.clock()); assertEquals(1234, OPTIONS.connectTimeout()); assertEquals("host", OPTIONS.host()); - assertEquals(MOCK_HTTP_TRANSPORT_FACTORY, OPTIONS.httpTransportFactory()); + assertSame(MOCK_HTTP_TRANSPORT_FACTORY, OPTIONS.httpTransportFactory()); assertEquals("project-id", OPTIONS.projectId()); assertEquals(5678, OPTIONS.readTimeout()); - assertEquals(RetryParams.noRetries(), OPTIONS.retryParams()); + assertSame(RetryParams.noRetries(), OPTIONS.retryParams()); - assertEquals(Clock.defaultClock(), DEFAULT_OPTIONS.clock()); + assertSame(Clock.defaultClock(), DEFAULT_OPTIONS.clock()); assertEquals(-1, DEFAULT_OPTIONS.connectTimeout()); assertEquals("https://www.googleapis.com", DEFAULT_OPTIONS.host()); assertTrue(DEFAULT_OPTIONS.httpTransportFactory() instanceof DefaultHttpTransportFactory); assertEquals(-1, DEFAULT_OPTIONS.readTimeout()); - assertEquals(RetryParams.defaultInstance(), DEFAULT_OPTIONS.retryParams()); + assertSame(RetryParams.defaultInstance(), DEFAULT_OPTIONS.retryParams()); } @Test From c6161a5ede9e287c28f6a2d23b662d35d5d95d34 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 15 Jan 2016 16:18:03 -0800 Subject: [PATCH 097/663] Release version to 0.1.2 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index ee39bcca1f..248df370e1 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.1.2-SNAPSHOT + 0.1.2 gcloud-java-core From b6d2563f3fa15974b922eaa569da26734124ad91 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Sat, 16 Jan 2016 00:37:15 +0000 Subject: [PATCH 098/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 89834e1c23..f47d99779a 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -17,16 +17,16 @@ If you are using Maven, add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.1.1 + 0.1.2 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:0.1.1' +compile 'com.google.gcloud:gcloud-java-core:0.1.2' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.1" +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.2" ``` Troubleshooting From d8490ff909037ae6c769f3fe0d049db932c8a242 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 15 Jan 2016 17:19:16 -0800 Subject: [PATCH 099/663] Update version to 0.1.3-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 248df370e1..d87e0d7eae 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.1.2 + 0.1.3-SNAPSHOT gcloud-java-core From da0ed11f5c03cfafbd3bf3d1fd17759be1d1f706 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 11 Jan 2016 16:56:52 +0100 Subject: [PATCH 100/663] Add support for BigQuery resumable uploads via a write channel - Move BlobWriteChannel and BlobReadChannel to core module - Rename BlobWriteChannel and BlobReadChannel to WriteChannel and ReadChannel - Add abstract class BaseWriteChannel implementing entity-agnostic channel functionality - Add BlobWriteChannel and BlobReadChannel implementation to gcloud-java-storage - Add LoadConfiguration and modify LoadJobInfo to take configuration as a parameter - Add BigQuery.writer method to return a writer given LoadConfiguration - Add BigQueryRpc.open and .write methods to implement write channel - Add TableDataWriteChannel class to support bigquery resumable streaming inserts - Add unit and integration tests - Update bigquery example with load-data action --- .../com/google/gcloud/BaseWriteChannel.java | 293 ++++++++++++++++++ .../java/com/google/gcloud/ReadChannel.java | 57 ++++ .../java/com/google/gcloud/WriteChannel.java | 48 +++ .../google/gcloud/BaseWriteChannelTest.java | 144 +++++++++ 4 files changed, 542 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/ReadChannel.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/WriteChannel.java create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java new file mode 100644 index 0000000000..e05383a658 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java @@ -0,0 +1,293 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import com.google.common.base.MoreObjects; + +import java.io.IOException; +import java.io.Serializable; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Objects; + +/** + * Base implementation for a {@link WriteChannel}. + * + * @param the service options used by the channel to issue RPC requests + * @param the entity this channel writes data to. Possibly with additional configuration + */ +public abstract class BaseWriteChannel< + ServiceOptionsT extends ServiceOptions, + EntityT extends Serializable> implements WriteChannel { + + private static final int MIN_CHUNK_SIZE = 256 * 1024; + private static final int DEFAULT_CHUNK_SIZE = 8 * MIN_CHUNK_SIZE; + + private final ServiceOptionsT options; + private final EntityT entity; + private final String uploadId; + private int position; + private byte[] buffer = new byte[0]; + private int limit; + private boolean isOpen = true; + private int chunkSize = defaultChunkSize(); + + protected int minChunkSize() { + return MIN_CHUNK_SIZE; + } + + protected int defaultChunkSize() { + return DEFAULT_CHUNK_SIZE; + } + + /** + * Writes {@code length} bytes of {@link #buffer()} to the {@link #uploadId()} URL. + * + * @param length the number of bytes to write from {@link #buffer()} + * @param last if {@code true} the resumable session is closed + */ + protected abstract void flushBuffer(int length, boolean last); + + protected ServiceOptionsT options() { + return options; + } + + protected EntityT entity() { + return entity; + } + + protected String uploadId() { + return uploadId; + } + + protected int position() { + return position; + } + + protected byte[] buffer() { + return buffer; + } + + protected int limit() { + return limit; + } + + protected int chunkSize() { + return chunkSize; + } + + @Override + public final void chunkSize(int chunkSize) { + chunkSize = (chunkSize / minChunkSize()) * minChunkSize(); + this.chunkSize = Math.max(minChunkSize(), chunkSize); + } + + protected BaseWriteChannel(ServiceOptionsT options, EntityT entity, String uploadId) { + this.options = options; + this.entity = entity; + this.uploadId = uploadId; + } + + private void flush() { + if (limit >= chunkSize) { + final int length = limit - limit % minChunkSize(); + flushBuffer(length, false); + position += length; + limit -= length; + byte[] temp = new byte[chunkSize]; + System.arraycopy(buffer, length, temp, 0, limit); + buffer = temp; + } + } + + private void validateOpen() throws IOException { + if (!isOpen) { + throw new IOException("stream is closed"); + } + } + + @Override + public final int write(ByteBuffer byteBuffer) throws IOException { + validateOpen(); + int toWrite = byteBuffer.remaining(); + int spaceInBuffer = buffer.length - limit; + if (spaceInBuffer >= toWrite) { + byteBuffer.get(buffer, limit, toWrite); + } else { + buffer = Arrays.copyOf(buffer, Math.max(chunkSize, buffer.length + toWrite - spaceInBuffer)); + byteBuffer.get(buffer, limit, toWrite); + } + limit += toWrite; + flush(); + return toWrite; + } + + @Override + public boolean isOpen() { + return isOpen; + } + + @Override + public final void close() throws IOException { + if (isOpen) { + flushBuffer(limit, true); + position += buffer.length; + isOpen = false; + buffer = null; + } + } + + /** + * Creates a {@link BaseState.Builder} for the current write channel. + */ + protected abstract BaseState.Builder stateBuilder(); + + @Override + public RestorableState capture() { + byte[] bufferToSave = null; + if (isOpen) { + flush(); + bufferToSave = Arrays.copyOf(buffer, limit); + } + return stateBuilder() + .position(position) + .buffer(bufferToSave) + .isOpen(isOpen) + .chunkSize(chunkSize) + .build(); + } + + /** + * Restores the state of the current write channel given a {@link BaseState} object. + */ + protected void restore(BaseState state) { + if (state.buffer != null) { + this.buffer = state.buffer.clone(); + this.limit = state.buffer.length; + } + this.position = state.position; + this.isOpen = state.isOpen; + this.chunkSize = state.chunkSize; + } + + protected abstract static class BaseState< + ServiceOptionsT extends ServiceOptions, EntityT extends Serializable> + implements RestorableState, Serializable { + + private static final long serialVersionUID = 8541062465055125619L; + + protected final ServiceOptionsT serviceOptions; + protected final EntityT entity; + protected final String uploadId; + protected final int position; + protected final byte[] buffer; + protected final boolean isOpen; + protected final int chunkSize; + + protected BaseState(Builder builder) { + this.serviceOptions = builder.serviceOptions; + this.entity = builder.entity; + this.uploadId = builder.uploadId; + this.position = builder.position; + this.buffer = builder.buffer; + this.isOpen = builder.isOpen; + this.chunkSize = builder.chunkSize; + } + + /** + * Base builder for a write channel's state. Users are not supposed to access this class + * directly. + * + * @param the service options used by the channel to issue RPC requests + * @param the entity this channel writes data to. Possibly with additional + * configuration + */ + public abstract static class Builder< + ServiceOptionsT extends ServiceOptions, + EntityT extends Serializable> { + private final ServiceOptionsT serviceOptions; + private final EntityT entity; + private final String uploadId; + private int position; + private byte[] buffer; + private boolean isOpen; + private int chunkSize; + + protected Builder(ServiceOptionsT options, EntityT entity, String uploadId) { + this.serviceOptions = options; + this.entity = entity; + this.uploadId = uploadId; + } + + public Builder position(int position) { + this.position = position; + return this; + } + + public Builder buffer(byte[] buffer) { + this.buffer = buffer; + return this; + } + + public Builder isOpen(boolean isOpen) { + this.isOpen = isOpen; + return this; + } + + public Builder chunkSize(int chunkSize) { + this.chunkSize = chunkSize; + return this; + } + + public abstract RestorableState build(); + } + + @Override + public int hashCode() { + return Objects.hash(serviceOptions, entity, uploadId, position, isOpen, chunkSize, + Arrays.hashCode(buffer)); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (!(obj instanceof BaseState)) { + return false; + } + final BaseState other = (BaseState) obj; + return Objects.equals(this.serviceOptions, other.serviceOptions) + && Objects.equals(this.entity, other.entity) + && Objects.equals(this.uploadId, other.uploadId) + && Objects.deepEquals(this.buffer, other.buffer) + && this.position == other.position + && this.isOpen == other.isOpen + && this.chunkSize == other.chunkSize; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("entity", entity) + .add("uploadId", uploadId) + .add("position", position) + .add("isOpen", isOpen) + .toString(); + } + } +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ReadChannel.java b/google-cloud-core/src/main/java/com/google/gcloud/ReadChannel.java new file mode 100644 index 0000000000..7537c5a8ce --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/ReadChannel.java @@ -0,0 +1,57 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import java.io.Closeable; +import java.io.IOException; +import java.nio.channels.ReadableByteChannel; + +/** + * A channel for reading data from a Google Cloud object. + * + *

Implementations of this class may buffer data internally to reduce remote calls. This + * interface implements {@link Restorable} to allow saving the reader's state to continue reading + * afterwards. + *

+ */ +public interface ReadChannel extends ReadableByteChannel, Closeable, Restorable { + + /** + * Overridden to remove IOException. + * + * @see java.nio.channels.Channel#close() + */ + @Override + void close(); + + void seek(int position) throws IOException; + + /** + * Sets the minimum size that will be read by a single RPC. + * Read data will be locally buffered until consumed. + */ + void chunkSize(int chunkSize); + + /** + * Captures the read channel state so that it can be saved and restored afterwards. + * + * @return a {@link RestorableState} object that contains the read channel state and can restore + * it afterwards. + */ + @Override + RestorableState capture(); +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/WriteChannel.java b/google-cloud-core/src/main/java/com/google/gcloud/WriteChannel.java new file mode 100644 index 0000000000..e6f06e23dc --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/WriteChannel.java @@ -0,0 +1,48 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import java.io.Closeable; +import java.nio.channels.WritableByteChannel; + +/** + * A channel for writing data to Google Cloud services. + * + *

Implementations of this class may further buffer data internally to reduce remote calls. + * Written data will only be visible after calling {@link #close()}. This interface implements + * {@link Restorable} to allow saving the writer's state to continue writing afterwards. + *

+ */ +public interface WriteChannel extends WritableByteChannel, Closeable, Restorable { + + /** + * Sets the minimum size that will be written by a single RPC. + * Written data will be buffered and only flushed upon reaching this size or closing the channel. + */ + void chunkSize(int chunkSize); + + /** + * Captures the write channel state so that it can be saved and restored afterwards. The original + * {@code WriteChannel} and the restored one should not both be used. Closing one channel + * causes the other channel to close; subsequent writes will fail. + * + * @return a {@link RestorableState} object that contains the write channel state and can restore + * it afterwards. + */ + @Override + RestorableState capture(); +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java new file mode 100644 index 0000000000..e49a17b019 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java @@ -0,0 +1,144 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import com.google.gcloud.spi.ServiceRpcFactory; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; +import java.io.Serializable; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Random; + +public class BaseWriteChannelTest { + + private abstract static class CustomService implements Service {} + private abstract static class CustomServiceOptions + extends ServiceOptions { + + private static final long serialVersionUID = 3302358029307467197L; + + protected CustomServiceOptions( + Class> serviceFactoryClass, + Class> rpcFactoryClass, + Builder builder) { + super(serviceFactoryClass, rpcFactoryClass, builder); + } + } + + private static final Serializable ENTITY = 42L; + private static final String UPLOAD_ID = "uploadId"; + private static final byte[] CONTENT = {0xD, 0xE, 0xA, 0xD}; + private static final int MIN_CHUNK_SIZE = 256 * 1024; + private static final int DEFAULT_CHUNK_SIZE = 8 * MIN_CHUNK_SIZE; + private static final Random RANDOM = new Random(); + private static BaseWriteChannel channel; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() { + channel = new BaseWriteChannel(null, ENTITY, UPLOAD_ID) { + @Override + public RestorableState capture() { + return null; + } + + @Override + protected void flushBuffer(int length, boolean last) {} + + @Override + protected BaseState.Builder stateBuilder() { + return null; + } + }; + } + + @Test + public void testConstructor() throws IOException { + assertEquals(null, channel.options()); + assertEquals(ENTITY, channel.entity()); + assertEquals(0, channel.position()); + assertEquals(UPLOAD_ID, channel.uploadId()); + assertEquals(0, channel.limit()); + assertTrue(channel.isOpen()); + assertArrayEquals(new byte[0], channel.buffer()); + assertEquals(DEFAULT_CHUNK_SIZE, channel.chunkSize()); + } + + @Test + public void testClose() throws IOException { + channel.close(); + assertFalse(channel.isOpen()); + assertNull(channel.buffer()); + } + + @Test + public void testValidateOpen() throws IOException { + channel.close(); + thrown.expect(IOException.class); + thrown.expectMessage("stream is closed"); + channel.write(ByteBuffer.allocate(42)); + } + + @Test + public void testChunkSize() throws IOException { + channel.chunkSize(42); + assertEquals(MIN_CHUNK_SIZE, channel.chunkSize()); + channel.chunkSize(2 * MIN_CHUNK_SIZE); + assertEquals(2 * MIN_CHUNK_SIZE, channel.chunkSize()); + channel.chunkSize(512 * 1025); + assertEquals(2 * MIN_CHUNK_SIZE, channel.chunkSize()); + } + + @Test + public void testWrite() throws IOException { + channel.write(ByteBuffer.wrap(CONTENT)); + assertEquals(CONTENT.length, channel.limit()); + assertEquals(DEFAULT_CHUNK_SIZE, channel.buffer().length); + assertArrayEquals(Arrays.copyOf(CONTENT, DEFAULT_CHUNK_SIZE), channel.buffer()); + } + + @Test + public void testWriteAndFlush() throws IOException { + ByteBuffer content = randomBuffer(DEFAULT_CHUNK_SIZE + 1); + channel.write(content); + assertEquals(DEFAULT_CHUNK_SIZE, channel.position()); + assertEquals(1, channel.limit()); + byte[] newContent = new byte[DEFAULT_CHUNK_SIZE]; + newContent[0] = content.get(DEFAULT_CHUNK_SIZE); + assertArrayEquals(newContent, channel.buffer()); + } + + private static ByteBuffer randomBuffer(int size) { + byte[] byteArray = new byte[size]; + RANDOM.nextBytes(byteArray); + return ByteBuffer.wrap(byteArray); + } +} From c5914ae568c419f810ec78ac7b0c6e9b21a3b98b Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 15 Jan 2016 15:10:21 +0100 Subject: [PATCH 101/663] Refactor BaseServiceException --- .../google/gcloud/BaseServiceException.java | 157 +++++++++++++++++- .../gcloud/BaseServiceExceptionTest.java | 134 +++++++++++++-- 2 files changed, 273 insertions(+), 18 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java index cd09334267..9f4bfdab99 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java @@ -16,26 +16,126 @@ package com.google.gcloud; +import com.google.api.client.googleapis.json.GoogleJsonError; +import com.google.api.client.googleapis.json.GoogleJsonResponseException; +import com.google.common.base.MoreObjects; + +import java.io.IOException; +import java.io.Serializable; +import java.net.SocketTimeoutException; +import java.util.Collections; +import java.util.Objects; +import java.util.Set; + /** * Base class for all service exceptions. */ public class BaseServiceException extends RuntimeException { - private static final long serialVersionUID = 5028833760039966178L; + protected static final class Error implements Serializable { + + private static final long serialVersionUID = -4019600198652965721L; + + private final Integer code; + private final String reason; + + public Error(Integer code, String reason) { + this.code = code; + this.reason = reason; + } + + /** + * Returns the code associated with this exception. + */ + public Integer code() { + return code; + } + + /** + * Returns the reason that caused the exception. + */ + public String reason() { + return reason; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("code", code).add("reason", reason).toString(); + } + + @Override + public int hashCode() { + return Objects.hash(code, reason); + } + } + + private static final long serialVersionUID = 759921776378760835L; + public static final int UNKNOWN_CODE = 0; private final int code; private final boolean retryable; + private final String reason; + private final boolean idempotent; - public BaseServiceException(int code, String message, boolean retryable) { - super(message); - this.code = code; - this.retryable = retryable; + public BaseServiceException(IOException exception, boolean idempotent) { + super(message(exception), exception); + if (exception instanceof GoogleJsonResponseException) { + Error error = error(((GoogleJsonResponseException) exception).getDetails()); + this.code = error.code; + this.reason = error.reason; + this.retryable = isRetryable(error); + } else { + this.code = UNKNOWN_CODE; + this.reason = null; + this.retryable = idempotent && isRetryable(exception); + } + this.idempotent = idempotent; + } + + public BaseServiceException(GoogleJsonError error, boolean idempotent) { + super(error.getMessage()); + this.code = error.getCode(); + this.reason = reason(error); + this.idempotent = idempotent; + this.retryable = idempotent && isRetryable(error); + } + + public BaseServiceException(int code, String message, String reason, boolean idempotent) { + this(code, message, reason, idempotent, null); } - public BaseServiceException(int code, String message, boolean retryable, Exception cause) { + public BaseServiceException(int code, String message, String reason, boolean idempotent, + Exception cause) { super(message, cause); this.code = code; - this.retryable = retryable; + this.reason = reason; + this.idempotent = idempotent; + this.retryable = idempotent && isRetryable(new Error(code, reason)); + } + + protected Set retryableErrors() { + return Collections.emptySet(); + } + + protected boolean isRetryable(GoogleJsonError error) { + return error != null && isRetryable(error(error)); + } + + protected boolean isRetryable(IOException exception) { + if (exception instanceof GoogleJsonResponseException) { + return isRetryable(((GoogleJsonResponseException) exception).getDetails()); + } + return exception instanceof SocketTimeoutException; + } + + protected boolean isRetryable(Error error) { + for (Error retryableError : retryableErrors()) { + if ((retryableError.code() == null || retryableError.code().equals(error.code())) + && (retryableError.reason() == null || retryableError.reason().equals(error.reason()))) { + return true; + } + } + return false; } /** @@ -45,10 +145,53 @@ public int code() { return code; } + /** + * Returns the reason that caused the exception. + */ + public String reason() { + return reason; + } + /** * Returns {@code true} when it is safe to retry the operation that caused this exception. */ public boolean retryable() { return retryable; } + + /** + * Returns {@code true} when the operation that caused this exception had no side effects. + */ + public boolean idempotent() { + return idempotent; + } + + protected static String reason(GoogleJsonError error) { + if (error.getErrors() != null && !error.getErrors().isEmpty()) { + return error.getErrors().get(0).getReason(); + } + return null; + } + + protected static Error error(GoogleJsonError error) { + return new Error(error.getCode(), reason(error)); + } + + protected static String message(IOException exception) { + if (exception instanceof GoogleJsonResponseException) { + return ((GoogleJsonResponseException) exception).getDetails().getMessage(); + } + return exception.getMessage(); + } + + protected static BaseServiceException translateAndThrow( + RetryHelper.RetryHelperException ex) { + if (ex.getCause() instanceof BaseServiceException) { + throw (BaseServiceException) ex.getCause(); + } + if (ex instanceof RetryHelper.RetryInterruptedException) { + RetryHelper.RetryInterruptedException.propagate(); + } + return null; + } } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java index f30fd3abfb..a6e22866ed 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java @@ -16,30 +16,142 @@ package com.google.gcloud; +import static com.google.gcloud.BaseServiceException.UNKNOWN_CODE; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import com.google.api.client.googleapis.json.GoogleJsonError; +import com.google.common.collect.ImmutableSet; import org.junit.Test; +import java.io.IOException; +import java.net.SocketTimeoutException; +import java.util.Set; + /** * Tests for {@link BaseServiceException}. */ public class BaseServiceExceptionTest { - private final int code = 1; - private final String message = "some message"; - private final boolean retryable = true; + private static final int CODE = 1; + private static final int CODE_NO_REASON = 2; + private static final String MESSAGE = "some message"; + private static final String REASON = "some reason"; + private static final boolean RETRYABLE = true; + private static final boolean IDEMPOTENT = true; + private static class CustomServiceException extends BaseServiceException { + + private static final long serialVersionUID = -195251309124875103L; + + public CustomServiceException(int code, String message, String reason, boolean idempotent) { + super(code, message, reason, idempotent); + } + + @Override + protected Set retryableErrors() { + return ImmutableSet.of(new Error(CODE, REASON), new Error(null, REASON), + new Error(CODE_NO_REASON, null)); + } + } @Test public void testBaseServiceException() { - BaseServiceException serviceException = new BaseServiceException(code, message, retryable); - assertEquals(serviceException.code(), code); - assertEquals(serviceException.getMessage(), message); - assertEquals(serviceException.getCause(), null); + BaseServiceException serviceException = new BaseServiceException(CODE, MESSAGE, REASON, + IDEMPOTENT); + assertEquals(CODE, serviceException.code()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.reason()); + assertFalse(serviceException.retryable()); + assertEquals(IDEMPOTENT, serviceException.idempotent()); + assertNull(serviceException.getCause()); + + serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); + assertEquals(CODE, serviceException.code()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.reason()); + assertFalse(serviceException.retryable()); + assertEquals(IDEMPOTENT, serviceException.idempotent()); + assertNull(serviceException.getCause()); Exception cause = new RuntimeException(); - serviceException = new BaseServiceException(code, message, retryable, cause); - assertEquals(serviceException.code(), code); - assertEquals(serviceException.getMessage(), message); - assertEquals(serviceException.getCause(), cause); + serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, cause); + assertEquals(CODE, serviceException.code()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.reason()); + assertFalse(serviceException.retryable()); + assertEquals(IDEMPOTENT, serviceException.idempotent()); + assertEquals(cause, serviceException.getCause()); + + serviceException = new BaseServiceException(CODE, MESSAGE, REASON, false, cause); + assertEquals(CODE, serviceException.code()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.reason()); + assertFalse(serviceException.retryable()); + assertFalse(serviceException.idempotent()); + assertEquals(cause, serviceException.getCause()); + + IOException exception = new SocketTimeoutException(); + serviceException = new BaseServiceException(exception, true); + assertTrue(serviceException.retryable()); + assertTrue(serviceException.idempotent()); + assertEquals(exception, serviceException.getCause()); + + GoogleJsonError error = new GoogleJsonError(); + error.setCode(CODE); + error.setMessage(MESSAGE); + serviceException = new BaseServiceException(error, true); + assertEquals(CODE, serviceException.code()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertFalse(serviceException.retryable()); + assertTrue(serviceException.idempotent()); + + serviceException = new CustomServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); + assertEquals(CODE, serviceException.code()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.reason()); + assertEquals(RETRYABLE, serviceException.retryable()); + assertEquals(IDEMPOTENT, serviceException.idempotent()); + + serviceException = new CustomServiceException(CODE_NO_REASON, MESSAGE, null, IDEMPOTENT); + assertEquals(CODE_NO_REASON, serviceException.code()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertNull(serviceException.reason()); + assertEquals(RETRYABLE, serviceException.retryable()); + assertEquals(IDEMPOTENT, serviceException.idempotent()); + + serviceException = new CustomServiceException(UNKNOWN_CODE, MESSAGE, REASON, IDEMPOTENT); + assertEquals(UNKNOWN_CODE, serviceException.code()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.reason()); + assertEquals(RETRYABLE, serviceException.retryable()); + assertEquals(IDEMPOTENT, serviceException.idempotent()); + } + + @Test + public void testTranslateAndThrow() throws Exception { + BaseServiceException cause = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); + RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class); + expect(exceptionMock.getCause()).andReturn(cause).times(2); + replay(exceptionMock); + try { + BaseServiceException ex = BaseServiceException.translateAndThrow(exceptionMock); + if (ex != null) { + throw ex; + } + } catch (BaseServiceException ex) { + assertEquals(CODE, ex.code()); + assertEquals(MESSAGE, ex.getMessage()); + assertFalse(ex.retryable()); + assertEquals(IDEMPOTENT, ex.idempotent()); + } finally { + verify(exceptionMock); + } } } From 9b05bc037caed1a3411afec01edb52c0681b08b9 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 15 Jan 2016 18:20:26 +0100 Subject: [PATCH 102/663] Move exception handler and interceptor to BaseService class --- .../java/com/google/gcloud/BaseService.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java index c028eaede3..d9e6f2db7c 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java @@ -16,6 +16,8 @@ package com.google.gcloud; +import com.google.gcloud.ExceptionHandler.Interceptor; + /** * Base class for service objects. * @@ -24,6 +26,29 @@ public abstract class BaseService> implements Service { + public static final Interceptor EXCEPTION_HANDLER_INTERCEPTOR = new Interceptor() { + + private static final long serialVersionUID = -8429573486870467828L; + + @Override + public RetryResult afterEval(Exception exception, RetryResult retryResult) { + return Interceptor.RetryResult.CONTINUE_EVALUATION; + } + + @Override + public RetryResult beforeEval(Exception exception) { + if (exception instanceof BaseServiceException) { + boolean retriable = ((BaseServiceException) exception).retryable(); + return retriable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.NO_RETRY; + } + return Interceptor.RetryResult.CONTINUE_EVALUATION; + } + }; + public static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.builder() + .abortOn(RuntimeException.class) + .interceptor(EXCEPTION_HANDLER_INTERCEPTOR) + .build(); + private final OptionsT options; protected BaseService(OptionsT options) { From 6aae69508e40c4e229844452ddab579ebdf25a70 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 20 Jan 2016 07:40:53 +0100 Subject: [PATCH 103/663] Rename translateAndThrow in BaseServiceException and make it package scope in other exceptions --- .../main/java/com/google/gcloud/BaseServiceException.java | 4 +--- .../java/com/google/gcloud/BaseServiceExceptionTest.java | 8 +++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java index 9f4bfdab99..351ad6cd18 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java @@ -184,14 +184,12 @@ protected static String message(IOException exception) { return exception.getMessage(); } - protected static BaseServiceException translateAndThrow( - RetryHelper.RetryHelperException ex) { + protected static void translateAndPropagateIfPossible(RetryHelper.RetryHelperException ex) { if (ex.getCause() instanceof BaseServiceException) { throw (BaseServiceException) ex.getCause(); } if (ex instanceof RetryHelper.RetryInterruptedException) { RetryHelper.RetryInterruptedException.propagate(); } - return null; } } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java index a6e22866ed..e3c6abb7d1 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java @@ -137,14 +137,12 @@ public void testBaseServiceException() { @Test public void testTranslateAndThrow() throws Exception { BaseServiceException cause = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); - RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class); + RetryHelper.RetryHelperException exceptionMock = + createMock(RetryHelper.RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try { - BaseServiceException ex = BaseServiceException.translateAndThrow(exceptionMock); - if (ex != null) { - throw ex; - } + BaseServiceException.translateAndPropagateIfPossible(exceptionMock); } catch (BaseServiceException ex) { assertEquals(CODE, ex.code()); assertEquals(MESSAGE, ex.getMessage()); From 256a36d83790748221b6543b60be3a9ded337f76 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 20 Jan 2016 07:55:39 +0100 Subject: [PATCH 104/663] Add throwable cause to DatastoreException --- .../src/main/java/com/google/gcloud/BaseServiceException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java index 351ad6cd18..b91090f94e 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java @@ -105,7 +105,7 @@ public BaseServiceException(int code, String message, String reason, boolean ide } public BaseServiceException(int code, String message, String reason, boolean idempotent, - Exception cause) { + Throwable cause) { super(message, cause); this.code = code; this.reason = reason; From 7941a83737beb6a8d3e2657439bd2630ea20fcdb Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 20 Jan 2016 09:28:40 +0100 Subject: [PATCH 105/663] Move isRetryable method to BaseServiceException.Error --- .../google/gcloud/BaseServiceException.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java index b91090f94e..0222a0d225 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java @@ -58,6 +58,16 @@ public String reason() { return reason; } + boolean isRetryable(Set retryableErrors) { + for (Error retryableError : retryableErrors) { + if ((retryableError.code() == null || retryableError.code().equals(this.code())) + && (retryableError.reason() == null || retryableError.reason().equals(this.reason()))) { + return true; + } + } + return false; + } + @Override public String toString() { return MoreObjects.toStringHelper(this).add("code", code).add("reason", reason).toString(); @@ -83,7 +93,7 @@ public BaseServiceException(IOException exception, boolean idempotent) { Error error = error(((GoogleJsonResponseException) exception).getDetails()); this.code = error.code; this.reason = error.reason; - this.retryable = isRetryable(error); + this.retryable = error.isRetryable(retryableErrors()); } else { this.code = UNKNOWN_CODE; this.reason = null; @@ -110,7 +120,7 @@ public BaseServiceException(int code, String message, String reason, boolean ide this.code = code; this.reason = reason; this.idempotent = idempotent; - this.retryable = idempotent && isRetryable(new Error(code, reason)); + this.retryable = idempotent && new Error(code, reason).isRetryable(retryableErrors()); } protected Set retryableErrors() { @@ -118,7 +128,7 @@ protected Set retryableErrors() { } protected boolean isRetryable(GoogleJsonError error) { - return error != null && isRetryable(error(error)); + return error != null && error(error).isRetryable(retryableErrors()); } protected boolean isRetryable(IOException exception) { @@ -128,16 +138,6 @@ protected boolean isRetryable(IOException exception) { return exception instanceof SocketTimeoutException; } - protected boolean isRetryable(Error error) { - for (Error retryableError : retryableErrors()) { - if ((retryableError.code() == null || retryableError.code().equals(error.code())) - && (retryableError.reason() == null || retryableError.reason().equals(error.reason()))) { - return true; - } - } - return false; - } - /** * Returns the code associated with this exception. */ From b788f37e00beeba31563b7576a6ddee8566ebe35 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 22 Jan 2016 09:47:26 +0100 Subject: [PATCH 106/663] Add location() and debugInfo() to BaseServiceException --- .../google/gcloud/BaseServiceException.java | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java index 0222a0d225..579340f125 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java @@ -86,20 +86,32 @@ public int hashCode() { private final boolean retryable; private final String reason; private final boolean idempotent; + private final String location; + private final String debugInfo; public BaseServiceException(IOException exception, boolean idempotent) { super(message(exception), exception); + int code = UNKNOWN_CODE; + String reason = null; + String location = null; + String debugInfo = null; if (exception instanceof GoogleJsonResponseException) { - Error error = error(((GoogleJsonResponseException) exception).getDetails()); - this.code = error.code; - this.reason = error.reason; - this.retryable = error.isRetryable(retryableErrors()); - } else { - this.code = UNKNOWN_CODE; - this.reason = null; - this.retryable = idempotent && isRetryable(exception); + GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails(); + Error error = error(jsonError); + code = error.code; + reason = error.reason; + if (reason != null) { + GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0); + location = errorInfo.getLocation(); + debugInfo = (String) errorInfo.get("debugInfo"); + } } + this.code = code; + this.retryable = idempotent && isRetryable(exception); + this.reason = reason; this.idempotent = idempotent; + this.location = location; + this.debugInfo = debugInfo; } public BaseServiceException(GoogleJsonError error, boolean idempotent) { @@ -108,6 +120,8 @@ public BaseServiceException(GoogleJsonError error, boolean idempotent) { this.reason = reason(error); this.idempotent = idempotent; this.retryable = idempotent && isRetryable(error); + this.location = null; + this.debugInfo = null; } public BaseServiceException(int code, String message, String reason, boolean idempotent) { @@ -121,6 +135,8 @@ public BaseServiceException(int code, String message, String reason, boolean ide this.reason = reason; this.idempotent = idempotent; this.retryable = idempotent && new Error(code, reason).isRetryable(retryableErrors()); + this.location = null; + this.debugInfo = null; } protected Set retryableErrors() { @@ -166,6 +182,18 @@ public boolean idempotent() { return idempotent; } + /** + * Returns the service location where the error causing the exception occurred. Returns + * {@code null} if not set. + */ + public String location() { + return location; + } + + protected String debugInfo() { + return debugInfo; + } + protected static String reason(GoogleJsonError error) { if (error.getErrors() != null && !error.getErrors().isEmpty()) { return error.getErrors().get(0).getReason(); From e53a96882eab12853ff6c417fafe00e914e3000d Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 26 Jan 2016 17:41:21 -0800 Subject: [PATCH 107/663] Release version 0.1.3 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d87e0d7eae..d1b3679bed 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.1.3-SNAPSHOT + 0.1.3 gcloud-java-core From d2fa3fe2751e99648b6f660b485533fde8ac11a8 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Wed, 27 Jan 2016 02:24:50 +0000 Subject: [PATCH 108/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f47d99779a..9063bebebb 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -17,16 +17,16 @@ If you are using Maven, add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.1.2 + 0.1.3 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:0.1.2' +compile 'com.google.gcloud:gcloud-java-core:0.1.3' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.2" +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.3" ``` Troubleshooting From 539b6824d192b37b3244a5c1409ea7caf8dbdec5 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 26 Jan 2016 18:45:02 -0800 Subject: [PATCH 109/663] update version to 0.1.4-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d1b3679bed..7373b40abc 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.gcloud gcloud-java-pom - 0.1.3 + 0.1.4-SNAPSHOT gcloud-java-core From d4f8e5dd39b63ec76b0a2ef1b45dd79eb0189d85 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 1 Feb 2016 17:35:06 -0800 Subject: [PATCH 110/663] Fix ServiceOptions merge bug, remove unnecessary protected modifier from DateTime, set cursorAfter to endCursor where appropriate, and fix error codes for retries. --- .../src/main/java/com/google/gcloud/ServiceOptions.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 34280dbf92..31e5438094 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -18,7 +18,6 @@ import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.api.client.extensions.appengine.http.UrlFetchTransport; @@ -229,8 +228,7 @@ public B clock(Clock clock) { * @return the builder */ public B projectId(String projectId) { - this.projectId = - checkNotNull(projectId, "Project ID cannot be set to null. Leave unset for default."); + this.projectId = projectId; return self(); } From ed121340e283a45878fdddcefed7d6e83e33c100 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 5 Feb 2016 17:06:41 +0100 Subject: [PATCH 111/663] Fix the 'Definition of groupId is redundant' mvn warning --- google-cloud-core/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7373b40abc..bd7f26e0bc 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -1,7 +1,6 @@ 4.0.0 - com.google.gcloud gcloud-java-core jar GCloud Java core From 3199641e81b32da8cfbf305c1ec1bf6b8036765e Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 10 Feb 2016 10:38:24 -0800 Subject: [PATCH 112/663] Fix indentation issues in javadoc code samples --- .../src/main/java/com/google/gcloud/Restorable.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java index 90633c7004..0b573522e3 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java @@ -21,14 +21,14 @@ * *

* A typical capture usage: - *

  {@code
+ * 
 {@code
  * X restorableObj; // X instanceof Restorable
  * RestorableState state = restorableObj.capture();
  * .. persist state
  * }
* * A typical restore usage: - *
  {@code
+ * 
 {@code
  * RestorableState state = ... // read from persistence
  * X restorableObj = state.restore();
  * ...

From 0c2f2976331f4a869dd98240a4d18b5844bd929a Mon Sep 17 00:00:00 2001
From: Marco Ziccardi 
Date: Thu, 11 Feb 2016 17:01:29 +0100
Subject: [PATCH 113/663] Add codacy badge to READMEs

---
 google-cloud-core/README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md
index 9063bebebb..8b91e49f38 100644
--- a/google-cloud-core/README.md
+++ b/google-cloud-core/README.md
@@ -6,6 +6,7 @@ This module provides common functionality required by service-specific modules o
 [![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java)
 [![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master)
 [![Maven](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg)](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg)
+[![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/gcloud-java)
 
 -  [Homepage] (https://googlecloudplatform.github.io/gcloud-java/)
 -  [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/package-summary.html)

From deb4b68300008b187924cccae7d4e9c5176bc18a Mon Sep 17 00:00:00 2001
From: Marco Ziccardi 
Date: Fri, 12 Feb 2016 12:18:02 +0100
Subject: [PATCH 114/663] Update dependencies when possible

---
 google-cloud-core/pom.xml | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml
index bd7f26e0bc..3463f40b52 100644
--- a/google-cloud-core/pom.xml
+++ b/google-cloud-core/pom.xml
@@ -35,24 +35,24 @@
     
       com.google.http-client
       google-http-client
-      1.20.0
+      1.21.0
       compile
     
     
       com.google.oauth-client
       google-oauth-client
-      1.20.0
+      1.21.0
       compile
     
     
       com.google.guava
       guava
-      18.0
+      19.0
     
     
       com.google.api-client
       google-api-client-appengine
-      1.20.0
+      1.21.0
       compile
       
         
@@ -64,7 +64,7 @@
     
       com.google.http-client
       google-http-client-jackson
-      1.20.0
+      1.21.0
       compile
       
         
@@ -82,19 +82,19 @@
     
       joda-time
       joda-time
-      2.8.2
+      2.9.2
       compile
     
     
       org.json
       json
-      20090211
+      20151123
       compile
     
     
       org.easymock
       easymock
-      3.3
+      3.4
       test
     
   

From 2414ee8aebf09984301bfa9d6ecef027f2a7ce8c Mon Sep 17 00:00:00 2001
From: Marco Ziccardi 
Date: Fri, 12 Feb 2016 12:19:04 +0100
Subject: [PATCH 115/663] Add versioneye badge to READMEs

---
 google-cloud-core/README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md
index 8b91e49f38..b7e5e05b6a 100644
--- a/google-cloud-core/README.md
+++ b/google-cloud-core/README.md
@@ -7,6 +7,7 @@ This module provides common functionality required by service-specific modules o
 [![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master)
 [![Maven](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg)](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg)
 [![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/gcloud-java)
+[![Dependency Status](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969)
 
 -  [Homepage] (https://googlecloudplatform.github.io/gcloud-java/)
 -  [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/package-summary.html)

From e15a6181bc0df5854346a6cd7402e1b643784edc Mon Sep 17 00:00:00 2001
From: Ajay Kannan 
Date: Wed, 17 Feb 2016 14:16:41 -0800
Subject: [PATCH 116/663] Add IAM Policy classes

---
 google-cloud-core/pom.xml                     |  12 +
 .../java/com/google/gcloud/IamPolicy.java     | 530 ++++++++++++++++++
 .../java/com/google/gcloud/IamPolicyTest.java | 126 +++++
 .../com/google/gcloud/SerializationTest.java  |  49 ++
 4 files changed, 717 insertions(+)
 create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java
 create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java
 create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java

diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml
index 3463f40b52..67d3af27d1 100644
--- a/google-cloud-core/pom.xml
+++ b/google-cloud-core/pom.xml
@@ -16,6 +16,18 @@
     gcloud-java-core
   
   
+    
+      com.google.apis
+      google-api-services-cloudresourcemanager
+      v1beta1-rev10-1.21.0
+      compile
+      
+        
+          com.google.guava
+          guava-jdk5
+        
+      
+    
     
       com.google.auth
       google-auth-library-credentials
diff --git a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java
new file mode 100644
index 0000000000..3109972956
--- /dev/null
+++ b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java
@@ -0,0 +1,530 @@
+/*
+ * Copyright 2016 Google Inc. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.gcloud;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * An Identity and Access Management (IAM) policy. It is used to specify access control policies for
+ * Cloud Platform resources. A Policy consists of a list of ACLs (also known as bindings in Cloud
+ * IAM documentation). An ACL binds a list of identities to a role, where the identities can be user
+ * accounts, Google groups, Google domains, and service accounts. A role is a named list of
+ * permissions defined by IAM.
+ *
+ * @see Policy
+ */
+public class IamPolicy implements Serializable {
+
+  static final long serialVersionUID = 1114489978726897720L;
+
+  private final List acls;
+  private final String etag;
+  private final int version;
+
+  public static class Identity implements Serializable {
+
+    private static final long serialVersionUID = 30811617560110848L;
+
+    private final Type type;
+    private final String id;
+
+    /**
+     * The types of IAM identities.
+     */
+    public enum Type {
+      /**
+       * Represents anyone who is on the internet; with or without a Google account.
+       */
+      ALL_USERS,
+
+      /**
+       * Represents anyone who is authenticated with a Google account or a service account.
+       */
+      ALL_AUTHENTICATED_USERS,
+
+      /**
+       * Represents a specific Google account.
+       */
+      USER,
+
+      /**
+       * Represents a service account.
+       */
+      SERVICE_ACCOUNT,
+
+      /**
+       * Represents a Google group.
+       */
+      GROUP,
+
+      /**
+       * Represents all the users of a Google Apps domain name.
+       */
+      DOMAIN
+    }
+
+    Identity(Type type, String id) {
+      this.type = type;
+      this.id = id;
+    }
+
+    public Type type() {
+      return type;
+    }
+
+    /**
+     * Returns the string identifier for this identity. The id corresponds to:
+     * 
    + *
  • email address (for identities of type {@code USER}, {@code SERVICE_ACCOUNT}, and + * {@code GROUP}) + *
  • domain (for identities of type {@code DOMAIN}) + *
  • null (for identities of type {@code ALL_USERS} and {@code ALL_AUTHENTICATED_USERS}) + *
+ */ + public String id() { + return id; + } + + /** + * Returns a new identity representing anyone who is on the internet; with or without a Google + * account. + */ + public static Identity allUsers() { + return new Identity(Type.ALL_USERS, null); + } + + /** + * Returns a new identity representing anyone who is authenticated with a Google account or a + * service account. + */ + public static Identity allAuthenticatedUsers() { + return new Identity(Type.ALL_AUTHENTICATED_USERS, null); + } + + /** + * Returns a new user identity. + * + * @param email An email address that represents a specific Google account. For example, + * alice@gmail.com or joe@example.com. + */ + public static Identity user(String email) { + return new Identity(Type.USER, checkNotNull(email)); + } + + /** + * Returns a new service account identity. + * + * @param email An email address that represents a service account. For example, + * my-other-app@appspot.gserviceaccount.com. + */ + public static Identity serviceAccount(String email) { + return new Identity(Type.SERVICE_ACCOUNT, checkNotNull(email)); + } + + /** + * Returns a new group identity. + * + * @param email An email address that represents a Google group. For example, + * admins@example.com. + */ + public static Identity group(String email) { + return new Identity(Type.GROUP, checkNotNull(email)); + } + + /** + * Returns a new domain identity. + * + * @param domain A Google Apps domain name that represents all the users of that domain. For + * example, google.com or example.com. + */ + public static Identity domain(String domain) { + return new Identity(Type.DOMAIN, checkNotNull(domain)); + } + + @Override + public int hashCode() { + return Objects.hash(id, type); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Identity)) { + return false; + } + Identity other = (Identity) obj; + return Objects.equals(toPb(), other.toPb()); + } + + String toPb() { + switch (type) { + case ALL_USERS: + return "allUsers"; + case ALL_AUTHENTICATED_USERS: + return "allAuthenticatedUsers"; + case USER: + return "user:" + id; + case SERVICE_ACCOUNT: + return "serviceAccount:" + id; + case GROUP: + return "group:" + id; + default: + return "domain:" + id; + } + } + + static Identity fromPb(String identityStr) { + String[] info = identityStr.split(":"); + switch (info[0]) { + case "allUsers": + return allUsers(); + case "allAuthenticatedUsers": + return allAuthenticatedUsers(); + case "user": + return user(info[1]); + case "serviceAccount": + return serviceAccount(info[1]); + case "group": + return group(info[1]); + case "domain": + return domain(info[1]); + default: + throw new IllegalArgumentException("Unexpected identity type: " + info[0]); + } + } + } + + /** + * An ACL binds a list of identities to a role, where the identities can be user accounts, Google + * groups, Google domains, and service accounts. A role is a named list of permissions defined by + * IAM. + * + * @see Binding + */ + public static class Acl implements Serializable { + + private static final long serialVersionUID = 3954282899483745158L; + + private final List identities; + private final String role; + + /** + * An ACL builder. + */ + public static class Builder { + private final List members = new LinkedList<>(); + private String role; + + Builder(String role) { + this.role = role; + } + + /** + * Sets the role associated with this ACL. + */ + public Builder role(String role) { + this.role = role; + return this; + } + + /** + * Replaces the builder's list of identities with the given list. + */ + public Builder identities(List identities) { + this.members.clear(); + this.members.addAll(identities); + return this; + } + + /** + * Adds one or more identities to the list of identities associated with the ACL. + */ + public Builder addIdentity(Identity first, Identity... others) { + members.add(first); + members.addAll(Arrays.asList(others)); + return this; + } + + /** + * Removes the specified identity from the ACL. + */ + public Builder removeIdentity(Identity identity) { + members.remove(identity); + return this; + } + + public Acl build() { + return new Acl(this); + } + } + + Acl(Builder builder) { + identities = ImmutableList.copyOf(checkNotNull(builder.members)); + role = checkNotNull(builder.role); + } + + /** + * Returns the list of identities associated with this ACL. + */ + public List identities() { + return identities; + } + + /** + * Returns the role associated with this ACL. + */ + public String role() { + return role; + } + + /** + * Returns an ACL builder for the specific role type. + * + * @param role string representing the role, without the "roles/" prefix. An example of a valid + * legacy role is "viewer". An example of a valid service-specific role is + * "pubsub.publisher". + */ + public static Builder builder(String role) { + return new Builder(role); + } + + /** + * Returns an ACL for the role type and list of identities provided. + * + * @param role string representing the role, without the "roles/" prefix. An example of a valid + * legacy role is "viewer". An example of a valid service-specific role is + * "pubsub.publisher". + * @param members list of identities associated with the role. + */ + public static Acl of(String role, List members) { + return new Acl(new Builder(role).identities(members)); + } + + /** + * Returns an ACL for the role type and identities provided. + * + * @param role string representing the role, without the "roles/" prefix. An example of a valid + * legacy role is "viewer". An example of a valid service-specific role is + * "pubsub.publisher". + * @param first identity associated with the role. + * @param others any other identities associated with the role. + */ + public static Acl of(String role, Identity first, Identity... others) { + return new Acl(new Builder(role).addIdentity(first, others)); + } + + public Builder toBuilder() { + return new Builder(role).identities(identities); + } + + @Override + public int hashCode() { + return Objects.hash(identities, role); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Acl)) { + return false; + } + Acl other = (Acl) obj; + return Objects.equals(toPb(), other.toPb()); + } + + com.google.api.services.cloudresourcemanager.model.Binding toPb() { + com.google.api.services.cloudresourcemanager.model.Binding bindingPb = + new com.google.api.services.cloudresourcemanager.model.Binding(); + bindingPb.setMembers(Lists.transform(identities, new Function() { + @Override + public String apply(Identity identity) { + return identity.toPb(); + } + })); + bindingPb.setRole("roles/" + role); + return bindingPb; + } + + static Acl fromPb(com.google.api.services.cloudresourcemanager.model.Binding bindingPb) { + return of( + bindingPb.getRole().substring("roles/".length()), + Lists.transform(bindingPb.getMembers(), new Function() { + @Override + public Identity apply(String memberPb) { + return Identity.fromPb(memberPb); + } + })); + } + } + + /** + * Builder for an IAM Policy. + */ + public static class Builder { + + private final List acls = new LinkedList<>(); + private String etag; + private int version; + + /** + * Replaces the builder's list of ACLs with the given list of ACLs. + */ + public Builder acls(List acls) { + this.acls.clear(); + this.acls.addAll(acls); + return this; + } + + /** + * Adds one or more ACLs to the policy. + */ + public Builder addAcl(Acl first, Acl... others) { + acls.add(first); + acls.addAll(Arrays.asList(others)); + return this; + } + + /** + * Removes the specified ACL. + */ + public Builder removeAcl(Acl acl) { + acls.remove(acl); + return this; + } + + /** + * Sets the policy's etag. + * + *

Etags are used for optimistic concurrency control as a way to help prevent simultaneous + * updates of a policy from overwriting each other. It is strongly suggested that systems make + * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid + * race conditions. An etag is returned in the response to getIamPolicy, and systems are + * expected to put that etag in the request to setIamPolicy to ensure that their change will be + * applied to the same version of the policy. If no etag is provided in the call to + * setIamPolicy, then the existing policy is overwritten blindly. + */ + public Builder etag(String etag) { + this.etag = etag; + return this; + } + + /** + * Sets the version of the policy. The default version is 0. + */ + public Builder version(int version) { + this.version = version; + return this; + } + + public IamPolicy build() { + return new IamPolicy(this); + } + } + + IamPolicy(Builder builder) { + acls = ImmutableList.copyOf(builder.acls); + etag = builder.etag; + version = builder.version; + } + + /** + * The list of ACLs specified in the policy. + */ + public List acls() { + return acls; + } + + /** + * The policy's etag. + * + *

Etags are used for optimistic concurrency control as a way to help prevent simultaneous + * updates of a policy from overwriting each other. It is strongly suggested that systems make + * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid + * race conditions. An etag is returned in the response to getIamPolicy, and systems are + * expected to put that etag in the request to setIamPolicy to ensure that their change will be + * applied to the same version of the policy. If no etag is provided in the call to + * setIamPolicy, then the existing policy is overwritten blindly. + */ + public String etag() { + return etag; + } + + /** + * The version of the policy. The default version is 0. + */ + public int version() { + return version; + } + + @Override + public int hashCode() { + return Objects.hash(acls, etag, version); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof IamPolicy)) { + return false; + } + IamPolicy other = (IamPolicy) obj; + return Objects.equals(toPb(), other.toPb()); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().acls(acls).etag(etag).version(version); + } + + com.google.api.services.cloudresourcemanager.model.Policy toPb() { + com.google.api.services.cloudresourcemanager.model.Policy policyPb = + new com.google.api.services.cloudresourcemanager.model.Policy(); + policyPb.setBindings(Lists.transform( + acls, new Function() { + @Override + public com.google.api.services.cloudresourcemanager.model.Binding apply(Acl acl) { + return acl.toPb(); + } + })); + policyPb.setEtag(etag); + policyPb.setVersion(version); + return policyPb; + } + + static IamPolicy fromPb(com.google.api.services.cloudresourcemanager.model.Policy policyPb) { + Builder builder = new Builder(); + builder.acls(Lists.transform( + policyPb.getBindings(), + new Function() { + @Override + public Acl apply(com.google.api.services.cloudresourcemanager.model.Binding binding) { + return Acl.fromPb(binding); + } + })); + return builder.etag(policyPb.getEtag()).version(policyPb.getVersion()).build(); + } +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java new file mode 100644 index 0000000000..a87a0b5f28 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java @@ -0,0 +1,126 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import com.google.gcloud.IamPolicy.Acl; +import com.google.gcloud.IamPolicy.Identity; + +import org.junit.Test; + +public class IamPolicyTest { + + private static final Identity ALL_USERS = Identity.allUsers(); + private static final Identity ALL_AUTHENTICATED_USERS = Identity.allAuthenticatedUsers(); + private static final Identity USER = Identity.user("abc@gmail.com"); + private static final Identity SERVICE_ACCOUNT = + Identity.serviceAccount("service-account@gmail.com"); + private static final Identity GROUP = Identity.group("group@gmail.com"); + private static final Identity DOMAIN = Identity.domain("google.com"); + private static final Acl ACL1 = Acl.of("viewer", USER, SERVICE_ACCOUNT, ALL_USERS); + private static final Acl ACL2 = Acl.of("editor", ALL_AUTHENTICATED_USERS, GROUP, DOMAIN); + private static final IamPolicy FULL_POLICY = + IamPolicy.builder().addAcl(ACL1, ACL2).etag("etag").version(1).build(); + private static final IamPolicy SIMPLE_POLICY = IamPolicy.builder().addAcl(ACL1, ACL2).build(); + + @Test + public void testIdentityOf() { + assertEquals(Identity.Type.ALL_USERS, ALL_USERS.type()); + assertEquals(null, ALL_USERS.id()); + assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTHENTICATED_USERS.type()); + assertEquals(null, ALL_AUTHENTICATED_USERS.id()); + assertEquals(Identity.Type.USER, USER.type()); + assertEquals("abc@gmail.com", USER.id()); + assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type()); + assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.id()); + assertEquals(Identity.Type.GROUP, GROUP.type()); + assertEquals("group@gmail.com", GROUP.id()); + assertEquals(Identity.Type.DOMAIN, DOMAIN.type()); + assertEquals("google.com", DOMAIN.id()); + } + + @Test + public void testIdentityToAndFromPb() { + assertEquals(ALL_USERS, Identity.fromPb(ALL_USERS.toPb())); + assertEquals(ALL_AUTHENTICATED_USERS, Identity.fromPb(ALL_AUTHENTICATED_USERS.toPb())); + assertEquals(USER, Identity.fromPb(USER.toPb())); + assertEquals(SERVICE_ACCOUNT, Identity.fromPb(SERVICE_ACCOUNT.toPb())); + assertEquals(GROUP, Identity.fromPb(GROUP.toPb())); + assertEquals(DOMAIN, Identity.fromPb(DOMAIN.toPb())); + } + + @Test + public void testAclBuilder() { + Acl acl = Acl.builder("owner").addIdentity(USER, GROUP).build(); + assertEquals("owner", acl.role()); + assertEquals(ImmutableList.of(USER, GROUP), acl.identities()); + acl = acl.toBuilder().role("viewer").removeIdentity(GROUP).build(); + assertEquals("viewer", acl.role()); + assertEquals(ImmutableList.of(USER), acl.identities()); + acl = acl.toBuilder().identities(ImmutableList.of(SERVICE_ACCOUNT)).build(); + assertEquals("viewer", acl.role()); + assertEquals(ImmutableList.of(SERVICE_ACCOUNT), acl.identities()); + } + + @Test + public void testAclOf() { + assertEquals("viewer", ACL1.role()); + assertEquals(ImmutableList.of(USER, SERVICE_ACCOUNT, ALL_USERS), ACL1.identities()); + Acl aclFromIdentitiesList = Acl.of("editor", ImmutableList.of(USER, SERVICE_ACCOUNT)); + assertEquals("editor", aclFromIdentitiesList.role()); + assertEquals(ImmutableList.of(USER, SERVICE_ACCOUNT), aclFromIdentitiesList.identities()); + } + + @Test + public void testAclToBuilder() { + assertEquals(ACL1, ACL1.toBuilder().build()); + } + + @Test + public void testAclToAndFromPb() { + assertEquals(ACL1, Acl.fromPb(ACL1.toPb())); + } + + @Test + public void testIamPolicyBuilder() { + assertEquals(ImmutableList.of(ACL1, ACL2), FULL_POLICY.acls()); + assertEquals("etag", FULL_POLICY.etag()); + assertEquals(1, FULL_POLICY.version()); + IamPolicy policy = FULL_POLICY.toBuilder().acls(ImmutableList.of(ACL2)).build(); + assertEquals(ImmutableList.of(ACL2), policy.acls()); + assertEquals("etag", policy.etag()); + assertEquals(1, policy.version()); + policy = SIMPLE_POLICY.toBuilder().removeAcl(ACL2).build(); + assertEquals(ImmutableList.of(ACL1), policy.acls()); + assertEquals(null, policy.etag()); + assertEquals(0, policy.version()); + } + + @Test + public void testIamPolicyToBuilder() { + assertEquals(FULL_POLICY, FULL_POLICY.toBuilder().build()); + assertEquals(SIMPLE_POLICY, SIMPLE_POLICY.toBuilder().build()); + } + + @Test + public void testToAndFromPb() { + assertEquals(FULL_POLICY, IamPolicy.fromPb(FULL_POLICY.toPb())); + assertEquals(SIMPLE_POLICY, IamPolicy.fromPb(SIMPLE_POLICY.toPb())); + } +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java new file mode 100644 index 0000000000..b529b2c09f --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java @@ -0,0 +1,49 @@ +package com.google.gcloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; + +import com.google.common.collect.ImmutableList; +import com.google.gcloud.IamPolicy.Acl; +import com.google.gcloud.IamPolicy.Identity; + +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + +public class SerializationTest { + + private static final Identity IDENTITY = Identity.user("abc@gmail.com"); + private static final Acl ACL = Acl.of("viewer", ImmutableList.of(IDENTITY)); + private static final IamPolicy POLICY = + IamPolicy.builder().acls(ImmutableList.of(ACL)).etag("etag").version(1).build(); + + @Test + public void testModelAndRequests() throws Exception { + Serializable[] objects = {IDENTITY, ACL, POLICY}; + for (Serializable obj : objects) { + Object copy = serializeAndDeserialize(obj); + assertEquals(obj, obj); + assertEquals(obj, copy); + assertNotSame(obj, copy); + assertEquals(copy, copy); + } + } + + @SuppressWarnings("unchecked") + private T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundException { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + try (ObjectOutputStream output = new ObjectOutputStream(bytes)) { + output.writeObject(obj); + } + try (ObjectInputStream input = + new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) { + return (T) input.readObject(); + } + } +} From ad9475d26cd9cd8928cb9ebd07d0c50b072f6edd Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 18 Feb 2016 16:29:47 -0800 Subject: [PATCH 117/663] move to/fromPb functions to Resource Manager --- google-cloud-core/pom.xml | 12 --- .../java/com/google/gcloud/IamPolicy.java | 98 +------------------ .../java/com/google/gcloud/IamPolicyTest.java | 27 +---- 3 files changed, 7 insertions(+), 130 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 67d3af27d1..3463f40b52 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -16,18 +16,6 @@ gcloud-java-core - - com.google.apis - google-api-services-cloudresourcemanager - v1beta1-rev10-1.21.0 - compile - - - com.google.guava - guava-jdk5 - - - com.google.auth google-auth-library-credentials diff --git a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java index 3109972956..a16ab790b3 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java @@ -18,9 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import java.io.Serializable; import java.util.Arrays; @@ -176,44 +174,7 @@ public boolean equals(Object obj) { return false; } Identity other = (Identity) obj; - return Objects.equals(toPb(), other.toPb()); - } - - String toPb() { - switch (type) { - case ALL_USERS: - return "allUsers"; - case ALL_AUTHENTICATED_USERS: - return "allAuthenticatedUsers"; - case USER: - return "user:" + id; - case SERVICE_ACCOUNT: - return "serviceAccount:" + id; - case GROUP: - return "group:" + id; - default: - return "domain:" + id; - } - } - - static Identity fromPb(String identityStr) { - String[] info = identityStr.split(":"); - switch (info[0]) { - case "allUsers": - return allUsers(); - case "allAuthenticatedUsers": - return allAuthenticatedUsers(); - case "user": - return user(info[1]); - case "serviceAccount": - return serviceAccount(info[1]); - case "group": - return group(info[1]); - case "domain": - return domain(info[1]); - default: - throw new IllegalArgumentException("Unexpected identity type: " + info[0]); - } + return Objects.equals(id, other.id()) && Objects.equals(type, other.type()); } } @@ -351,31 +312,7 @@ public boolean equals(Object obj) { return false; } Acl other = (Acl) obj; - return Objects.equals(toPb(), other.toPb()); - } - - com.google.api.services.cloudresourcemanager.model.Binding toPb() { - com.google.api.services.cloudresourcemanager.model.Binding bindingPb = - new com.google.api.services.cloudresourcemanager.model.Binding(); - bindingPb.setMembers(Lists.transform(identities, new Function() { - @Override - public String apply(Identity identity) { - return identity.toPb(); - } - })); - bindingPb.setRole("roles/" + role); - return bindingPb; - } - - static Acl fromPb(com.google.api.services.cloudresourcemanager.model.Binding bindingPb) { - return of( - bindingPb.getRole().substring("roles/".length()), - Lists.transform(bindingPb.getMembers(), new Function() { - @Override - public Identity apply(String memberPb) { - return Identity.fromPb(memberPb); - } - })); + return Objects.equals(identities, other.identities()) && Objects.equals(role, other.role()); } } @@ -489,7 +426,8 @@ public boolean equals(Object obj) { return false; } IamPolicy other = (IamPolicy) obj; - return Objects.equals(toPb(), other.toPb()); + return Objects.equals(acls, other.acls()) && Objects.equals(etag, other.etag()) + && Objects.equals(version, other.version()); } public static Builder builder() { @@ -499,32 +437,4 @@ public static Builder builder() { public Builder toBuilder() { return new Builder().acls(acls).etag(etag).version(version); } - - com.google.api.services.cloudresourcemanager.model.Policy toPb() { - com.google.api.services.cloudresourcemanager.model.Policy policyPb = - new com.google.api.services.cloudresourcemanager.model.Policy(); - policyPb.setBindings(Lists.transform( - acls, new Function() { - @Override - public com.google.api.services.cloudresourcemanager.model.Binding apply(Acl acl) { - return acl.toPb(); - } - })); - policyPb.setEtag(etag); - policyPb.setVersion(version); - return policyPb; - } - - static IamPolicy fromPb(com.google.api.services.cloudresourcemanager.model.Policy policyPb) { - Builder builder = new Builder(); - builder.acls(Lists.transform( - policyPb.getBindings(), - new Function() { - @Override - public Acl apply(com.google.api.services.cloudresourcemanager.model.Binding binding) { - return Acl.fromPb(binding); - } - })); - return builder.etag(policyPb.getEtag()).version(policyPb.getVersion()).build(); - } } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java index a87a0b5f28..76a57b5fef 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java @@ -55,16 +55,6 @@ public void testIdentityOf() { assertEquals("google.com", DOMAIN.id()); } - @Test - public void testIdentityToAndFromPb() { - assertEquals(ALL_USERS, Identity.fromPb(ALL_USERS.toPb())); - assertEquals(ALL_AUTHENTICATED_USERS, Identity.fromPb(ALL_AUTHENTICATED_USERS.toPb())); - assertEquals(USER, Identity.fromPb(USER.toPb())); - assertEquals(SERVICE_ACCOUNT, Identity.fromPb(SERVICE_ACCOUNT.toPb())); - assertEquals(GROUP, Identity.fromPb(GROUP.toPb())); - assertEquals(DOMAIN, Identity.fromPb(DOMAIN.toPb())); - } - @Test public void testAclBuilder() { Acl acl = Acl.builder("owner").addIdentity(USER, GROUP).build(); @@ -82,9 +72,9 @@ public void testAclBuilder() { public void testAclOf() { assertEquals("viewer", ACL1.role()); assertEquals(ImmutableList.of(USER, SERVICE_ACCOUNT, ALL_USERS), ACL1.identities()); - Acl aclFromIdentitiesList = Acl.of("editor", ImmutableList.of(USER, SERVICE_ACCOUNT)); - assertEquals("editor", aclFromIdentitiesList.role()); - assertEquals(ImmutableList.of(USER, SERVICE_ACCOUNT), aclFromIdentitiesList.identities()); + Acl aclFromList = Acl.of("editor", ImmutableList.of(USER, SERVICE_ACCOUNT)); + assertEquals("editor", aclFromList.role()); + assertEquals(ImmutableList.of(USER, SERVICE_ACCOUNT), aclFromList.identities()); } @Test @@ -92,11 +82,6 @@ public void testAclToBuilder() { assertEquals(ACL1, ACL1.toBuilder().build()); } - @Test - public void testAclToAndFromPb() { - assertEquals(ACL1, Acl.fromPb(ACL1.toPb())); - } - @Test public void testIamPolicyBuilder() { assertEquals(ImmutableList.of(ACL1, ACL2), FULL_POLICY.acls()); @@ -117,10 +102,4 @@ public void testIamPolicyToBuilder() { assertEquals(FULL_POLICY, FULL_POLICY.toBuilder().build()); assertEquals(SIMPLE_POLICY, SIMPLE_POLICY.toBuilder().build()); } - - @Test - public void testToAndFromPb() { - assertEquals(FULL_POLICY, IamPolicy.fromPb(FULL_POLICY.toPb())); - assertEquals(SIMPLE_POLICY, IamPolicy.fromPb(SIMPLE_POLICY.toPb())); - } } From 140026c42a9219e2b07c9b777c7b15107db8b0b4 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 18 Feb 2016 17:33:13 -0800 Subject: [PATCH 118/663] variable rename to make codacy happy --- .../src/test/java/com/google/gcloud/IamPolicyTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java index 76a57b5fef..0d4e9fbfa6 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java @@ -27,14 +27,14 @@ public class IamPolicyTest { private static final Identity ALL_USERS = Identity.allUsers(); - private static final Identity ALL_AUTHENTICATED_USERS = Identity.allAuthenticatedUsers(); + private static final Identity ALL_AUTH_USERS = Identity.allAuthenticatedUsers(); private static final Identity USER = Identity.user("abc@gmail.com"); private static final Identity SERVICE_ACCOUNT = Identity.serviceAccount("service-account@gmail.com"); private static final Identity GROUP = Identity.group("group@gmail.com"); private static final Identity DOMAIN = Identity.domain("google.com"); private static final Acl ACL1 = Acl.of("viewer", USER, SERVICE_ACCOUNT, ALL_USERS); - private static final Acl ACL2 = Acl.of("editor", ALL_AUTHENTICATED_USERS, GROUP, DOMAIN); + private static final Acl ACL2 = Acl.of("editor", ALL_AUTH_USERS, GROUP, DOMAIN); private static final IamPolicy FULL_POLICY = IamPolicy.builder().addAcl(ACL1, ACL2).etag("etag").version(1).build(); private static final IamPolicy SIMPLE_POLICY = IamPolicy.builder().addAcl(ACL1, ACL2).build(); @@ -43,8 +43,8 @@ public class IamPolicyTest { public void testIdentityOf() { assertEquals(Identity.Type.ALL_USERS, ALL_USERS.type()); assertEquals(null, ALL_USERS.id()); - assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTHENTICATED_USERS.type()); - assertEquals(null, ALL_AUTHENTICATED_USERS.id()); + assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTH_USERS.type()); + assertEquals(null, ALL_AUTH_USERS.id()); assertEquals(Identity.Type.USER, USER.type()); assertEquals("abc@gmail.com", USER.id()); assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type()); From 12ae596092e8d4306ebf8a8d1ba6e1a6bdf50ce2 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 19 Feb 2016 07:46:43 -0800 Subject: [PATCH 119/663] Update version for release --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3463f40b52..bc5e9c78ba 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -10,7 +10,7 @@ com.google.gcloud gcloud-java-pom - 0.1.4-SNAPSHOT + 0.1.4 gcloud-java-core From 51ac60a7ef9fed37e89e842498df8e3a4627b01c Mon Sep 17 00:00:00 2001 From: travis-ci Date: Fri, 19 Feb 2016 16:22:46 +0000 Subject: [PATCH 120/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index b7e5e05b6a..bc9463b9cc 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.1.3 + 0.1.4 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:0.1.3' +compile 'com.google.gcloud:gcloud-java-core:0.1.4' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.3" +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.4" ``` Troubleshooting From faef6be212119b54c342d54fa1656617226de6da Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 19 Feb 2016 08:38:20 -0800 Subject: [PATCH 121/663] Update version to 0.1.5-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index bc5e9c78ba..d07a567b7e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -10,7 +10,7 @@ com.google.gcloud gcloud-java-pom - 0.1.4 + 0.1.5-SNAPSHOT gcloud-java-core From 33cd8ab59fcfb3c74b30b830f797ebfceeb7d2d2 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 19 Feb 2016 20:08:22 -0800 Subject: [PATCH 122/663] Make BaseIamPolicy in core and a subclass in Resource Manager --- .../{IamPolicy.java => BaseIamPolicy.java} | 245 ++++-------------- .../com/google/gcloud/BaseIamPolicyTest.java | 50 ++++ .../java/com/google/gcloud/IamPolicyTest.java | 105 -------- .../com/google/gcloud/SerializationTest.java | 49 ---- 4 files changed, 101 insertions(+), 348 deletions(-) rename google-cloud-core/src/main/java/com/google/gcloud/{IamPolicy.java => BaseIamPolicy.java} (50%) create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/BaseIamPolicyTest.java delete mode 100644 google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java delete mode 100644 google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseIamPolicy.java similarity index 50% rename from google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java rename to google-cloud-core/src/main/java/com/google/gcloud/BaseIamPolicy.java index a16ab790b3..bc0aed43b9 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseIamPolicy.java @@ -21,29 +21,28 @@ import com.google.common.collect.ImmutableList; import java.io.Serializable; -import java.util.Arrays; -import java.util.LinkedList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; /** - * An Identity and Access Management (IAM) policy. It is used to specify access control policies for - * Cloud Platform resources. A Policy consists of a list of ACLs (also known as bindings in Cloud - * IAM documentation). An ACL binds a list of identities to a role, where the identities can be user - * accounts, Google groups, Google domains, and service accounts. A role is a named list of - * permissions defined by IAM. + * Base class for Identity and Access Management (IAM) policies. IAM policies are used to specify + * access settings for Cloud Platform resources. A Policy consists of a list of bindings. An binding + * assigns a list of identities to a role, where the identities can be user accounts, Google groups, + * Google domains, and service accounts. A role is a named list of permissions defined by IAM. * * @see Policy */ -public class IamPolicy implements Serializable { +public abstract class BaseIamPolicy implements Serializable { - static final long serialVersionUID = 1114489978726897720L; + private static final long serialVersionUID = 1114489978726897720L; - private final List acls; + private final Map> bindings; private final String etag; private final int version; - public static class Identity implements Serializable { + public static final class Identity implements Serializable { private static final long serialVersionUID = 30811617560110848L; @@ -85,7 +84,7 @@ public enum Type { DOMAIN } - Identity(Type type, String id) { + private Identity(Type type, String id) { this.type = type; this.id = id; } @@ -178,177 +177,38 @@ public boolean equals(Object obj) { } } - /** - * An ACL binds a list of identities to a role, where the identities can be user accounts, Google - * groups, Google domains, and service accounts. A role is a named list of permissions defined by - * IAM. - * - * @see Binding - */ - public static class Acl implements Serializable { - - private static final long serialVersionUID = 3954282899483745158L; - - private final List identities; - private final String role; - - /** - * An ACL builder. - */ - public static class Builder { - private final List members = new LinkedList<>(); - private String role; - - Builder(String role) { - this.role = role; - } - - /** - * Sets the role associated with this ACL. - */ - public Builder role(String role) { - this.role = role; - return this; - } - - /** - * Replaces the builder's list of identities with the given list. - */ - public Builder identities(List identities) { - this.members.clear(); - this.members.addAll(identities); - return this; - } - - /** - * Adds one or more identities to the list of identities associated with the ACL. - */ - public Builder addIdentity(Identity first, Identity... others) { - members.add(first); - members.addAll(Arrays.asList(others)); - return this; - } - - /** - * Removes the specified identity from the ACL. - */ - public Builder removeIdentity(Identity identity) { - members.remove(identity); - return this; - } - - public Acl build() { - return new Acl(this); - } - } - - Acl(Builder builder) { - identities = ImmutableList.copyOf(checkNotNull(builder.members)); - role = checkNotNull(builder.role); - } - - /** - * Returns the list of identities associated with this ACL. - */ - public List identities() { - return identities; - } - - /** - * Returns the role associated with this ACL. - */ - public String role() { - return role; - } - - /** - * Returns an ACL builder for the specific role type. - * - * @param role string representing the role, without the "roles/" prefix. An example of a valid - * legacy role is "viewer". An example of a valid service-specific role is - * "pubsub.publisher". - */ - public static Builder builder(String role) { - return new Builder(role); - } - - /** - * Returns an ACL for the role type and list of identities provided. - * - * @param role string representing the role, without the "roles/" prefix. An example of a valid - * legacy role is "viewer". An example of a valid service-specific role is - * "pubsub.publisher". - * @param members list of identities associated with the role. - */ - public static Acl of(String role, List members) { - return new Acl(new Builder(role).identities(members)); - } - - /** - * Returns an ACL for the role type and identities provided. - * - * @param role string representing the role, without the "roles/" prefix. An example of a valid - * legacy role is "viewer". An example of a valid service-specific role is - * "pubsub.publisher". - * @param first identity associated with the role. - * @param others any other identities associated with the role. - */ - public static Acl of(String role, Identity first, Identity... others) { - return new Acl(new Builder(role).addIdentity(first, others)); - } - - public Builder toBuilder() { - return new Builder(role).identities(identities); - } - - @Override - public int hashCode() { - return Objects.hash(identities, role); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Acl)) { - return false; - } - Acl other = (Acl) obj; - return Objects.equals(identities, other.identities()) && Objects.equals(role, other.role()); - } - } - /** * Builder for an IAM Policy. */ - public static class Builder { + protected abstract static class BaseBuilder> { - private final List acls = new LinkedList<>(); + private final Map> bindings = new HashMap<>(); private String etag; private int version; /** - * Replaces the builder's list of ACLs with the given list of ACLs. + * Replaces the builder's list of bindings with the given list of bindings. */ - public Builder acls(List acls) { - this.acls.clear(); - this.acls.addAll(acls); - return this; + public B bindings(Map> bindings) { + this.bindings.clear(); + this.bindings.putAll(bindings); + return self(); } /** - * Adds one or more ACLs to the policy. + * Adds one or more bindings to the policy. */ - public Builder addAcl(Acl first, Acl... others) { - acls.add(first); - acls.addAll(Arrays.asList(others)); - return this; + public B addBinding(R role, List identities) { + bindings.put(role, ImmutableList.copyOf(identities)); + return self(); } /** * Removes the specified ACL. */ - public Builder removeAcl(Acl acl) { - acls.remove(acl); - return this; + public B removeBinding(R role) { + bindings.remove(role); + return self(); } /** @@ -362,35 +222,40 @@ public Builder removeAcl(Acl acl) { * applied to the same version of the policy. If no etag is provided in the call to * setIamPolicy, then the existing policy is overwritten blindly. */ - public Builder etag(String etag) { + protected B etag(String etag) { this.etag = etag; - return this; + return self(); } /** - * Sets the version of the policy. The default version is 0. + * Sets the version of the policy. The default version is 0, meaning roles that are in alpha + * (non-legacy) roles are not permitted. If the version is 1, you may use roles other than + * "owner", "editor", and "viewer". */ - public Builder version(int version) { + protected B version(int version) { this.version = version; - return this; + return self(); } - public IamPolicy build() { - return new IamPolicy(this); + @SuppressWarnings("unchecked") + private B self() { + return (B) this; } + + public abstract BaseIamPolicy build(); } - IamPolicy(Builder builder) { - acls = ImmutableList.copyOf(builder.acls); - etag = builder.etag; - version = builder.version; + protected BaseIamPolicy(BaseBuilder> builder) { + this.bindings = builder.bindings; + this.etag = builder.etag; + this.version = builder.version; } /** * The list of ACLs specified in the policy. */ - public List acls() { - return acls; + public Map> bindings() { + return bindings; } /** @@ -415,26 +280,18 @@ public int version() { return version; } - @Override - public int hashCode() { - return Objects.hash(acls, etag, version); + public int baseHashCode() { + return Objects.hash(bindings, etag, version); } - @Override - public boolean equals(Object obj) { - if (!(obj instanceof IamPolicy)) { + public boolean baseEquals(Object obj) { + if (!(obj instanceof BaseIamPolicy)) { return false; } - IamPolicy other = (IamPolicy) obj; - return Objects.equals(acls, other.acls()) && Objects.equals(etag, other.etag()) + @SuppressWarnings("rawtypes") + BaseIamPolicy other = (BaseIamPolicy) obj; + return Objects.equals(bindings, other.bindings()) + && Objects.equals(etag, other.etag()) && Objects.equals(version, other.version()); } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder().acls(acls).etag(etag).version(version); - } } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseIamPolicyTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseIamPolicyTest.java new file mode 100644 index 0000000000..0c26bc8068 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/BaseIamPolicyTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static org.junit.Assert.assertEquals; + +import com.google.gcloud.BaseIamPolicy.Identity; + +import org.junit.Test; + +public class BaseIamPolicyTest { + + private static final Identity ALL_USERS = Identity.allUsers(); + private static final Identity ALL_AUTH_USERS = Identity.allAuthenticatedUsers(); + private static final Identity USER = Identity.user("abc@gmail.com"); + private static final Identity SERVICE_ACCOUNT = + Identity.serviceAccount("service-account@gmail.com"); + private static final Identity GROUP = Identity.group("group@gmail.com"); + private static final Identity DOMAIN = Identity.domain("google.com"); + + @Test + public void testIdentityOf() { + assertEquals(Identity.Type.ALL_USERS, ALL_USERS.type()); + assertEquals(null, ALL_USERS.id()); + assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTH_USERS.type()); + assertEquals(null, ALL_AUTH_USERS.id()); + assertEquals(Identity.Type.USER, USER.type()); + assertEquals("abc@gmail.com", USER.id()); + assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type()); + assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.id()); + assertEquals(Identity.Type.GROUP, GROUP.type()); + assertEquals("group@gmail.com", GROUP.id()); + assertEquals(Identity.Type.DOMAIN, DOMAIN.type()); + assertEquals("google.com", DOMAIN.id()); + } +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java deleted file mode 100644 index 0d4e9fbfa6..0000000000 --- a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.gcloud; - -import static org.junit.Assert.assertEquals; - -import com.google.common.collect.ImmutableList; -import com.google.gcloud.IamPolicy.Acl; -import com.google.gcloud.IamPolicy.Identity; - -import org.junit.Test; - -public class IamPolicyTest { - - private static final Identity ALL_USERS = Identity.allUsers(); - private static final Identity ALL_AUTH_USERS = Identity.allAuthenticatedUsers(); - private static final Identity USER = Identity.user("abc@gmail.com"); - private static final Identity SERVICE_ACCOUNT = - Identity.serviceAccount("service-account@gmail.com"); - private static final Identity GROUP = Identity.group("group@gmail.com"); - private static final Identity DOMAIN = Identity.domain("google.com"); - private static final Acl ACL1 = Acl.of("viewer", USER, SERVICE_ACCOUNT, ALL_USERS); - private static final Acl ACL2 = Acl.of("editor", ALL_AUTH_USERS, GROUP, DOMAIN); - private static final IamPolicy FULL_POLICY = - IamPolicy.builder().addAcl(ACL1, ACL2).etag("etag").version(1).build(); - private static final IamPolicy SIMPLE_POLICY = IamPolicy.builder().addAcl(ACL1, ACL2).build(); - - @Test - public void testIdentityOf() { - assertEquals(Identity.Type.ALL_USERS, ALL_USERS.type()); - assertEquals(null, ALL_USERS.id()); - assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTH_USERS.type()); - assertEquals(null, ALL_AUTH_USERS.id()); - assertEquals(Identity.Type.USER, USER.type()); - assertEquals("abc@gmail.com", USER.id()); - assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type()); - assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.id()); - assertEquals(Identity.Type.GROUP, GROUP.type()); - assertEquals("group@gmail.com", GROUP.id()); - assertEquals(Identity.Type.DOMAIN, DOMAIN.type()); - assertEquals("google.com", DOMAIN.id()); - } - - @Test - public void testAclBuilder() { - Acl acl = Acl.builder("owner").addIdentity(USER, GROUP).build(); - assertEquals("owner", acl.role()); - assertEquals(ImmutableList.of(USER, GROUP), acl.identities()); - acl = acl.toBuilder().role("viewer").removeIdentity(GROUP).build(); - assertEquals("viewer", acl.role()); - assertEquals(ImmutableList.of(USER), acl.identities()); - acl = acl.toBuilder().identities(ImmutableList.of(SERVICE_ACCOUNT)).build(); - assertEquals("viewer", acl.role()); - assertEquals(ImmutableList.of(SERVICE_ACCOUNT), acl.identities()); - } - - @Test - public void testAclOf() { - assertEquals("viewer", ACL1.role()); - assertEquals(ImmutableList.of(USER, SERVICE_ACCOUNT, ALL_USERS), ACL1.identities()); - Acl aclFromList = Acl.of("editor", ImmutableList.of(USER, SERVICE_ACCOUNT)); - assertEquals("editor", aclFromList.role()); - assertEquals(ImmutableList.of(USER, SERVICE_ACCOUNT), aclFromList.identities()); - } - - @Test - public void testAclToBuilder() { - assertEquals(ACL1, ACL1.toBuilder().build()); - } - - @Test - public void testIamPolicyBuilder() { - assertEquals(ImmutableList.of(ACL1, ACL2), FULL_POLICY.acls()); - assertEquals("etag", FULL_POLICY.etag()); - assertEquals(1, FULL_POLICY.version()); - IamPolicy policy = FULL_POLICY.toBuilder().acls(ImmutableList.of(ACL2)).build(); - assertEquals(ImmutableList.of(ACL2), policy.acls()); - assertEquals("etag", policy.etag()); - assertEquals(1, policy.version()); - policy = SIMPLE_POLICY.toBuilder().removeAcl(ACL2).build(); - assertEquals(ImmutableList.of(ACL1), policy.acls()); - assertEquals(null, policy.etag()); - assertEquals(0, policy.version()); - } - - @Test - public void testIamPolicyToBuilder() { - assertEquals(FULL_POLICY, FULL_POLICY.toBuilder().build()); - assertEquals(SIMPLE_POLICY, SIMPLE_POLICY.toBuilder().build()); - } -} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java deleted file mode 100644 index b529b2c09f..0000000000 --- a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.google.gcloud; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; - -import com.google.common.collect.ImmutableList; -import com.google.gcloud.IamPolicy.Acl; -import com.google.gcloud.IamPolicy.Identity; - -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -public class SerializationTest { - - private static final Identity IDENTITY = Identity.user("abc@gmail.com"); - private static final Acl ACL = Acl.of("viewer", ImmutableList.of(IDENTITY)); - private static final IamPolicy POLICY = - IamPolicy.builder().acls(ImmutableList.of(ACL)).etag("etag").version(1).build(); - - @Test - public void testModelAndRequests() throws Exception { - Serializable[] objects = {IDENTITY, ACL, POLICY}; - for (Serializable obj : objects) { - Object copy = serializeAndDeserialize(obj); - assertEquals(obj, obj); - assertEquals(obj, copy); - assertNotSame(obj, copy); - assertEquals(copy, copy); - } - } - - @SuppressWarnings("unchecked") - private T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundException { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - try (ObjectOutputStream output = new ObjectOutputStream(bytes)) { - output.writeObject(obj); - } - try (ObjectInputStream input = - new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) { - return (T) input.readObject(); - } - } -} From fcf5e35bd5d2a936f5e9aa8ec4caf7e162b8dec4 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 22 Feb 2016 09:51:53 -0800 Subject: [PATCH 123/663] Fix equals, javadoc, bindings representation, and address other comments. --- .../java/com/google/gcloud/BaseIamPolicy.java | 297 ------------------ .../java/com/google/gcloud/IamPolicy.java | 213 +++++++++++++ .../main/java/com/google/gcloud/Identity.java | 208 ++++++++++++ .../com/google/gcloud/BaseIamPolicyTest.java | 50 --- .../java/com/google/gcloud/IamPolicyTest.java | 173 ++++++++++ .../java/com/google/gcloud/IdentityTest.java | 110 +++++++ 6 files changed, 704 insertions(+), 347 deletions(-) delete mode 100644 google-cloud-core/src/main/java/com/google/gcloud/BaseIamPolicy.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/Identity.java delete mode 100644 google-cloud-core/src/test/java/com/google/gcloud/BaseIamPolicyTest.java create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseIamPolicy.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseIamPolicy.java deleted file mode 100644 index bc0aed43b9..0000000000 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseIamPolicy.java +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.gcloud; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.collect.ImmutableList; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * Base class for Identity and Access Management (IAM) policies. IAM policies are used to specify - * access settings for Cloud Platform resources. A Policy consists of a list of bindings. An binding - * assigns a list of identities to a role, where the identities can be user accounts, Google groups, - * Google domains, and service accounts. A role is a named list of permissions defined by IAM. - * - * @see Policy - */ -public abstract class BaseIamPolicy implements Serializable { - - private static final long serialVersionUID = 1114489978726897720L; - - private final Map> bindings; - private final String etag; - private final int version; - - public static final class Identity implements Serializable { - - private static final long serialVersionUID = 30811617560110848L; - - private final Type type; - private final String id; - - /** - * The types of IAM identities. - */ - public enum Type { - /** - * Represents anyone who is on the internet; with or without a Google account. - */ - ALL_USERS, - - /** - * Represents anyone who is authenticated with a Google account or a service account. - */ - ALL_AUTHENTICATED_USERS, - - /** - * Represents a specific Google account. - */ - USER, - - /** - * Represents a service account. - */ - SERVICE_ACCOUNT, - - /** - * Represents a Google group. - */ - GROUP, - - /** - * Represents all the users of a Google Apps domain name. - */ - DOMAIN - } - - private Identity(Type type, String id) { - this.type = type; - this.id = id; - } - - public Type type() { - return type; - } - - /** - * Returns the string identifier for this identity. The id corresponds to: - *

    - *
  • email address (for identities of type {@code USER}, {@code SERVICE_ACCOUNT}, and - * {@code GROUP}) - *
  • domain (for identities of type {@code DOMAIN}) - *
  • null (for identities of type {@code ALL_USERS} and {@code ALL_AUTHENTICATED_USERS}) - *
- */ - public String id() { - return id; - } - - /** - * Returns a new identity representing anyone who is on the internet; with or without a Google - * account. - */ - public static Identity allUsers() { - return new Identity(Type.ALL_USERS, null); - } - - /** - * Returns a new identity representing anyone who is authenticated with a Google account or a - * service account. - */ - public static Identity allAuthenticatedUsers() { - return new Identity(Type.ALL_AUTHENTICATED_USERS, null); - } - - /** - * Returns a new user identity. - * - * @param email An email address that represents a specific Google account. For example, - * alice@gmail.com or joe@example.com. - */ - public static Identity user(String email) { - return new Identity(Type.USER, checkNotNull(email)); - } - - /** - * Returns a new service account identity. - * - * @param email An email address that represents a service account. For example, - * my-other-app@appspot.gserviceaccount.com. - */ - public static Identity serviceAccount(String email) { - return new Identity(Type.SERVICE_ACCOUNT, checkNotNull(email)); - } - - /** - * Returns a new group identity. - * - * @param email An email address that represents a Google group. For example, - * admins@example.com. - */ - public static Identity group(String email) { - return new Identity(Type.GROUP, checkNotNull(email)); - } - - /** - * Returns a new domain identity. - * - * @param domain A Google Apps domain name that represents all the users of that domain. For - * example, google.com or example.com. - */ - public static Identity domain(String domain) { - return new Identity(Type.DOMAIN, checkNotNull(domain)); - } - - @Override - public int hashCode() { - return Objects.hash(id, type); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Identity)) { - return false; - } - Identity other = (Identity) obj; - return Objects.equals(id, other.id()) && Objects.equals(type, other.type()); - } - } - - /** - * Builder for an IAM Policy. - */ - protected abstract static class BaseBuilder> { - - private final Map> bindings = new HashMap<>(); - private String etag; - private int version; - - /** - * Replaces the builder's list of bindings with the given list of bindings. - */ - public B bindings(Map> bindings) { - this.bindings.clear(); - this.bindings.putAll(bindings); - return self(); - } - - /** - * Adds one or more bindings to the policy. - */ - public B addBinding(R role, List identities) { - bindings.put(role, ImmutableList.copyOf(identities)); - return self(); - } - - /** - * Removes the specified ACL. - */ - public B removeBinding(R role) { - bindings.remove(role); - return self(); - } - - /** - * Sets the policy's etag. - * - *

Etags are used for optimistic concurrency control as a way to help prevent simultaneous - * updates of a policy from overwriting each other. It is strongly suggested that systems make - * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid - * race conditions. An etag is returned in the response to getIamPolicy, and systems are - * expected to put that etag in the request to setIamPolicy to ensure that their change will be - * applied to the same version of the policy. If no etag is provided in the call to - * setIamPolicy, then the existing policy is overwritten blindly. - */ - protected B etag(String etag) { - this.etag = etag; - return self(); - } - - /** - * Sets the version of the policy. The default version is 0, meaning roles that are in alpha - * (non-legacy) roles are not permitted. If the version is 1, you may use roles other than - * "owner", "editor", and "viewer". - */ - protected B version(int version) { - this.version = version; - return self(); - } - - @SuppressWarnings("unchecked") - private B self() { - return (B) this; - } - - public abstract BaseIamPolicy build(); - } - - protected BaseIamPolicy(BaseBuilder> builder) { - this.bindings = builder.bindings; - this.etag = builder.etag; - this.version = builder.version; - } - - /** - * The list of ACLs specified in the policy. - */ - public Map> bindings() { - return bindings; - } - - /** - * The policy's etag. - * - *

Etags are used for optimistic concurrency control as a way to help prevent simultaneous - * updates of a policy from overwriting each other. It is strongly suggested that systems make - * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid - * race conditions. An etag is returned in the response to getIamPolicy, and systems are - * expected to put that etag in the request to setIamPolicy to ensure that their change will be - * applied to the same version of the policy. If no etag is provided in the call to - * setIamPolicy, then the existing policy is overwritten blindly. - */ - public String etag() { - return etag; - } - - /** - * The version of the policy. The default version is 0. - */ - public int version() { - return version; - } - - public int baseHashCode() { - return Objects.hash(bindings, etag, version); - } - - public boolean baseEquals(Object obj) { - if (!(obj instanceof BaseIamPolicy)) { - return false; - } - @SuppressWarnings("rawtypes") - BaseIamPolicy other = (BaseIamPolicy) obj; - return Objects.equals(bindings, other.bindings()) - && Objects.equals(etag, other.etag()) - && Objects.equals(version, other.version()); - } -} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java new file mode 100644 index 0000000000..ed9dcf9503 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java @@ -0,0 +1,213 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +/** + * Base class for Identity and Access Management (IAM) policies. IAM policies are used to specify + * access settings for Cloud Platform resources. A policy is a map of bindings. A binding assigns + * a set of identities to a role, where the identities can be user accounts, Google groups, Google + * domains, and service accounts. A role is a named list of permissions defined by IAM. + * + * @param the data type of roles (should be serializable) + * @see Policy + */ +public abstract class IamPolicy implements Serializable { + + private static final long serialVersionUID = 1114489978726897720L; + + private final Map> bindings; + private final String etag; + private final Integer version; + + /** + * Builder for an IAM Policy. + * + * @param the data type of roles + * @param the subclass extending this abstract builder + */ + public abstract static class Builder> { + + private final Map> bindings = new HashMap<>(); + private String etag; + private Integer version; + + protected Builder() {} + + /** + * Replaces the builder's map of bindings with the given map of bindings. + */ + public final B bindings(Map> bindings) { + this.bindings.clear(); + for (Map.Entry> binding : bindings.entrySet()) { + this.bindings.put(binding.getKey(), new HashSet(binding.getValue())); + } + return self(); + } + + /** + * Adds a binding to the policy. + */ + public final B addBinding(R role, Set identities) { + checkArgument(!bindings.containsKey(role), + "The policy already contains a binding with the role " + role.toString()); + bindings.put(role, new HashSet(identities)); + return self(); + } + + /** + * Adds a binding to the policy. + */ + public final B addBinding(R role, Identity first, Identity... others) { + checkArgument(!bindings.containsKey(role), + "The policy already contains a binding with the role " + role.toString()); + HashSet identities = new HashSet<>(); + identities.add(first); + identities.addAll(Arrays.asList(others)); + bindings.put(role, identities); + return self(); + } + + /** + * Removes the binding associated with the specified role. + */ + public final B removeBinding(R role) { + bindings.remove(role); + return self(); + } + + /** + * Adds one or more identities to an existing binding. + */ + public final B addIdentity(R role, Identity first, Identity... others) { + Set identities = bindings.get(role); + identities.add(first); + identities.addAll(Arrays.asList(others)); + return self(); + } + + /** + * Removes one or more identities from an existing binding. + */ + public final B removeIdentity(R role, Identity first, Identity... others) { + bindings.get(role).remove(first); + bindings.get(role).removeAll(Arrays.asList(others)); + return self(); + } + + /** + * Sets the policy's etag. + * + *

Etags are used for optimistic concurrency control as a way to help prevent simultaneous + * updates of a policy from overwriting each other. It is strongly suggested that systems make + * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid + * race conditions. An etag is returned in the response to getIamPolicy, and systems are + * expected to put that etag in the request to setIamPolicy to ensure that their change will be + * applied to the same version of the policy. If no etag is provided in the call to + * setIamPolicy, then the existing policy is overwritten blindly. + */ + protected final B etag(String etag) { + this.etag = etag; + return self(); + } + + /** + * Sets the version of the policy. The default version is 0, meaning only the "owner", "editor", + * and "viewer" roles are permitted. If the version is 1, you may also use other roles. + */ + protected final B version(Integer version) { + this.version = version; + return self(); + } + + @SuppressWarnings("unchecked") + private B self() { + return (B) this; + } + + public abstract IamPolicy build(); + } + + protected IamPolicy(Builder> builder) { + ImmutableMap.Builder> bindingsBuilder = ImmutableMap.builder(); + for (Map.Entry> binding : builder.bindings.entrySet()) { + bindingsBuilder.put(binding.getKey(), ImmutableSet.copyOf(binding.getValue())); + } + this.bindings = bindingsBuilder.build(); + this.etag = builder.etag; + this.version = builder.version; + } + + /** + * The map of bindings that comprises the policy. + */ + public Map> bindings() { + return bindings; + } + + /** + * The policy's etag. + * + *

Etags are used for optimistic concurrency control as a way to help prevent simultaneous + * updates of a policy from overwriting each other. It is strongly suggested that systems make + * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid + * race conditions. An etag is returned in the response to getIamPolicy, and systems are + * expected to put that etag in the request to setIamPolicy to ensure that their change will be + * applied to the same version of the policy. If no etag is provided in the call to + * setIamPolicy, then the existing policy is overwritten blindly. + */ + public String etag() { + return etag; + } + + /** + * Sets the version of the policy. The default version is 0, meaning only the "owner", "editor", + * and "viewer" roles are permitted. If the version is 1, you may also use other roles. + */ + public Integer version() { + return version; + } + + @Override + public final int hashCode() { + return Objects.hash(getClass(), bindings, etag, version); + } + + @Override + public final boolean equals(Object obj) { + if (obj == null || !getClass().equals(obj.getClass())) { + return false; + } + @SuppressWarnings("rawtypes") + IamPolicy other = (IamPolicy) obj; + return Objects.equals(bindings, other.bindings()) + && Objects.equals(etag, other.etag()) + && Objects.equals(version, other.version()); + } +} diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Identity.java b/google-cloud-core/src/main/java/com/google/gcloud/Identity.java new file mode 100644 index 0000000000..0513916cc8 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/Identity.java @@ -0,0 +1,208 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.Serializable; +import java.util.Objects; + +/** + * An identity in an {@link IamPolicy}. + */ +public final class Identity implements Serializable { + + private static final long serialVersionUID = -8181841964597657446L; + + private final Type type; + private final String id; + + /** + * The types of IAM identities. + */ + public enum Type { + + /** + * Represents anyone who is on the internet; with or without a Google account. + */ + ALL_USERS, + + /** + * Represents anyone who is authenticated with a Google account or a service account. + */ + ALL_AUTHENTICATED_USERS, + + /** + * Represents a specific Google account. + */ + USER, + + /** + * Represents a service account. + */ + SERVICE_ACCOUNT, + + /** + * Represents a Google group. + */ + GROUP, + + /** + * Represents all the users of a Google Apps domain name. + */ + DOMAIN + } + + private Identity(Type type, String id) { + this.type = type; + this.id = id; + } + + public Type type() { + return type; + } + + /** + * Returns the string identifier for this identity. The id corresponds to: + *

    + *
  • email address (for identities of type {@code USER}, {@code SERVICE_ACCOUNT}, and + * {@code GROUP}) + *
  • domain (for identities of type {@code DOMAIN}) + *
  • null (for identities of type {@code ALL_USERS} and {@code ALL_AUTHENTICATED_USERS}) + *
+ */ + public String id() { + return id; + } + + /** + * Returns a new identity representing anyone who is on the internet; with or without a Google + * account. + */ + public static Identity allUsers() { + return new Identity(Type.ALL_USERS, null); + } + + /** + * Returns a new identity representing anyone who is authenticated with a Google account or a + * service account. + */ + public static Identity allAuthenticatedUsers() { + return new Identity(Type.ALL_AUTHENTICATED_USERS, null); + } + + /** + * Returns a new user identity. + * + * @param email An email address that represents a specific Google account. For example, + * alice@gmail.com or joe@example.com. + */ + public static Identity user(String email) { + return new Identity(Type.USER, checkNotNull(email)); + } + + /** + * Returns a new service account identity. + * + * @param email An email address that represents a service account. For example, + * my-other-app@appspot.gserviceaccount.com. + */ + public static Identity serviceAccount(String email) { + return new Identity(Type.SERVICE_ACCOUNT, checkNotNull(email)); + } + + /** + * Returns a new group identity. + * + * @param email An email address that represents a Google group. For example, + * admins@example.com. + */ + public static Identity group(String email) { + return new Identity(Type.GROUP, checkNotNull(email)); + } + + /** + * Returns a new domain identity. + * + * @param domain A Google Apps domain name that represents all the users of that domain. For + * example, google.com or example.com. + */ + public static Identity domain(String domain) { + return new Identity(Type.DOMAIN, checkNotNull(domain)); + } + + @Override + public int hashCode() { + return Objects.hash(id, type); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Identity)) { + return false; + } + Identity other = (Identity) obj; + return Objects.equals(id, other.id()) && Objects.equals(type, other.type()); + } + + /** + * Returns the string value associated with the identity. Used primarily for converting from + * {@code Identity} objects to strings for protobuf-generated policies. + */ + public String strValue() { + switch (type) { + case ALL_USERS: + return "allUsers"; + case ALL_AUTHENTICATED_USERS: + return "allAuthenticatedUsers"; + case USER: + return "user:" + id; + case SERVICE_ACCOUNT: + return "serviceAccount:" + id; + case GROUP: + return "group:" + id; + case DOMAIN: + return "domain:" + id; + default: + throw new IllegalArgumentException("Unexpected identity type: " + type); + } + } + + /** + * Converts a string to an {@code Identity}. Used primarily for converting protobuf-generated + * policy identities to {@code Identity} objects. + */ + public static Identity valueOf(String identityStr) { + String[] info = identityStr.split(":"); + switch (info[0]) { + case "allUsers": + return Identity.allUsers(); + case "allAuthenticatedUsers": + return Identity.allAuthenticatedUsers(); + case "user": + return Identity.user(info[1]); + case "serviceAccount": + return Identity.serviceAccount(info[1]); + case "group": + return Identity.group(info[1]); + case "domain": + return Identity.domain(info[1]); + default: + throw new IllegalArgumentException("Unexpected identity type: " + info[0]); + } + } +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseIamPolicyTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseIamPolicyTest.java deleted file mode 100644 index 0c26bc8068..0000000000 --- a/google-cloud-core/src/test/java/com/google/gcloud/BaseIamPolicyTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.gcloud; - -import static org.junit.Assert.assertEquals; - -import com.google.gcloud.BaseIamPolicy.Identity; - -import org.junit.Test; - -public class BaseIamPolicyTest { - - private static final Identity ALL_USERS = Identity.allUsers(); - private static final Identity ALL_AUTH_USERS = Identity.allAuthenticatedUsers(); - private static final Identity USER = Identity.user("abc@gmail.com"); - private static final Identity SERVICE_ACCOUNT = - Identity.serviceAccount("service-account@gmail.com"); - private static final Identity GROUP = Identity.group("group@gmail.com"); - private static final Identity DOMAIN = Identity.domain("google.com"); - - @Test - public void testIdentityOf() { - assertEquals(Identity.Type.ALL_USERS, ALL_USERS.type()); - assertEquals(null, ALL_USERS.id()); - assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTH_USERS.type()); - assertEquals(null, ALL_AUTH_USERS.id()); - assertEquals(Identity.Type.USER, USER.type()); - assertEquals("abc@gmail.com", USER.id()); - assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type()); - assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.id()); - assertEquals(Identity.Type.GROUP, GROUP.type()); - assertEquals("group@gmail.com", GROUP.id()); - assertEquals(Identity.Type.DOMAIN, DOMAIN.type()); - assertEquals("google.com", DOMAIN.id()); - } -} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java new file mode 100644 index 0000000000..b77b5e2df7 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java @@ -0,0 +1,173 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +import org.junit.Test; + +import java.util.Map; +import java.util.Set; + +public class IamPolicyTest { + + private static final Identity ALL_USERS = Identity.allUsers(); + private static final Identity ALL_AUTH_USERS = Identity.allAuthenticatedUsers(); + private static final Identity USER = Identity.user("abc@gmail.com"); + private static final Identity SERVICE_ACCOUNT = + Identity.serviceAccount("service-account@gmail.com"); + private static final Identity GROUP = Identity.group("group@gmail.com"); + private static final Identity DOMAIN = Identity.domain("google.com"); + private static final Map> BINDINGS = ImmutableMap.of( + "viewer", + ImmutableSet.of(USER, SERVICE_ACCOUNT, ALL_USERS), + "editor", + ImmutableSet.of(ALL_AUTH_USERS, GROUP, DOMAIN)); + private static final PolicyImpl SIMPLE_POLICY = PolicyImpl.builder() + .addBinding("viewer", ImmutableSet.of(USER, SERVICE_ACCOUNT, ALL_USERS)) + .addBinding("editor", ImmutableSet.of(ALL_AUTH_USERS, GROUP, DOMAIN)) + .build(); + private static final PolicyImpl FULL_POLICY = + new PolicyImpl.Builder(SIMPLE_POLICY.bindings(), "etag", 1).build(); + + static class PolicyImpl extends IamPolicy { + + static class Builder extends IamPolicy.Builder { + + private Builder() {} + + private Builder(Map> bindings, String etag, Integer version) { + bindings(bindings).etag(etag).version(version); + } + + @Override + public PolicyImpl build() { + return new PolicyImpl(this); + } + } + + PolicyImpl(Builder builder) { + super(builder); + } + + Builder toBuilder() { + return new Builder(bindings(), etag(), version()); + } + + static Builder builder() { + return new Builder(); + } + } + + @Test + public void testBuilder() { + assertEquals(BINDINGS, FULL_POLICY.bindings()); + assertEquals("etag", FULL_POLICY.etag()); + assertEquals(1, FULL_POLICY.version().intValue()); + Map> editorBinding = + ImmutableMap.>builder().put("editor", BINDINGS.get("editor")).build(); + PolicyImpl policy = FULL_POLICY.toBuilder().bindings(editorBinding).build(); + assertEquals(editorBinding, policy.bindings()); + assertEquals("etag", policy.etag()); + assertEquals(1, policy.version().intValue()); + policy = SIMPLE_POLICY.toBuilder().removeBinding("editor").build(); + assertEquals(ImmutableMap.of("viewer", BINDINGS.get("viewer")), policy.bindings()); + assertEquals(null, policy.etag()); + assertEquals(null, policy.version()); + policy = policy.toBuilder() + .removeIdentity("viewer", USER, ALL_USERS) + .addIdentity("viewer", DOMAIN, GROUP) + .build(); + assertEquals(ImmutableMap.of("viewer", ImmutableSet.of(SERVICE_ACCOUNT, DOMAIN, GROUP)), + policy.bindings()); + assertEquals(null, policy.etag()); + assertEquals(null, policy.version()); + policy = PolicyImpl.builder().addBinding("owner", USER, SERVICE_ACCOUNT).build(); + assertEquals( + ImmutableMap.of("owner", ImmutableSet.of(USER, SERVICE_ACCOUNT)), policy.bindings()); + assertEquals(null, policy.etag()); + assertEquals(null, policy.version()); + try { + SIMPLE_POLICY.toBuilder().addBinding("viewer", USER); + fail("Should have failed due to duplicate role."); + } catch (IllegalArgumentException e) { + assertEquals("The policy already contains a binding with the role viewer", e.getMessage()); + } + try { + SIMPLE_POLICY.toBuilder().addBinding("editor", ImmutableSet.of(USER)); + fail("Should have failed due to duplicate role."); + } catch (IllegalArgumentException e) { + assertEquals("The policy already contains a binding with the role editor", e.getMessage()); + } + } + + @Test + public void testEqualsHashCode() { + assertNotEquals(FULL_POLICY, null); + PolicyImpl emptyPolicy = PolicyImpl.builder().build(); + AnotherPolicyImpl anotherPolicy = new AnotherPolicyImpl.Builder().build(); + assertNotEquals(emptyPolicy, anotherPolicy); + assertNotEquals(emptyPolicy.hashCode(), anotherPolicy.hashCode()); + assertNotEquals(FULL_POLICY, SIMPLE_POLICY); + assertNotEquals(FULL_POLICY.hashCode(), SIMPLE_POLICY.hashCode()); + PolicyImpl copy = SIMPLE_POLICY.toBuilder().build(); + assertEquals(SIMPLE_POLICY, copy); + assertEquals(SIMPLE_POLICY.hashCode(), copy.hashCode()); + } + + @Test + public void testBindings() { + assertTrue(PolicyImpl.builder().build().bindings().isEmpty()); + assertEquals(BINDINGS, SIMPLE_POLICY.bindings()); + } + + @Test + public void testEtag() { + assertNull(SIMPLE_POLICY.etag()); + assertEquals("etag", FULL_POLICY.etag()); + } + + @Test + public void testVersion() { + assertNull(SIMPLE_POLICY.version()); + assertEquals(null, SIMPLE_POLICY.version()); + } + + static class AnotherPolicyImpl extends IamPolicy { + + static class Builder extends IamPolicy.Builder { + + private Builder() {} + + @Override + public AnotherPolicyImpl build() { + return new AnotherPolicyImpl(this); + } + } + + AnotherPolicyImpl(Builder builder) { + super(builder); + } + } +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java new file mode 100644 index 0000000000..7abbc98521 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java @@ -0,0 +1,110 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import org.junit.Test; + +public class IdentityTest { + + private static final Identity ALL_USERS = Identity.allUsers(); + private static final Identity ALL_AUTH_USERS = Identity.allAuthenticatedUsers(); + private static final Identity USER = Identity.user("abc@gmail.com"); + private static final Identity SERVICE_ACCOUNT = + Identity.serviceAccount("service-account@gmail.com"); + private static final Identity GROUP = Identity.group("group@gmail.com"); + private static final Identity DOMAIN = Identity.domain("google.com"); + + @Test + public void testAllUsers() { + assertEquals(Identity.Type.ALL_USERS, ALL_USERS.type()); + assertNull(ALL_USERS.id()); + } + + @Test + public void testAllAuthenticatedUsers() { + assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTH_USERS.type()); + assertNull(ALL_AUTH_USERS.id()); + } + + @Test + public void testUser() { + assertEquals(Identity.Type.USER, USER.type()); + assertEquals("abc@gmail.com", USER.id()); + try { + Identity.user(null); + fail("Should have thrown exception due to null email address."); + } catch (NullPointerException e) { + // expected + } + } + + @Test + public void testServiceAccount() { + assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type()); + assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.id()); + try { + Identity.serviceAccount(null); + fail("Should have thrown exception due to null email address."); + } catch (NullPointerException e) { + // expected + } + } + + @Test + public void testGroup() { + assertEquals(Identity.Type.GROUP, GROUP.type()); + assertEquals("group@gmail.com", GROUP.id()); + try { + Identity.group(null); + fail("Should have thrown exception due to null email address."); + } catch (NullPointerException e) { + // expected + } + } + + @Test + public void testDomain() { + assertEquals(Identity.Type.DOMAIN, DOMAIN.type()); + assertEquals("google.com", DOMAIN.id()); + try { + Identity.domain(null); + fail("Should have thrown exception due to null domain."); + } catch (NullPointerException e) { + // expected + } + } + + @Test + public void testIdentityToAndFromPb() { + compareIdentities(ALL_USERS, Identity.valueOf(ALL_USERS.strValue())); + compareIdentities(ALL_AUTH_USERS, Identity.valueOf(ALL_AUTH_USERS.strValue())); + compareIdentities(USER, Identity.valueOf(USER.strValue())); + compareIdentities(SERVICE_ACCOUNT, Identity.valueOf(SERVICE_ACCOUNT.strValue())); + compareIdentities(GROUP, Identity.valueOf(GROUP.strValue())); + compareIdentities(DOMAIN, Identity.valueOf(DOMAIN.strValue())); + } + + private void compareIdentities(Identity expected, Identity actual) { + assertEquals(expected, actual); + assertEquals(expected.type(), actual.type()); + assertEquals(expected.id(), actual.id()); + } +} From 6e423df9f845305cfa8346f3ff99a43ba141bf0d Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 25 Feb 2016 17:05:55 +0100 Subject: [PATCH 124/663] validateOpen throws ClosedChannelException in BaseWriteChannel and BlobReadChannel --- .../src/main/java/com/google/gcloud/BaseWriteChannel.java | 5 +++-- .../test/java/com/google/gcloud/BaseWriteChannelTest.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java index e05383a658..1d18a5a27e 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.Serializable; import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; import java.util.Arrays; import java.util.Objects; @@ -114,9 +115,9 @@ private void flush() { } } - private void validateOpen() throws IOException { + private void validateOpen() throws ClosedChannelException { if (!isOpen) { - throw new IOException("stream is closed"); + throw new ClosedChannelException(); } } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java index e49a17b019..6d5306a3bc 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.io.Serializable; import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; import java.util.Arrays; import java.util.Random; @@ -102,8 +103,7 @@ public void testClose() throws IOException { @Test public void testValidateOpen() throws IOException { channel.close(); - thrown.expect(IOException.class); - thrown.expectMessage("stream is closed"); + thrown.expect(ClosedChannelException.class); channel.write(ByteBuffer.allocate(42)); } From 0357e61edf76c6cd635b7850a488ec3a216932fd Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 25 Feb 2016 09:13:01 -0800 Subject: [PATCH 125/663] Document exceptions and satisfy codacy's demands. --- .../java/com/google/gcloud/IamPolicy.java | 15 +++++++ .../java/com/google/gcloud/IdentityTest.java | 45 +++++++++---------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java index ed9dcf9503..73c3e3fec6 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java @@ -58,6 +58,9 @@ public abstract static class Builder> { private String etag; private Integer version; + /** + * Constructor for IAM Policy builder. + */ protected Builder() {} /** @@ -73,6 +76,8 @@ public final B bindings(Map> bindings) { /** * Adds a binding to the policy. + * + * @throws IllegalArgumentException if the policy already contains a binding with the same role */ public final B addBinding(R role, Set identities) { checkArgument(!bindings.containsKey(role), @@ -83,6 +88,8 @@ public final B addBinding(R role, Set identities) { /** * Adds a binding to the policy. + * + * @throws IllegalArgumentException if the policy already contains a binding with the same role */ public final B addBinding(R role, Identity first, Identity... others) { checkArgument(!bindings.containsKey(role), @@ -104,8 +111,12 @@ public final B removeBinding(R role) { /** * Adds one or more identities to an existing binding. + * + * @throws IllegalArgumentException if the policy doesn't contain a binding with the specified + * role */ public final B addIdentity(R role, Identity first, Identity... others) { + checkArgument(bindings.containsKey(role), "The policy doesn't contain the specified role."); Set identities = bindings.get(role); identities.add(first); identities.addAll(Arrays.asList(others)); @@ -114,8 +125,12 @@ public final B addIdentity(R role, Identity first, Identity... others) { /** * Removes one or more identities from an existing binding. + * + * @throws IllegalArgumentException if the policy doesn't contain a binding with the specified + * role */ public final B removeIdentity(R role, Identity first, Identity... others) { + checkArgument(bindings.containsKey(role), "The policy doesn't contain the specified role."); bindings.get(role).remove(first); bindings.get(role).removeAll(Arrays.asList(others)); return self(); diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java index 7abbc98521..828f1c8394 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java @@ -18,7 +18,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; import org.junit.Test; @@ -48,48 +47,44 @@ public void testAllAuthenticatedUsers() { public void testUser() { assertEquals(Identity.Type.USER, USER.type()); assertEquals("abc@gmail.com", USER.id()); - try { - Identity.user(null); - fail("Should have thrown exception due to null email address."); - } catch (NullPointerException e) { - // expected - } + } + + @Test(expected = NullPointerException.class) + public void testUserNullEmail() { + Identity.user(null); } @Test public void testServiceAccount() { assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type()); assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.id()); - try { - Identity.serviceAccount(null); - fail("Should have thrown exception due to null email address."); - } catch (NullPointerException e) { - // expected - } + } + + @Test(expected = NullPointerException.class) + public void testServiceAccountNullEmail() { + Identity.serviceAccount(null); } @Test public void testGroup() { assertEquals(Identity.Type.GROUP, GROUP.type()); assertEquals("group@gmail.com", GROUP.id()); - try { - Identity.group(null); - fail("Should have thrown exception due to null email address."); - } catch (NullPointerException e) { - // expected - } + } + + @Test(expected = NullPointerException.class) + public void testGroupNullEmail() { + Identity.group(null); } @Test public void testDomain() { assertEquals(Identity.Type.DOMAIN, DOMAIN.type()); assertEquals("google.com", DOMAIN.id()); - try { - Identity.domain(null); - fail("Should have thrown exception due to null domain."); - } catch (NullPointerException e) { - // expected - } + } + + @Test(expected = NullPointerException.class) + public void testDomainNullId() { + Identity.domain(null); } @Test From bab574abdba07cfa89682402999b392f230dc673 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 26 Feb 2016 08:05:10 -0800 Subject: [PATCH 126/663] Use enum for legacy roles, add input checks --- .../java/com/google/gcloud/IamPolicy.java | 50 +++++++++++++++---- .../main/java/com/google/gcloud/Identity.java | 39 +++++++++++---- .../java/com/google/gcloud/IamPolicyTest.java | 29 +++++++---- 3 files changed, 85 insertions(+), 33 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java index 73c3e3fec6..748eaba2ab 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java @@ -23,8 +23,11 @@ import java.io.Serializable; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -65,8 +68,14 @@ protected Builder() {} /** * Replaces the builder's map of bindings with the given map of bindings. + * + * @throws IllegalArgumentException if the provided map is null or contain any null values */ public final B bindings(Map> bindings) { + checkArgument(bindings != null, "The provided map of bindings cannot be null."); + for (Map.Entry> binding : bindings.entrySet()) { + verifyBinding(binding.getKey(), binding.getValue()); + } this.bindings.clear(); for (Map.Entry> binding : bindings.entrySet()) { this.bindings.put(binding.getKey(), new HashSet(binding.getValue())); @@ -78,10 +87,12 @@ public final B bindings(Map> bindings) { * Adds a binding to the policy. * * @throws IllegalArgumentException if the policy already contains a binding with the same role + * or if the role or any identities are null */ public final B addBinding(R role, Set identities) { + verifyBinding(role, identities); checkArgument(!bindings.containsKey(role), - "The policy already contains a binding with the role " + role.toString()); + "The policy already contains a binding with the role " + role.toString() + "."); bindings.put(role, new HashSet(identities)); return self(); } @@ -90,15 +101,23 @@ public final B addBinding(R role, Set identities) { * Adds a binding to the policy. * * @throws IllegalArgumentException if the policy already contains a binding with the same role + * or if the role or any identities are null */ public final B addBinding(R role, Identity first, Identity... others) { - checkArgument(!bindings.containsKey(role), - "The policy already contains a binding with the role " + role.toString()); HashSet identities = new HashSet<>(); identities.add(first); identities.addAll(Arrays.asList(others)); - bindings.put(role, identities); - return self(); + return addBinding(role, identities); + } + + private void verifyBinding(R role, Collection identities) { + checkArgument(role != null, "The role cannot be null."); + verifyIdentities(identities); + } + + private void verifyIdentities(Collection identities) { + checkArgument(identities != null, "A role cannot be assigned to a null set of identities."); + checkArgument(!identities.contains(null), "Null identities are not permitted."); } /** @@ -113,13 +132,16 @@ public final B removeBinding(R role) { * Adds one or more identities to an existing binding. * * @throws IllegalArgumentException if the policy doesn't contain a binding with the specified - * role + * role or any identities are null */ public final B addIdentity(R role, Identity first, Identity... others) { - checkArgument(bindings.containsKey(role), "The policy doesn't contain the specified role."); - Set identities = bindings.get(role); - identities.add(first); - identities.addAll(Arrays.asList(others)); + checkArgument(bindings.containsKey(role), + "The policy doesn't contain the role " + role.toString() + "."); + List toAdd = new LinkedList<>(); + toAdd.add(first); + toAdd.addAll(Arrays.asList(others)); + verifyIdentities(toAdd); + bindings.get(role).addAll(toAdd); return self(); } @@ -130,7 +152,8 @@ public final B addIdentity(R role, Identity first, Identity... others) { * role */ public final B removeIdentity(R role, Identity first, Identity... others) { - checkArgument(bindings.containsKey(role), "The policy doesn't contain the specified role."); + checkArgument(bindings.containsKey(role), + "The policy doesn't contain the role " + role.toString() + "."); bindings.get(role).remove(first); bindings.get(role).removeAll(Arrays.asList(others)); return self(); @@ -179,6 +202,11 @@ protected IamPolicy(Builder> builder) { this.version = builder.version; } + /** + * Returns a builder containing the properties of this IAM Policy. + */ + public abstract Builder> toBuilder(); + /** * The map of bindings that comprises the policy. */ diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Identity.java b/google-cloud-core/src/main/java/com/google/gcloud/Identity.java index 0513916cc8..d1644198f7 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Identity.java @@ -18,11 +18,26 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.CaseFormat; + import java.io.Serializable; import java.util.Objects; /** - * An identity in an {@link IamPolicy}. + * An identity in an {@link IamPolicy}. The following types of identities are permitted in IAM + * policies: + *
    + *
  • Google account + *
  • Service account + *
  • Google group + *
  • Google Apps domain + *
+ * + *

There are also two special identities that represent all users and all Google-authenticated + * accounts. + * + * @see Concepts + * related to identity */ public final class Identity implements Serializable { @@ -82,7 +97,8 @@ public Type type() { *

  • email address (for identities of type {@code USER}, {@code SERVICE_ACCOUNT}, and * {@code GROUP}) *
  • domain (for identities of type {@code DOMAIN}) - *
  • null (for identities of type {@code ALL_USERS} and {@code ALL_AUTHENTICATED_USERS}) + *
  • {@code null} (for identities of type {@code ALL_USERS} and + * {@code ALL_AUTHENTICATED_USERS}) * */ public String id() { @@ -178,7 +194,7 @@ public String strValue() { case DOMAIN: return "domain:" + id; default: - throw new IllegalArgumentException("Unexpected identity type: " + type); + throw new IllegalStateException("Unexpected identity type: " + type); } } @@ -188,21 +204,22 @@ public String strValue() { */ public static Identity valueOf(String identityStr) { String[] info = identityStr.split(":"); - switch (info[0]) { - case "allUsers": + Type type = Type.valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, info[0])); + switch (type) { + case ALL_USERS: return Identity.allUsers(); - case "allAuthenticatedUsers": + case ALL_AUTHENTICATED_USERS: return Identity.allAuthenticatedUsers(); - case "user": + case USER: return Identity.user(info[1]); - case "serviceAccount": + case SERVICE_ACCOUNT: return Identity.serviceAccount(info[1]); - case "group": + case GROUP: return Identity.group(info[1]); - case "domain": + case DOMAIN: return Identity.domain(info[1]); default: - throw new IllegalArgumentException("Unexpected identity type: " + info[0]); + throw new IllegalStateException("Unexpected identity type " + type); } } } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java index b77b5e2df7..db0935c476 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -71,7 +72,8 @@ public PolicyImpl build() { super(builder); } - Builder toBuilder() { + @Override + public Builder toBuilder() { return new Builder(bindings(), etag(), version()); } @@ -93,38 +95,38 @@ public void testBuilder() { assertEquals(1, policy.version().intValue()); policy = SIMPLE_POLICY.toBuilder().removeBinding("editor").build(); assertEquals(ImmutableMap.of("viewer", BINDINGS.get("viewer")), policy.bindings()); - assertEquals(null, policy.etag()); - assertEquals(null, policy.version()); + assertNull(policy.etag()); + assertNull(policy.version()); policy = policy.toBuilder() .removeIdentity("viewer", USER, ALL_USERS) .addIdentity("viewer", DOMAIN, GROUP) .build(); assertEquals(ImmutableMap.of("viewer", ImmutableSet.of(SERVICE_ACCOUNT, DOMAIN, GROUP)), policy.bindings()); - assertEquals(null, policy.etag()); - assertEquals(null, policy.version()); + assertNull(policy.etag()); + assertNull(policy.version()); policy = PolicyImpl.builder().addBinding("owner", USER, SERVICE_ACCOUNT).build(); assertEquals( ImmutableMap.of("owner", ImmutableSet.of(USER, SERVICE_ACCOUNT)), policy.bindings()); - assertEquals(null, policy.etag()); - assertEquals(null, policy.version()); + assertNull(policy.etag()); + assertNull(policy.version()); try { SIMPLE_POLICY.toBuilder().addBinding("viewer", USER); fail("Should have failed due to duplicate role."); } catch (IllegalArgumentException e) { - assertEquals("The policy already contains a binding with the role viewer", e.getMessage()); + assertEquals("The policy already contains a binding with the role viewer.", e.getMessage()); } try { SIMPLE_POLICY.toBuilder().addBinding("editor", ImmutableSet.of(USER)); fail("Should have failed due to duplicate role."); } catch (IllegalArgumentException e) { - assertEquals("The policy already contains a binding with the role editor", e.getMessage()); + assertEquals("The policy already contains a binding with the role editor.", e.getMessage()); } } @Test public void testEqualsHashCode() { - assertNotEquals(FULL_POLICY, null); + assertNotNull(FULL_POLICY); PolicyImpl emptyPolicy = PolicyImpl.builder().build(); AnotherPolicyImpl anotherPolicy = new AnotherPolicyImpl.Builder().build(); assertNotEquals(emptyPolicy, anotherPolicy); @@ -151,7 +153,7 @@ public void testEtag() { @Test public void testVersion() { assertNull(SIMPLE_POLICY.version()); - assertEquals(null, SIMPLE_POLICY.version()); + assertEquals(1, FULL_POLICY.version().intValue()); } static class AnotherPolicyImpl extends IamPolicy { @@ -169,5 +171,10 @@ public AnotherPolicyImpl build() { AnotherPolicyImpl(Builder builder) { super(builder); } + + @Override + public Builder toBuilder() { + return new Builder(); + } } } From 20f2e150a387d1d28cc3e8ea54f36bfd64cbd623 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Sun, 6 Mar 2016 08:54:43 -0800 Subject: [PATCH 127/663] Add NoAuthCredentials --- .../com/google/gcloud/AuthCredentials.java | 34 +++++++++++++++++++ .../com/google/gcloud/ServiceOptions.java | 7 ++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index fc5d74d089..f4f6b69385 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -243,6 +243,33 @@ public RestorableState capture() { } } + public static class NoAuthCredentials extends AuthCredentials { + + private static final AuthCredentials INSTANCE = new NoAuthCredentials(); + private static final NoAuthCredentialsState STATE = new NoAuthCredentialsState(); + + private static class NoAuthCredentialsState + implements RestorableState, Serializable { + + private static final long serialVersionUID = -4022100563954640465L; + + @Override + public AuthCredentials restore() { + return INSTANCE; + } + } + + @Override + public GoogleCredentials credentials() { + return null; + } + + @Override + public RestorableState capture() { + return STATE; + } + } + public abstract GoogleCredentials credentials(); public static AuthCredentials createForAppEngine() { @@ -281,6 +308,13 @@ public static ServiceAccountAuthCredentials createFor(String account, PrivateKey return new ServiceAccountAuthCredentials(account, privateKey); } + /** + * Creates a placeholder denoting that no credentials should be used. + */ + public static AuthCredentials noAuth() { + return NoAuthCredentials.INSTANCE; + } + /** * Creates Service Account Credentials given a stream for credentials in JSON format. * diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 31e5438094..d45069434a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -523,9 +523,10 @@ public RetryParams retryParams() { * options. */ public HttpRequestInitializer httpRequestInitializer() { - final HttpRequestInitializer delegate = authCredentials() != null - ? new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes())) - : null; + final HttpRequestInitializer delegate = + authCredentials() != null && authCredentials.credentials() != null + ? new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes())) + : null; return new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { From 5b969938ee679b8a00259e19322fd20abc55cb74 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 7 Mar 2016 08:27:49 -0800 Subject: [PATCH 128/663] Add javadoc --- .../com/google/gcloud/AuthCredentials.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index f4f6b69385..1f8a56f8e6 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -132,6 +132,12 @@ public RestorableState capture() { } } + /** + * Represents service account credentials. + * + * @see + * User accounts and service accounts + */ public static class ServiceAccountAuthCredentials extends AuthCredentials { private final String account; @@ -195,6 +201,14 @@ public RestorableState capture() { } } + /** + * Represents Application Default Credentials, which are credentials that are inferred from the + * runtime environment. + * + * @see + * Google Application Default Credentials + */ public static class ApplicationDefaultAuthCredentials extends AuthCredentials { private GoogleCredentials googleCredentials; @@ -243,6 +257,11 @@ public RestorableState capture() { } } + /** + * Represents that requests sent to the server should not be authenticated. This is typically + * useful when using the local service emulators, such as {@code LocalGcdHelper} and + * {@code LocalResourceManagerHelper}. + */ public static class NoAuthCredentials extends AuthCredentials { private static final AuthCredentials INSTANCE = new NoAuthCredentials(); @@ -309,7 +328,9 @@ public static ServiceAccountAuthCredentials createFor(String account, PrivateKey } /** - * Creates a placeholder denoting that no credentials should be used. + * Creates a placeholder denoting that no credentials should be used. This is typically useful + * when using the local service emulators, such as {@code LocalGcdHelper} and + * {@code LocalResourceManagerHelper}. */ public static AuthCredentials noAuth() { return NoAuthCredentials.INSTANCE; From bf3ea411a82afacc43ff96faab99ffc4ea8a440e Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 7 Mar 2016 08:50:26 -0800 Subject: [PATCH 129/663] change NoAuthCredentials javadoc wording --- .../src/main/java/com/google/gcloud/AuthCredentials.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 1f8a56f8e6..6f9e09ca04 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -258,9 +258,9 @@ public RestorableState capture() { } /** - * Represents that requests sent to the server should not be authenticated. This is typically - * useful when using the local service emulators, such as {@code LocalGcdHelper} and - * {@code LocalResourceManagerHelper}. + * A placeholder for credentials to signify that requests sent to the server should not be + * authenticated. This is typically useful when using the local service emulators, such as + * {@code LocalGcdHelper} and {@code LocalResourceManagerHelper}. */ public static class NoAuthCredentials extends AuthCredentials { From df66f922f7a5447610b6c24e43aa37d1bee0ee5f Mon Sep 17 00:00:00 2001 From: aozarov Date: Mon, 7 Mar 2016 17:00:03 -0800 Subject: [PATCH 130/663] Fix test and issue #723 --- .../google/gcloud/BaseServiceException.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java index 579340f125..3652439044 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java @@ -97,13 +97,17 @@ public BaseServiceException(IOException exception, boolean idempotent) { String debugInfo = null; if (exception instanceof GoogleJsonResponseException) { GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails(); - Error error = error(jsonError); - code = error.code; - reason = error.reason; - if (reason != null) { - GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0); - location = errorInfo.getLocation(); - debugInfo = (String) errorInfo.get("debugInfo"); + if (jsonError != null) { + Error error = error(jsonError); + code = error.code; + reason = error.reason; + if (reason != null) { + GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0); + location = errorInfo.getLocation(); + debugInfo = (String) errorInfo.get("debugInfo"); + } + } else { + code = ((GoogleJsonResponseException) exception).getStatusCode(); } } this.code = code; @@ -207,7 +211,10 @@ protected static Error error(GoogleJsonError error) { protected static String message(IOException exception) { if (exception instanceof GoogleJsonResponseException) { - return ((GoogleJsonResponseException) exception).getDetails().getMessage(); + GoogleJsonError details = ((GoogleJsonResponseException) exception).getDetails(); + if (details != null) { + return details.getMessage(); + } } return exception.getMessage(); } From 7b5410781bbb4eb9d210f8d016d8001aebddf6ad Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 8 Mar 2016 18:41:22 +0100 Subject: [PATCH 131/663] Release version 0.1.5 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d07a567b7e..8525fde681 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -10,7 +10,7 @@ com.google.gcloud gcloud-java-pom - 0.1.5-SNAPSHOT + 0.1.5 gcloud-java-core From 562669dffd2b472f4b080429d51477900591b86b Mon Sep 17 00:00:00 2001 From: travis-ci Date: Tue, 8 Mar 2016 18:26:13 +0000 Subject: [PATCH 132/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index bc9463b9cc..fc5f481f8e 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.1.4 + 0.1.5 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:0.1.4' +compile 'com.google.gcloud:gcloud-java-core:0.1.5' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.4" +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.5" ``` Troubleshooting From 673b40cb2c28fd041590b345582f056ff827cc8d Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 8 Mar 2016 20:27:32 +0100 Subject: [PATCH 133/663] Update version to 0.1.6-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 8525fde681..6d0ed675b4 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -10,7 +10,7 @@ com.google.gcloud gcloud-java-pom - 0.1.5 + 0.1.6-SNAPSHOT gcloud-java-core From 1cd1a0e558bed702898dcb3378259693c8d99b6c Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 10 Mar 2016 16:36:26 +0100 Subject: [PATCH 134/663] Use groups to separate packages in javadoc's index --- .../java/com/google/gcloud/package-info.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/package-info.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/package-info.java b/google-cloud-core/src/main/java/com/google/gcloud/package-info.java new file mode 100644 index 0000000000..215264675d --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Core classes for the {@code gcloud-java} library. + */ +package com.google.gcloud; \ No newline at end of file From 0e479af9b8e9487b0a8b3806dc1aa1c8258715eb Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 10 Mar 2016 18:50:34 +0100 Subject: [PATCH 135/663] Add group for testing packages --- .../src/main/java/com/google/gcloud/package-info.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/package-info.java b/google-cloud-core/src/main/java/com/google/gcloud/package-info.java index 215264675d..d527640c99 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/package-info.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/package-info.java @@ -17,4 +17,4 @@ /** * Core classes for the {@code gcloud-java} library. */ -package com.google.gcloud; \ No newline at end of file +package com.google.gcloud; From 971fbc2ad5bf0dd7b2c27fd70e0fb4f998464ccb Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 1 Mar 2016 10:02:57 -0800 Subject: [PATCH 136/663] Add get, replace, and test for IAM --- .../main/java/com/google/gcloud/Identity.java | 24 +++++++++---------- .../java/com/google/gcloud/IdentityTest.java | 14 +++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Identity.java b/google-cloud-core/src/main/java/com/google/gcloud/Identity.java index d1644198f7..687a76ffc4 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Identity.java @@ -44,7 +44,7 @@ public final class Identity implements Serializable { private static final long serialVersionUID = -8181841964597657446L; private final Type type; - private final String id; + private final String value; /** * The types of IAM identities. @@ -82,9 +82,9 @@ public enum Type { DOMAIN } - private Identity(Type type, String id) { + private Identity(Type type, String value) { this.type = type; - this.id = id; + this.value = value; } public Type type() { @@ -92,7 +92,7 @@ public Type type() { } /** - * Returns the string identifier for this identity. The id corresponds to: + * Returns the string identifier for this identity. The value corresponds to: *
      *
    • email address (for identities of type {@code USER}, {@code SERVICE_ACCOUNT}, and * {@code GROUP}) @@ -101,8 +101,8 @@ public Type type() { * {@code ALL_AUTHENTICATED_USERS}) *
    */ - public String id() { - return id; + public String value() { + return value; } /** @@ -163,7 +163,7 @@ public static Identity domain(String domain) { @Override public int hashCode() { - return Objects.hash(id, type); + return Objects.hash(value, type); } @Override @@ -172,7 +172,7 @@ public boolean equals(Object obj) { return false; } Identity other = (Identity) obj; - return Objects.equals(id, other.id()) && Objects.equals(type, other.type()); + return Objects.equals(value, other.value()) && Objects.equals(type, other.type()); } /** @@ -186,13 +186,13 @@ public String strValue() { case ALL_AUTHENTICATED_USERS: return "allAuthenticatedUsers"; case USER: - return "user:" + id; + return "user:" + value; case SERVICE_ACCOUNT: - return "serviceAccount:" + id; + return "serviceAccount:" + value; case GROUP: - return "group:" + id; + return "group:" + value; case DOMAIN: - return "domain:" + id; + return "domain:" + value; default: throw new IllegalStateException("Unexpected identity type: " + type); } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java index 828f1c8394..a42bc9db7a 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java @@ -34,19 +34,19 @@ public class IdentityTest { @Test public void testAllUsers() { assertEquals(Identity.Type.ALL_USERS, ALL_USERS.type()); - assertNull(ALL_USERS.id()); + assertNull(ALL_USERS.value()); } @Test public void testAllAuthenticatedUsers() { assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTH_USERS.type()); - assertNull(ALL_AUTH_USERS.id()); + assertNull(ALL_AUTH_USERS.value()); } @Test public void testUser() { assertEquals(Identity.Type.USER, USER.type()); - assertEquals("abc@gmail.com", USER.id()); + assertEquals("abc@gmail.com", USER.value()); } @Test(expected = NullPointerException.class) @@ -57,7 +57,7 @@ public void testUserNullEmail() { @Test public void testServiceAccount() { assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type()); - assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.id()); + assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.value()); } @Test(expected = NullPointerException.class) @@ -68,7 +68,7 @@ public void testServiceAccountNullEmail() { @Test public void testGroup() { assertEquals(Identity.Type.GROUP, GROUP.type()); - assertEquals("group@gmail.com", GROUP.id()); + assertEquals("group@gmail.com", GROUP.value()); } @Test(expected = NullPointerException.class) @@ -79,7 +79,7 @@ public void testGroupNullEmail() { @Test public void testDomain() { assertEquals(Identity.Type.DOMAIN, DOMAIN.type()); - assertEquals("google.com", DOMAIN.id()); + assertEquals("google.com", DOMAIN.value()); } @Test(expected = NullPointerException.class) @@ -100,6 +100,6 @@ public void testIdentityToAndFromPb() { private void compareIdentities(Identity expected, Identity actual) { assertEquals(expected, actual); assertEquals(expected.type(), actual.type()); - assertEquals(expected.id(), actual.id()); + assertEquals(expected.value(), actual.value()); } } From 5e592fb86c1f2689577d7ba352f7128d64bf9998 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 16 Mar 2016 09:35:09 +0100 Subject: [PATCH 137/663] Create base class for serialization tests --- .../google/gcloud/BaseSerializationTest.java | 64 +++++++++++++++++++ .../com/google/gcloud/SerializationTest.java | 33 ++++++++++ 2 files changed, 97 insertions(+) create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java new file mode 100644 index 0000000000..533dfcde6a --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; + +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + +/** + * Base class for serialization tests. To use this class in your tests override the + * {@code serializableObjects()} method to return all objects that must be serializable. + */ +public abstract class BaseSerializationTest { + + public abstract Serializable[] serializableObjects(); + + @Test + public void testSerializableObjects() throws Exception { + for (Serializable obj : serializableObjects()) { + Object copy = serializeAndDeserialize(obj); + assertEquals(obj, obj); + assertEquals(obj, copy); + assertEquals(obj.hashCode(), copy.hashCode()); + assertEquals(obj.toString(), copy.toString()); + assertNotSame(obj, copy); + assertEquals(copy, copy); + } + } + + @SuppressWarnings("unchecked") + public T serializeAndDeserialize(T obj) + throws IOException, ClassNotFoundException { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + try (ObjectOutputStream output = new ObjectOutputStream(bytes)) { + output.writeObject(obj); + } + try (ObjectInputStream input = + new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) { + return (T) input.readObject(); + } + } +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java new file mode 100644 index 0000000000..aec9158e1e --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java @@ -0,0 +1,33 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import com.google.common.collect.ImmutableList; + +import java.io.Serializable; + +public class SerializationTest extends BaseSerializationTest { + + private static final PageImpl PAGE = + new PageImpl<>(null, "cursor", ImmutableList.of("string1", "string2")); + private static final RetryParams RETRY_PARAMS = RetryParams.defaultInstance(); + + @Override + public Serializable[] serializableObjects() { + return new Serializable[]{PAGE, RETRY_PARAMS}; + } +} From a2dde88add25fc3db35ae891d833968cc56ecead Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 17 Mar 2016 09:54:13 +0100 Subject: [PATCH 138/663] Add tests for restorable classes. Fix serialization issues --- .../com/google/gcloud/AuthCredentials.java | 10 ++++ .../com/google/gcloud/ExceptionHandler.java | 22 +++++++++ .../google/gcloud/BaseSerializationTest.java | 19 +++++++- .../com/google/gcloud/SerializationTest.java | 46 ++++++++++++++++++- 4 files changed, 94 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 6f9e09ca04..38265a26be 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -276,6 +276,16 @@ private static class NoAuthCredentialsState public AuthCredentials restore() { return INSTANCE; } + + @Override + public int hashCode() { + return getClass().getName().hashCode(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof NoAuthCredentialsState; + } } @Override diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java index 39d4c4e75a..0dbcbeb653 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java @@ -26,6 +26,7 @@ import java.io.Serializable; import java.lang.reflect.Method; +import java.util.Objects; import java.util.Set; import java.util.concurrent.Callable; @@ -259,6 +260,27 @@ boolean shouldRetry(Exception ex) { return retryResult == Interceptor.RetryResult.RETRY; } + @Override + public int hashCode() { + return Objects.hash(interceptors, retriableExceptions, nonRetriableExceptions, retryInfo); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof ExceptionHandler)) { + return false; + } + ExceptionHandler other = (ExceptionHandler) obj; + return Objects.equals(interceptors, other.interceptors) + && Objects.equals(retriableExceptions, other.retriableExceptions) + && Objects.equals(nonRetriableExceptions, other.nonRetriableExceptions) + && Objects.equals(retryInfo, other.retryInfo); + + } + /** * Returns an instance which retry any checked exception and abort on any runtime exception. */ diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java index 533dfcde6a..a8136bfbf0 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java @@ -34,6 +34,9 @@ */ public abstract class BaseSerializationTest { + /** + * Returns all objects for which correct serialization must be tested. + */ public abstract Serializable[] serializableObjects(); @Test @@ -50,8 +53,7 @@ public void testSerializableObjects() throws Exception { } @SuppressWarnings("unchecked") - public T serializeAndDeserialize(T obj) - throws IOException, ClassNotFoundException { + public T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try (ObjectOutputStream output = new ObjectOutputStream(bytes)) { output.writeObject(obj); @@ -61,4 +63,17 @@ public T serializeAndDeserialize(T obj) return (T) input.readObject(); } } + + /** + * Checks whether the state of a restorable object can correctly be captured, serialized and + * restored. + */ + public void assertRestorable(Restorable restorable) throws IOException, + ClassNotFoundException { + RestorableState state = restorable.capture(); + RestorableState deserializedState = serializeAndDeserialize(state); + assertEquals(state, deserializedState); + assertEquals(state.hashCode(), deserializedState.hashCode()); + assertEquals(state.toString(), deserializedState.toString()); + } } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java index aec9158e1e..46f1f73563 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java @@ -18,16 +18,60 @@ import com.google.common.collect.ImmutableList; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.Serializable; public class SerializationTest extends BaseSerializationTest { + private static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.defaultInstance(); + private static final Identity IDENTITY = Identity.allAuthenticatedUsers(); private static final PageImpl PAGE = new PageImpl<>(null, "cursor", ImmutableList.of("string1", "string2")); private static final RetryParams RETRY_PARAMS = RetryParams.defaultInstance(); + private static final String JSON_KEY = "{\n" + + " \"private_key_id\": \"somekeyid\",\n" + + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" + + "kAgEAAoIBAQC+K2hSuFpAdrJI\\nnCgcDz2M7t7bjdlsadsasad+fvRSW6TjNQZ3p5LLQY1kSZRqBqylRkzteMOyHg" + + "aR\\n0Pmxh3ILCND5men43j3h4eDbrhQBuxfEMalkG92sL+PNQSETY2tnvXryOvmBRwa/\\nQP/9dJfIkIDJ9Fw9N4" + + "Bhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nknddadwkwewcVxHFhcZJO+XWf6ofLUXpRwiTZakGMn8EE1uVa2" + + "LgczOjwWHGi99MFjxSer5m9\\n1tCa3/KEGKiS/YL71JvjwX3mb+cewlkcmweBKZHM2JPTk0ZednFSpVZMtycjkbLa" + + "\\ndYOS8V85AgMBewECggEBAKksaldajfDZDV6nGqbFjMiizAKJolr/M3OQw16K6o3/\\n0S31xIe3sSlgW0+UbYlF" + + "4U8KifhManD1apVSC3csafaspP4RZUHFhtBywLO9pR5c\\nr6S5aLp+gPWFyIp1pfXbWGvc5VY/v9x7ya1VEa6rXvL" + + "sKupSeWAW4tMj3eo/64ge\\nsdaceaLYw52KeBYiT6+vpsnYrEkAHO1fF/LavbLLOFJmFTMxmsNaG0tuiJHgjshB\\" + + "n82DpMCbXG9YcCgI/DbzuIjsdj2JC1cascSP//3PmefWysucBQe7Jryb6NQtASmnv\\nCdDw/0jmZTEjpe4S1lxfHp" + + "lAhHFtdgYTvyYtaLZiVVkCgYEA8eVpof2rceecw/I6\\n5ng1q3Hl2usdWV/4mZMvR0fOemacLLfocX6IYxT1zA1FF" + + "JlbXSRsJMf/Qq39mOR2\\nSpW+hr4jCoHeRVYLgsbggtrevGmILAlNoqCMpGZ6vDmJpq6ECV9olliDvpPgWOP+\\nm" + + "YPDreFBGxWvQrADNbRt2dmGsrsCgYEAyUHqB2wvJHFqdmeBsaacewzV8x9WgmeX\\ngUIi9REwXlGDW0Mz50dxpxcK" + + "CAYn65+7TCnY5O/jmL0VRxU1J2mSWyWTo1C+17L0\\n3fUqjxL1pkefwecxwecvC+gFFYdJ4CQ/MHHXU81Lwl1iWdF" + + "Cd2UoGddYaOF+KNeM\\nHC7cmqra+JsCgYEAlUNywzq8nUg7282E+uICfCB0LfwejuymR93CtsFgb7cRd6ak\\nECR" + + "8FGfCpH8ruWJINllbQfcHVCX47ndLZwqv3oVFKh6pAS/vVI4dpOepP8++7y1u\\ncoOvtreXCX6XqfrWDtKIvv0vjl" + + "HBhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nkndj5uNl5SiuVxHFhcZJO+XWf6ofLUregtevZakGMn8EE1uVa" + + "2AY7eafmoU/nZPT\\n00YB0TBATdCbn/nBSuKDESkhSg9s2GEKQZG5hBmL5uCMfo09z3SfxZIhJdlerreP\\nJ7gSi" + + "dI12N+EZxYd4xIJh/HFDgp7RRO87f+WJkofMQKBgGTnClK1VMaCRbJZPriw\\nEfeFCoOX75MxKwXs6xgrw4W//AYG" + + "GUjDt83lD6AZP6tws7gJ2IwY/qP7+lyhjEqN\\nHtfPZRGFkGZsdaksdlaksd323423d+15/UvrlRSFPNj1tWQmNKk" + + "XyRDW4IG1Oa2p\\nrALStNBx5Y9t0/LQnFI4w3aG\\n-----END PRIVATE KEY-----\\n\",\n" + + " \"client_email\": \"someclientid@developer.gserviceaccount.com\",\n" + + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" + + " \"type\": \"service_account\"\n" + + "}"; @Override public Serializable[] serializableObjects() { - return new Serializable[]{PAGE, RETRY_PARAMS}; + return new Serializable[]{EXCEPTION_HANDLER, IDENTITY, PAGE, RETRY_PARAMS}; + } + + @Test + public void testAuthCredentialState() throws IOException, ClassNotFoundException { + AuthCredentials credentials = AuthCredentials.createApplicationDefaults(); + assertRestorable(credentials); + credentials = AuthCredentials.createForAppEngine(); + assertRestorable(credentials); + credentials = AuthCredentials.noAuth(); + assertRestorable(credentials); + credentials = AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes())); + assertRestorable(credentials); } } From 13a9546a4591c30d11e6c745f544d5797ce20874 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 17 Mar 2016 17:28:55 +0100 Subject: [PATCH 139/663] Remove serialization test for ApplicationDefaultAuthCredentials --- .../src/test/java/com/google/gcloud/SerializationTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java index 46f1f73563..a9526a42d7 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java @@ -65,9 +65,7 @@ public Serializable[] serializableObjects() { @Test public void testAuthCredentialState() throws IOException, ClassNotFoundException { - AuthCredentials credentials = AuthCredentials.createApplicationDefaults(); - assertRestorable(credentials); - credentials = AuthCredentials.createForAppEngine(); + AuthCredentials credentials = AuthCredentials.createForAppEngine(); assertRestorable(credentials); credentials = AuthCredentials.noAuth(); assertRestorable(credentials); From 413309667910ee33cbefe63e49b5c76a1009e799 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 17 Mar 2016 18:59:46 +0100 Subject: [PATCH 140/663] Add restorableObjects method to BaseSerializationTest --- .../com/google/gcloud/ExceptionHandler.java | 1 - .../google/gcloud/BaseSerializationTest.java | 39 +++++++++++-------- .../com/google/gcloud/SerializationTest.java | 21 +++++----- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java index 0dbcbeb653..0b3c923d1e 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java @@ -278,7 +278,6 @@ public boolean equals(Object obj) { && Objects.equals(retriableExceptions, other.retriableExceptions) && Objects.equals(nonRetriableExceptions, other.nonRetriableExceptions) && Objects.equals(retryInfo, other.retryInfo); - } /** diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java index a8136bfbf0..e9ab3d4798 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java @@ -16,6 +16,7 @@ package com.google.gcloud; +import static com.google.common.base.MoreObjects.firstNonNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; @@ -30,18 +31,26 @@ /** * Base class for serialization tests. To use this class in your tests override the - * {@code serializableObjects()} method to return all objects that must be serializable. + * {@code serializableObjects()} method to return all objects that must be serializable. Also + * override {@code restorableObjects()} method to return all restorable objects whose state must be + * tested for proper serialization. Both methods can return {@code null} if no such object needs to + * be tested. */ public abstract class BaseSerializationTest { /** * Returns all objects for which correct serialization must be tested. */ - public abstract Serializable[] serializableObjects(); + protected abstract Serializable[] serializableObjects(); + + /** + * Returns all restorable objects whose state must be tested for proper serialization. + */ + protected abstract Restorable[] restorableObjects(); @Test public void testSerializableObjects() throws Exception { - for (Serializable obj : serializableObjects()) { + for (Serializable obj : firstNonNull(serializableObjects(), new Serializable[0])) { Object copy = serializeAndDeserialize(obj); assertEquals(obj, obj); assertEquals(obj, copy); @@ -52,6 +61,17 @@ public void testSerializableObjects() throws Exception { } } + @Test + public void testRestorableObjects() throws Exception { + for (Restorable restorable : firstNonNull(restorableObjects(), new Restorable[0])) { + RestorableState state = restorable.capture(); + RestorableState deserializedState = serializeAndDeserialize(state); + assertEquals(state, deserializedState); + assertEquals(state.hashCode(), deserializedState.hashCode()); + assertEquals(state.toString(), deserializedState.toString()); + } + } + @SuppressWarnings("unchecked") public T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); @@ -63,17 +83,4 @@ public T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundExc return (T) input.readObject(); } } - - /** - * Checks whether the state of a restorable object can correctly be captured, serialized and - * restored. - */ - public void assertRestorable(Restorable restorable) throws IOException, - ClassNotFoundException { - RestorableState state = restorable.capture(); - RestorableState deserializedState = serializeAndDeserialize(state); - assertEquals(state, deserializedState); - assertEquals(state.hashCode(), deserializedState.hashCode()); - assertEquals(state.toString(), deserializedState.toString()); - } } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java index a9526a42d7..c4bcfcc13b 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java @@ -18,8 +18,6 @@ import com.google.common.collect.ImmutableList; -import org.junit.Test; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.Serializable; @@ -59,17 +57,18 @@ public class SerializationTest extends BaseSerializationTest { + "}"; @Override - public Serializable[] serializableObjects() { + protected Serializable[] serializableObjects() { return new Serializable[]{EXCEPTION_HANDLER, IDENTITY, PAGE, RETRY_PARAMS}; } - @Test - public void testAuthCredentialState() throws IOException, ClassNotFoundException { - AuthCredentials credentials = AuthCredentials.createForAppEngine(); - assertRestorable(credentials); - credentials = AuthCredentials.noAuth(); - assertRestorable(credentials); - credentials = AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes())); - assertRestorable(credentials); + @Override + protected Restorable[] restorableObjects() { + try { + return new Restorable[]{AuthCredentials.createForAppEngine(), AuthCredentials.noAuth(), + AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes()))}; + } catch (IOException ex) { + // never reached + throw new RuntimeException(ex); + } } } From 6091a8190bdf3654fe536e72975243c57bdd3031 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 18 Mar 2016 16:01:58 +0100 Subject: [PATCH 141/663] Make NoAuthCredentials constructor private --- .../src/main/java/com/google/gcloud/AuthCredentials.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 38265a26be..27cafc1815 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -288,6 +288,8 @@ public boolean equals(Object obj) { } } + private NoAuthCredentials() {} + @Override public GoogleCredentials credentials() { return null; From b3844f9c45da619622aadc48733559249a95f57a Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 18 Mar 2016 16:03:46 +0100 Subject: [PATCH 142/663] Add IamPolicy to SerializationTest --- .../com/google/gcloud/SerializationTest.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java index c4bcfcc13b..194479ac36 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java @@ -24,11 +24,34 @@ public class SerializationTest extends BaseSerializationTest { + private static class SomeIamPolicy extends IamPolicy { + + private static final long serialVersionUID = 271243551016958285L; + + private static class Builder extends IamPolicy.Builder { + + @Override + public SomeIamPolicy build() { + return new SomeIamPolicy(this); + } + } + + protected SomeIamPolicy(Builder builder) { + super(builder); + } + + @Override + public Builder toBuilder() { + return new Builder(); + } + } + private static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.defaultInstance(); private static final Identity IDENTITY = Identity.allAuthenticatedUsers(); private static final PageImpl PAGE = new PageImpl<>(null, "cursor", ImmutableList.of("string1", "string2")); private static final RetryParams RETRY_PARAMS = RetryParams.defaultInstance(); + private static final SomeIamPolicy SOME_IAM_POLICY = new SomeIamPolicy.Builder().build(); private static final String JSON_KEY = "{\n" + " \"private_key_id\": \"somekeyid\",\n" + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" @@ -58,7 +81,7 @@ public class SerializationTest extends BaseSerializationTest { @Override protected Serializable[] serializableObjects() { - return new Serializable[]{EXCEPTION_HANDLER, IDENTITY, PAGE, RETRY_PARAMS}; + return new Serializable[]{EXCEPTION_HANDLER, IDENTITY, PAGE, RETRY_PARAMS, SOME_IAM_POLICY}; } @Override From 9f0a79e9ebab2d1c5b1a4243010d6d66a464600c Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 18 Mar 2016 16:08:37 +0100 Subject: [PATCH 143/663] Add equals and hashCode to exceptions. Add exceptions to serialization tests --- .../google/gcloud/BaseServiceException.java | 45 ++++++++++++++----- .../com/google/gcloud/SerializationTest.java | 5 ++- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java index 3652439044..4e0d03e007 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java @@ -32,6 +32,16 @@ */ public class BaseServiceException extends RuntimeException { + private static final long serialVersionUID = 759921776378760835L; + public static final int UNKNOWN_CODE = 0; + + private final int code; + private final boolean retryable; + private final String reason; + private final boolean idempotent; + private final String location; + private final String debugInfo; + protected static final class Error implements Serializable { private static final long serialVersionUID = -4019600198652965721L; @@ -79,16 +89,6 @@ public int hashCode() { } } - private static final long serialVersionUID = 759921776378760835L; - public static final int UNKNOWN_CODE = 0; - - private final int code; - private final boolean retryable; - private final String reason; - private final boolean idempotent; - private final String location; - private final String debugInfo; - public BaseServiceException(IOException exception, boolean idempotent) { super(message(exception), exception); int code = UNKNOWN_CODE; @@ -198,6 +198,31 @@ protected String debugInfo() { return debugInfo; } + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof BaseServiceException)) { + return false; + } + BaseServiceException other = (BaseServiceException) obj; + return Objects.equals(getCause(), other.getCause()) + && Objects.equals(getMessage(), other.getMessage()) + && code == other.code + && retryable == other.retryable + && Objects.equals(reason, other.reason) + && idempotent == other.idempotent + && Objects.equals(location, other.location) + && Objects.equals(debugInfo, other.debugInfo); + } + + @Override + public int hashCode() { + return Objects.hash(getCause(), getMessage(), code, retryable, reason, idempotent, location, + debugInfo); + } + protected static String reason(GoogleJsonError error) { if (error.getErrors() != null && !error.getErrors().isEmpty()) { return error.getErrors().get(0).getReason(); diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java index 194479ac36..3255a17333 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java @@ -46,6 +46,8 @@ public Builder toBuilder() { } } + private static final BaseServiceException BASE_SERVICE_EXCEPTION = + new BaseServiceException(42, "message", "reason", true); private static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.defaultInstance(); private static final Identity IDENTITY = Identity.allAuthenticatedUsers(); private static final PageImpl PAGE = @@ -81,7 +83,8 @@ public Builder toBuilder() { @Override protected Serializable[] serializableObjects() { - return new Serializable[]{EXCEPTION_HANDLER, IDENTITY, PAGE, RETRY_PARAMS, SOME_IAM_POLICY}; + return new Serializable[]{BASE_SERVICE_EXCEPTION, EXCEPTION_HANDLER, IDENTITY, PAGE, + RETRY_PARAMS, SOME_IAM_POLICY}; } @Override From 28c529c20e43a8e42003a76f618c112fc984a0fe Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 21 Mar 2016 09:36:13 -0700 Subject: [PATCH 144/663] Add binding entries as necessary in IamPolicy.Builder --- .../java/com/google/gcloud/IamPolicy.java | 63 +++++-------------- .../java/com/google/gcloud/IamPolicyTest.java | 44 +++++++++---- 2 files changed, 49 insertions(+), 58 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java index 748eaba2ab..3d7c1422e6 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java @@ -83,39 +83,8 @@ public final B bindings(Map> bindings) { return self(); } - /** - * Adds a binding to the policy. - * - * @throws IllegalArgumentException if the policy already contains a binding with the same role - * or if the role or any identities are null - */ - public final B addBinding(R role, Set identities) { - verifyBinding(role, identities); - checkArgument(!bindings.containsKey(role), - "The policy already contains a binding with the role " + role.toString() + "."); - bindings.put(role, new HashSet(identities)); - return self(); - } - - /** - * Adds a binding to the policy. - * - * @throws IllegalArgumentException if the policy already contains a binding with the same role - * or if the role or any identities are null - */ - public final B addBinding(R role, Identity first, Identity... others) { - HashSet identities = new HashSet<>(); - identities.add(first); - identities.addAll(Arrays.asList(others)); - return addBinding(role, identities); - } - private void verifyBinding(R role, Collection identities) { checkArgument(role != null, "The role cannot be null."); - verifyIdentities(identities); - } - - private void verifyIdentities(Collection identities) { checkArgument(identities != null, "A role cannot be assigned to a null set of identities."); checkArgument(!identities.contains(null), "Null identities are not permitted."); } @@ -129,33 +98,33 @@ public final B removeBinding(R role) { } /** - * Adds one or more identities to an existing binding. - * - * @throws IllegalArgumentException if the policy doesn't contain a binding with the specified - * role or any identities are null + * Adds one or more identities to the policy under the role specified. Creates a new role + * binding if the binding corresponding to the given role did not previously exist. */ public final B addIdentity(R role, Identity first, Identity... others) { - checkArgument(bindings.containsKey(role), - "The policy doesn't contain the role " + role.toString() + "."); List toAdd = new LinkedList<>(); toAdd.add(first); toAdd.addAll(Arrays.asList(others)); - verifyIdentities(toAdd); - bindings.get(role).addAll(toAdd); + verifyBinding(role, toAdd); + Set identities = bindings.get(role); + if (identities == null) { + identities = new HashSet(); + bindings.put(role, identities); + } + identities.addAll(toAdd); return self(); } /** - * Removes one or more identities from an existing binding. - * - * @throws IllegalArgumentException if the policy doesn't contain a binding with the specified - * role + * Removes one or more identities from an existing binding. Does nothing if the binding + * associated with the provided role doesn't exist. */ public final B removeIdentity(R role, Identity first, Identity... others) { - checkArgument(bindings.containsKey(role), - "The policy doesn't contain the role " + role.toString() + "."); - bindings.get(role).remove(first); - bindings.get(role).removeAll(Arrays.asList(others)); + Set identities = bindings.get(role); + if (identities != null) { + identities.remove(first); + identities.removeAll(Arrays.asList(others)); + } return self(); } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java index db0935c476..2f40c3b760 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java @@ -28,6 +28,7 @@ import org.junit.Test; +import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -46,8 +47,8 @@ public class IamPolicyTest { "editor", ImmutableSet.of(ALL_AUTH_USERS, GROUP, DOMAIN)); private static final PolicyImpl SIMPLE_POLICY = PolicyImpl.builder() - .addBinding("viewer", ImmutableSet.of(USER, SERVICE_ACCOUNT, ALL_USERS)) - .addBinding("editor", ImmutableSet.of(ALL_AUTH_USERS, GROUP, DOMAIN)) + .addIdentity("viewer", USER, SERVICE_ACCOUNT, ALL_USERS) + .addIdentity("editor", ALL_AUTH_USERS, GROUP, DOMAIN) .build(); private static final PolicyImpl FULL_POLICY = new PolicyImpl.Builder(SIMPLE_POLICY.bindings(), "etag", 1).build(); @@ -105,22 +106,43 @@ public void testBuilder() { policy.bindings()); assertNull(policy.etag()); assertNull(policy.version()); - policy = PolicyImpl.builder().addBinding("owner", USER, SERVICE_ACCOUNT).build(); + policy = PolicyImpl.builder() + .removeIdentity("viewer", USER) + .addIdentity("owner", USER, SERVICE_ACCOUNT) + .build(); assertEquals( ImmutableMap.of("owner", ImmutableSet.of(USER, SERVICE_ACCOUNT)), policy.bindings()); assertNull(policy.etag()); assertNull(policy.version()); + } + + @Test + public void testIllegalPolicies() { + try { + PolicyImpl.builder().addIdentity(null, USER); + fail("Null role should cause exception."); + } catch (IllegalArgumentException ex) { + assertEquals("The role cannot be null.", ex.getMessage()); + } + try { + PolicyImpl.builder().addIdentity("viewer", null, USER); + fail("Null identity should cause exception."); + } catch (IllegalArgumentException ex) { + assertEquals("Null identities are not permitted.", ex.getMessage()); + } try { - SIMPLE_POLICY.toBuilder().addBinding("viewer", USER); - fail("Should have failed due to duplicate role."); - } catch (IllegalArgumentException e) { - assertEquals("The policy already contains a binding with the role viewer.", e.getMessage()); + PolicyImpl.builder().bindings(null); + fail("Null bindings map should cause exception."); + } catch (IllegalArgumentException ex) { + assertEquals("The provided map of bindings cannot be null.", ex.getMessage()); } try { - SIMPLE_POLICY.toBuilder().addBinding("editor", ImmutableSet.of(USER)); - fail("Should have failed due to duplicate role."); - } catch (IllegalArgumentException e) { - assertEquals("The policy already contains a binding with the role editor.", e.getMessage()); + Map> bindings = new HashMap<>(); + bindings.put("viewer", null); + PolicyImpl.builder().bindings(bindings); + fail("Null set of identities should cause exception."); + } catch (IllegalArgumentException ex) { + assertEquals("A role cannot be assigned to a null set of identities.", ex.getMessage()); } } From ad48c5c85cfc23adbb21d8bd3d38b18791c8c975 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 21 Mar 2016 16:29:10 -0700 Subject: [PATCH 145/663] Take care of minor changes --- .../java/com/google/gcloud/IamPolicy.java | 44 +++++++++++-------- .../java/com/google/gcloud/IamPolicyTest.java | 29 +++++++++--- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java index 3d7c1422e6..9cce4b23c8 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java @@ -17,17 +17,16 @@ package com.google.gcloud; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.io.Serializable; import java.util.Arrays; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -69,12 +68,16 @@ protected Builder() {} /** * Replaces the builder's map of bindings with the given map of bindings. * - * @throws IllegalArgumentException if the provided map is null or contain any null values + * @throws NullPointerException if the given map is null or contains any null keys or values + * @throws IllegalArgumentException if any identities in the given map are null */ public final B bindings(Map> bindings) { - checkArgument(bindings != null, "The provided map of bindings cannot be null."); + checkNotNull(bindings, "The provided map of bindings cannot be null."); for (Map.Entry> binding : bindings.entrySet()) { - verifyBinding(binding.getKey(), binding.getValue()); + checkNotNull(binding.getKey(), "The role cannot be null."); + Set identities = binding.getValue(); + checkNotNull(identities, "A role cannot be assigned to a null set of identities."); + checkArgument(!identities.contains(null), "Null identities are not permitted."); } this.bindings.clear(); for (Map.Entry> binding : bindings.entrySet()) { @@ -83,30 +86,30 @@ public final B bindings(Map> bindings) { return self(); } - private void verifyBinding(R role, Collection identities) { - checkArgument(role != null, "The role cannot be null."); - checkArgument(identities != null, "A role cannot be assigned to a null set of identities."); - checkArgument(!identities.contains(null), "Null identities are not permitted."); - } - /** - * Removes the binding associated with the specified role. + * Removes the role (and all identities associated with that role) from the policy. */ - public final B removeBinding(R role) { + public final B removeRole(R role) { bindings.remove(role); return self(); } /** - * Adds one or more identities to the policy under the role specified. Creates a new role - * binding if the binding corresponding to the given role did not previously exist. + * Adds one or more identities to the policy under the role specified. + * + * @throws NullPointerException if the role or any of the identities is null. */ public final B addIdentity(R role, Identity first, Identity... others) { - List toAdd = new LinkedList<>(); + String nullIdentityMessage = "Null identities are not permitted."; + checkNotNull(first, nullIdentityMessage); + checkNotNull(others, nullIdentityMessage); + for (Identity identity : others) { + checkNotNull(identity, nullIdentityMessage); + } + Set toAdd = new LinkedHashSet<>(); toAdd.add(first); toAdd.addAll(Arrays.asList(others)); - verifyBinding(role, toAdd); - Set identities = bindings.get(role); + Set identities = bindings.get(checkNotNull(role, "The role cannot be null.")); if (identities == null) { identities = new HashSet(); bindings.put(role, identities); @@ -125,6 +128,9 @@ public final B removeIdentity(R role, Identity first, Identity... others) { identities.remove(first); identities.removeAll(Arrays.asList(others)); } + if (identities != null && identities.isEmpty()) { + bindings.remove(role); + } return self(); } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java index 2f40c3b760..235c2c2b1c 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java @@ -29,6 +29,7 @@ import org.junit.Test; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -94,7 +95,7 @@ public void testBuilder() { assertEquals(editorBinding, policy.bindings()); assertEquals("etag", policy.etag()); assertEquals(1, policy.version().intValue()); - policy = SIMPLE_POLICY.toBuilder().removeBinding("editor").build(); + policy = SIMPLE_POLICY.toBuilder().removeRole("editor").build(); assertEquals(ImmutableMap.of("viewer", BINDINGS.get("viewer")), policy.bindings()); assertNull(policy.etag()); assertNull(policy.version()); @@ -109,6 +110,8 @@ public void testBuilder() { policy = PolicyImpl.builder() .removeIdentity("viewer", USER) .addIdentity("owner", USER, SERVICE_ACCOUNT) + .addIdentity("editor", GROUP) + .removeIdentity("editor", GROUP) .build(); assertEquals( ImmutableMap.of("owner", ImmutableSet.of(USER, SERVICE_ACCOUNT)), policy.bindings()); @@ -121,19 +124,25 @@ public void testIllegalPolicies() { try { PolicyImpl.builder().addIdentity(null, USER); fail("Null role should cause exception."); - } catch (IllegalArgumentException ex) { + } catch (NullPointerException ex) { assertEquals("The role cannot be null.", ex.getMessage()); } try { PolicyImpl.builder().addIdentity("viewer", null, USER); fail("Null identity should cause exception."); - } catch (IllegalArgumentException ex) { + } catch (NullPointerException ex) { + assertEquals("Null identities are not permitted.", ex.getMessage()); + } + try { + PolicyImpl.builder().addIdentity("viewer", USER, (Identity[]) null); + fail("Null identity should cause exception."); + } catch (NullPointerException ex) { assertEquals("Null identities are not permitted.", ex.getMessage()); } try { PolicyImpl.builder().bindings(null); fail("Null bindings map should cause exception."); - } catch (IllegalArgumentException ex) { + } catch (NullPointerException ex) { assertEquals("The provided map of bindings cannot be null.", ex.getMessage()); } try { @@ -141,9 +150,19 @@ public void testIllegalPolicies() { bindings.put("viewer", null); PolicyImpl.builder().bindings(bindings); fail("Null set of identities should cause exception."); - } catch (IllegalArgumentException ex) { + } catch (NullPointerException ex) { assertEquals("A role cannot be assigned to a null set of identities.", ex.getMessage()); } + try { + Map> bindings = new HashMap<>(); + Set identities = new HashSet<>(); + identities.add(null); + bindings.put("viewer", identities); + PolicyImpl.builder().bindings(bindings); + fail("Null identity should cause exception."); + } catch (IllegalArgumentException ex) { + assertEquals("Null identities are not permitted.", ex.getMessage()); + } } @Test From d0d0a6a3f6e43bab4b0824324ec03458377636c6 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 28 Mar 2016 17:36:19 -0700 Subject: [PATCH 146/663] Release v0.1.6 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6d0ed675b4..51d6baf213 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -10,7 +10,7 @@ com.google.gcloud gcloud-java-pom - 0.1.6-SNAPSHOT + 0.1.6 gcloud-java-core From 056d119074660179fe611e1f572b1b14de78b744 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Tue, 29 Mar 2016 01:10:21 +0000 Subject: [PATCH 147/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index fc5f481f8e..1ee96b9504 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.1.5 + 0.1.6 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:0.1.5' +compile 'com.google.gcloud:gcloud-java-core:0.1.6' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.5" +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.6" ``` Troubleshooting From ddd630877db71aa57152634911929e8e4a17b41e Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 28 Mar 2016 18:33:20 -0700 Subject: [PATCH 148/663] Update version to 0.1.7-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 51d6baf213..13e170e061 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -10,7 +10,7 @@ com.google.gcloud gcloud-java-pom - 0.1.6 + 0.1.7-SNAPSHOT gcloud-java-core From 47f3d57ddccee6d7a1f6c1f1450b0a4e34398365 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 29 Mar 2016 17:57:35 +0200 Subject: [PATCH 149/663] Add common interface for field selectors --- .../java/com/google/gcloud/FieldSelector.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java new file mode 100644 index 0000000000..358c4d4798 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java @@ -0,0 +1,30 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +/** + * Interface for Google Cloud resource's fields. Implementations of this interface can be used to + * select only desired fields when getting or listing Google Cloud resources. + */ +public interface FieldSelector { + + /** + * Returns a string selector. This selector is passed to a Google Cloud service (possibly with + * other field selectors) to specify which resource fields should be returned by an API call. + */ + String selector(); +} From 8bed1dc0cdaddf5adaf3237eb9b64c593502ae25 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 30 Mar 2016 14:57:00 +0200 Subject: [PATCH 150/663] Refactor field selection and helpers - Add FieldSelector.SelectorHelper with static methods to create selectors - Add SelectorHelperTest - Rename dns.AbstractOption to Option, make other Option classes abstract - Add OptionTest class to resource manager and refactor other OptionTest classes --- .../java/com/google/gcloud/FieldSelector.java | 68 +++++++++++++++++- .../com/google/gcloud/SelectorHelperTest.java | 71 +++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 google-cloud-core/src/test/java/com/google/gcloud/SelectorHelperTest.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java index 358c4d4798..343f67e338 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java @@ -16,9 +16,18 @@ package com.google.gcloud; +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; + /** * Interface for Google Cloud resource's fields. Implementations of this interface can be used to - * select only desired fields when getting or listing Google Cloud resources. + * select only desired fields from a returned Google Cloud resource. */ public interface FieldSelector { @@ -27,4 +36,61 @@ public interface FieldSelector { * other field selectors) to specify which resource fields should be returned by an API call. */ String selector(); + + /** + * A helper class used to build composite selectors given a number of fields. This class is not + * supposed to be used directly by users. + */ + class SelectorHelper { + + private SelectorHelper() {} + + private static final Function FIELD_TO_STRING_FUNCTION = + new Function() { + @Override + public String apply(FieldSelector fieldSelector) { + return fieldSelector.selector(); + } + }; + + private static String selector(List required, FieldSelector[] others, + String... extraResourceFields) { + Set fieldStrings = Sets.newHashSetWithExpectedSize(required.size() + others.length); + fieldStrings.addAll(Lists.transform(required, FIELD_TO_STRING_FUNCTION)); + fieldStrings.addAll(Lists.transform(Arrays.asList(others), FIELD_TO_STRING_FUNCTION)); + fieldStrings.addAll(Arrays.asList(extraResourceFields)); + return Joiner.on(',').join(fieldStrings); + } + + /** + * Returns a composite selector given a number of fields. The string selector returned by this + * method can be used for field selection in API calls that return a single resource. This + * method is not supposed to be used directly by users. + */ + public static String selector(List required, FieldSelector... others) { + return selector(required, others, new String[]{}); + } + + /** + * Returns a composite selector given a number of fields and a container name. The string + * selector returned by this method can be used for field selection in API calls that return a + * list of resources. This method is not supposed to be used directly by users. + */ + public static String selector(String containerName, List required, + FieldSelector... others) { + return "nextPageToken," + containerName + '(' + selector(required, others) + ')'; + } + + /** + * Returns a composite selector given a number of fields and a container name. This methods also + * takes an {@code extraResourceFields} parameter to specify some extra fields as strings. The + * string selector returned by this method can be used for field selection in API calls that + * return a list of resources. This method is not supposed to be used directly by users. + */ + public static String selector(String containerName, List required, + FieldSelector[] others, String... extraResourceFields) { + return "nextPageToken," + containerName + '(' + + selector(required, others, extraResourceFields) + ')'; + } + } } diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SelectorHelperTest.java b/google-cloud-core/src/test/java/com/google/gcloud/SelectorHelperTest.java new file mode 100644 index 0000000000..2279205539 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/gcloud/SelectorHelperTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import com.google.common.collect.ImmutableList; +import com.google.gcloud.FieldSelector.SelectorHelper; + +import org.junit.Test; + +import java.util.List; + +public class SelectorHelperTest { + + private static final FieldSelector FIELD1 = new FieldSelector() { + @Override + public String selector() { + return "field1"; + } + }; + private static final FieldSelector FIELD2 = new FieldSelector() { + @Override + public String selector() { + return "field2"; + } + }; + private static final FieldSelector FIELD3 = new FieldSelector() { + @Override + public String selector() { + return "field3"; + } + }; + private static final List REQUIRED_FIELDS = ImmutableList.of(FIELD1, FIELD2); + private static final String CONTAINER = "container"; + + @Test + public void testSelector() { + String selector = SelectorHelper.selector(REQUIRED_FIELDS, FIELD3); + assertTrue(selector.contains("field1")); + assertTrue(selector.contains("field2")); + assertTrue(selector.contains("field3")); + assertEquals(20, selector.length()); + } + + @Test + public void testListSelector() { + String selector = SelectorHelper.selector(CONTAINER, REQUIRED_FIELDS, FIELD3); + assertTrue(selector.startsWith("nextPageToken,container(")); + assertTrue(selector.contains("field1")); + assertTrue(selector.contains("field2")); + assertTrue(selector.contains("field3")); + assertTrue(selector.endsWith(")")); + assertEquals(45, selector.length()); + } +} From 11fb97fdf97ab1b4beee9a17b13727374afbf58f Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 30 Mar 2016 22:42:29 +0200 Subject: [PATCH 151/663] Minor refactoring for SelectorHelper - Rename selector method for lists to listSelector - Update selectors to accept List parameters - Add missing unit test for listSelector - Remove redundant extends Serializable from dns' option classes --- .../java/com/google/gcloud/FieldSelector.java | 12 +++++------ ...Test.java => FieldSelectorHelperTest.java} | 21 +++++++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) rename google-cloud-core/src/test/java/com/google/gcloud/{SelectorHelperTest.java => FieldSelectorHelperTest.java} (72%) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java index 343f67e338..be6ab73d00 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java @@ -41,9 +41,9 @@ public interface FieldSelector { * A helper class used to build composite selectors given a number of fields. This class is not * supposed to be used directly by users. */ - class SelectorHelper { + class Helper { - private SelectorHelper() {} + private Helper() {} private static final Function FIELD_TO_STRING_FUNCTION = new Function() { @@ -53,7 +53,7 @@ public String apply(FieldSelector fieldSelector) { } }; - private static String selector(List required, FieldSelector[] others, + private static String selector(List required, FieldSelector[] others, String... extraResourceFields) { Set fieldStrings = Sets.newHashSetWithExpectedSize(required.size() + others.length); fieldStrings.addAll(Lists.transform(required, FIELD_TO_STRING_FUNCTION)); @@ -67,7 +67,7 @@ private static String selector(List required, FieldSelector[] oth * method can be used for field selection in API calls that return a single resource. This * method is not supposed to be used directly by users. */ - public static String selector(List required, FieldSelector... others) { + public static String selector(List required, FieldSelector... others) { return selector(required, others, new String[]{}); } @@ -76,7 +76,7 @@ public static String selector(List required, FieldSelector... oth * selector returned by this method can be used for field selection in API calls that return a * list of resources. This method is not supposed to be used directly by users. */ - public static String selector(String containerName, List required, + public static String listSelector(String containerName, List required, FieldSelector... others) { return "nextPageToken," + containerName + '(' + selector(required, others) + ')'; } @@ -87,7 +87,7 @@ public static String selector(String containerName, List required * string selector returned by this method can be used for field selection in API calls that * return a list of resources. This method is not supposed to be used directly by users. */ - public static String selector(String containerName, List required, + public static String listSelector(String containerName, List required, FieldSelector[] others, String... extraResourceFields) { return "nextPageToken," + containerName + '(' + selector(required, others, extraResourceFields) + ')'; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SelectorHelperTest.java b/google-cloud-core/src/test/java/com/google/gcloud/FieldSelectorHelperTest.java similarity index 72% rename from google-cloud-core/src/test/java/com/google/gcloud/SelectorHelperTest.java rename to google-cloud-core/src/test/java/com/google/gcloud/FieldSelectorHelperTest.java index 2279205539..9871c94218 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/SelectorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/FieldSelectorHelperTest.java @@ -20,13 +20,13 @@ import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableList; -import com.google.gcloud.FieldSelector.SelectorHelper; +import com.google.gcloud.FieldSelector.Helper; import org.junit.Test; import java.util.List; -public class SelectorHelperTest { +public class FieldSelectorHelperTest { private static final FieldSelector FIELD1 = new FieldSelector() { @Override @@ -51,7 +51,7 @@ public String selector() { @Test public void testSelector() { - String selector = SelectorHelper.selector(REQUIRED_FIELDS, FIELD3); + String selector = Helper.selector(REQUIRED_FIELDS, FIELD3); assertTrue(selector.contains("field1")); assertTrue(selector.contains("field2")); assertTrue(selector.contains("field3")); @@ -60,7 +60,7 @@ public void testSelector() { @Test public void testListSelector() { - String selector = SelectorHelper.selector(CONTAINER, REQUIRED_FIELDS, FIELD3); + String selector = Helper.listSelector(CONTAINER, REQUIRED_FIELDS, FIELD3); assertTrue(selector.startsWith("nextPageToken,container(")); assertTrue(selector.contains("field1")); assertTrue(selector.contains("field2")); @@ -68,4 +68,17 @@ public void testListSelector() { assertTrue(selector.endsWith(")")); assertEquals(45, selector.length()); } + + @Test + public void testListSelectorWithExtraFields() { + String selector = Helper.listSelector(CONTAINER, REQUIRED_FIELDS, + new FieldSelector[]{FIELD3}, "field4"); + assertTrue(selector.startsWith("nextPageToken,container(")); + assertTrue(selector.contains("field1")); + assertTrue(selector.contains("field2")); + assertTrue(selector.contains("field3")); + assertTrue(selector.contains("field4")); + assertTrue(selector.endsWith(")")); + assertEquals(52, selector.length()); + } } From 7829228e8026edc887856eb814d6056019c34480 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 1 Apr 2016 00:28:12 +0200 Subject: [PATCH 152/663] Get projectId from gcloud active config --- .../java/com/google/gcloud/ServiceOptions.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index d45069434a..1c5289bbcd 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -27,6 +27,7 @@ import com.google.api.client.http.javanet.NetHttpTransport; import com.google.auth.http.HttpCredentialsAdapter; import com.google.common.collect.Iterables; +import com.google.common.io.Files; import com.google.gcloud.spi.ServiceRpcFactory; import java.io.BufferedReader; @@ -42,6 +43,7 @@ import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.charset.Charset; import java.util.Enumeration; import java.util.Locale; import java.util.Objects; @@ -381,6 +383,18 @@ protected String defaultProject() { return projectId != null ? projectId : googleCloudProjectId(); } + private static String activeGoogleCloudConfig(File configDir) { + String activeGoogleCloudConfig = null; + try { + activeGoogleCloudConfig = + Files.readFirstLine(new File(configDir, "active_config"), Charset.defaultCharset()); + } catch (IOException ex) { + // ignore + } + // if reading active_config failed or the file is empty we try default + return firstNonNull(activeGoogleCloudConfig, "default"); + } + protected static String googleCloudProjectId() { File configDir; if (System.getenv().containsKey("CLOUDSDK_CONFIG")) { @@ -390,9 +404,10 @@ protected static String googleCloudProjectId() { } else { configDir = new File(System.getProperty("user.home"), ".config/gcloud"); } + String activeConfig = activeGoogleCloudConfig(configDir); FileReader fileReader = null; try { - fileReader = new FileReader(new File(configDir, "configurations/config_default")); + fileReader = new FileReader(new File(configDir, "configurations/config_" + activeConfig)); } catch (FileNotFoundException newConfigFileNotFoundEx) { try { fileReader = new FileReader(new File(configDir, "properties")); From e4a9722105e062a2e5cac36ac24b81c503d66ff8 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 1 Apr 2016 13:46:59 -0700 Subject: [PATCH 153/663] Release 0.1.7 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 13e170e061..7d6b9c8887 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -10,7 +10,7 @@ com.google.gcloud gcloud-java-pom - 0.1.7-SNAPSHOT + 0.1.7 gcloud-java-core From 5327d370f18a5ca10574c034740222b3d975ead6 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Fri, 1 Apr 2016 23:24:02 +0000 Subject: [PATCH 154/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 1ee96b9504..067505179b 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.gcloud gcloud-java-core - 0.1.6 + 0.1.7 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:0.1.6' +compile 'com.google.gcloud:gcloud-java-core:0.1.7' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.6" +libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.7" ``` Troubleshooting From c384cd5ac1ee49586c7f2bce7157a16a9f6edf4b Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 1 Apr 2016 17:05:26 -0700 Subject: [PATCH 155/663] Update to version 0.1.8-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7d6b9c8887..df116b0b1b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -10,7 +10,7 @@ com.google.gcloud gcloud-java-pom - 0.1.7 + 0.1.8-SNAPSHOT gcloud-java-core From 89467ff0c93dfaa4cdb8b65ed7b3ffc64bfffae9 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 4 Apr 2016 18:29:44 +0200 Subject: [PATCH 156/663] Extract projectId from GOOGLE_APPLICATION_CREDENTIALS if set * Extract projectId from GOOGLE_APPLICATION_CREDENTIALS if set * First look for AE's project id, then GOOGLE_APPLICATION_CREDENTIALS' --- .../com/google/gcloud/ServiceOptions.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 1c5289bbcd..d53cfcdafe 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -30,8 +30,13 @@ import com.google.common.io.Files; import com.google.gcloud.spi.ServiceRpcFactory; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONTokener; + import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; @@ -378,7 +383,10 @@ protected String defaultHost() { protected String defaultProject() { String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); if (projectId == null) { - projectId = getAppEngineProjectId(); + projectId = appEngineProjectId(); + } + if (projectId == null) { + projectId = serviceAccountProjectId(); } return projectId != null ? projectId : googleCloudProjectId(); } @@ -461,7 +469,7 @@ private static boolean isWindows() { return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"); } - protected static String getAppEngineProjectId() { + protected static String appEngineProjectId() { try { Class factoryClass = Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory"); @@ -479,6 +487,20 @@ protected static String getAppEngineProjectId() { } } + protected static String serviceAccountProjectId() { + String project = null; + String credentialsPath = System.getenv("GOOGLE_APPLICATION_CREDENTIALS"); + if(credentialsPath != null) { + try (InputStream credentialsStream = new FileInputStream(credentialsPath)) { + JSONObject json = new JSONObject(new JSONTokener(credentialsStream)); + project = json.getString("project_id"); + } catch (IOException | JSONException ex) { + // ignore + } + } + return project; + } + @SuppressWarnings("unchecked") public ServiceT service() { if (service == null) { From 53efa081423959281ddfff11fe6837b3b9c0ee5b Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 6 Apr 2016 19:02:58 +0200 Subject: [PATCH 157/663] Add ServiceAccountSigner interface, enable signing for AE credentials --- .../com/google/gcloud/AuthCredentials.java | 104 ++++++++++++++++-- .../google/gcloud/ServiceAccountSigner.java | 67 +++++++++++ .../com/google/gcloud/SerializationTest.java | 49 +++++---- 3 files changed, 187 insertions(+), 33 deletions(-) create mode 100644 google-cloud-core/src/main/java/com/google/gcloud/ServiceAccountSigner.java diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 27cafc1815..080d49ed3c 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -25,8 +25,13 @@ import java.io.IOException; import java.io.InputStream; import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; +import java.security.Signature; +import java.security.SignatureException; import java.util.Collection; import java.util.Objects; @@ -35,16 +40,26 @@ */ public abstract class AuthCredentials implements Restorable { - private static class AppEngineAuthCredentials extends AuthCredentials { + /** + * Represents built-in credentials when running in Google App Engine. + */ + public static class AppEngineAuthCredentials extends AuthCredentials + implements ServiceAccountSigner { private static final AuthCredentials INSTANCE = new AppEngineAuthCredentials(); private static final AppEngineAuthCredentialsState STATE = new AppEngineAuthCredentialsState(); - private static class AppEngineCredentials extends GoogleCredentials { + private AppEngineCredentials credentials; + + private static class AppEngineCredentials extends GoogleCredentials + implements ServiceAccountSigner { private final Object appIdentityService; + private final String account; private final Method getAccessToken; private final Method getAccessTokenResult; + private final Method signForApp; + private final Method getSignature; private final Collection scopes; AppEngineCredentials() { @@ -59,6 +74,12 @@ private static class AppEngineCredentials extends GoogleCredentials { "com.google.appengine.api.appidentity.AppIdentityService$GetAccessTokenResult"); this.getAccessTokenResult = serviceClass.getMethod("getAccessToken", Iterable.class); this.getAccessToken = tokenResultClass.getMethod("getAccessToken"); + this.account = (String) serviceClass.getMethod("getServiceAccountName") + .invoke(appIdentityService); + this.signForApp = serviceClass.getMethod("signForApp", byte[].class); + Class signingResultClass = Class.forName( + "com.google.appengine.api.appidentity.AppIdentityService$SigningResult"); + this.getSignature = signingResultClass.getMethod("getSignature"); this.scopes = null; } catch (Exception e) { throw new RuntimeException("Could not create AppEngineCredentials.", e); @@ -69,11 +90,14 @@ private static class AppEngineCredentials extends GoogleCredentials { this.appIdentityService = unscoped.appIdentityService; this.getAccessToken = unscoped.getAccessToken; this.getAccessTokenResult = unscoped.getAccessTokenResult; + this.account = unscoped.account; + this.signForApp = unscoped.signForApp; + this.getSignature = unscoped.getSignature; this.scopes = scopes; } /** - * Refresh the access token by getting it from the App Identity service + * Refresh the access token by getting it from the App Identity service. */ @Override public AccessToken refreshAccessToken() throws IOException { @@ -98,6 +122,21 @@ public boolean createScopedRequired() { public GoogleCredentials createScoped(Collection scopes) { return new AppEngineCredentials(scopes, this); } + + @Override + public String account() { + return account; + } + + @Override + public byte[] sign(byte[] toSign) { + try { + Object signingResult = signForApp.invoke(appIdentityService, (Object) toSign); + return (byte[]) getSignature.invoke(signingResult); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + throw new SigningException("Failed to sign the provided bytes", ex); + } + } } private static class AppEngineAuthCredentialsState @@ -122,14 +161,27 @@ public boolean equals(Object obj) { } @Override - public GoogleCredentials credentials() { - return new AppEngineCredentials(); + public AppEngineCredentials credentials() { + if (credentials == null) { + credentials = new AppEngineCredentials(); + } + return credentials; } @Override public RestorableState capture() { return STATE; } + + @Override + public String account() { + return credentials().account(); + } + + @Override + public byte[] sign(byte[] toSign) { + return credentials().sign(toSign); + } } /** @@ -138,8 +190,10 @@ public RestorableState capture() { * @see * User accounts and service accounts */ - public static class ServiceAccountAuthCredentials extends AuthCredentials { + public static class ServiceAccountAuthCredentials extends AuthCredentials + implements ServiceAccountSigner { + private final ServiceAccountCredentials credentials; private final String account; private final PrivateKey privateKey; @@ -178,23 +232,44 @@ public boolean equals(Object obj) { } ServiceAccountAuthCredentials(String account, PrivateKey privateKey) { - this.account = checkNotNull(account); - this.privateKey = checkNotNull(privateKey); + this(new ServiceAccountCredentials(null, account, privateKey, null, null)); + } + + ServiceAccountAuthCredentials(ServiceAccountCredentials credentials) { + this.credentials = checkNotNull(credentials); + this.account = checkNotNull(credentials.getClientEmail()); + this.privateKey = checkNotNull(credentials.getPrivateKey()); } @Override public ServiceAccountCredentials credentials() { - return new ServiceAccountCredentials(null, account, privateKey, null, null); + return credentials; } + @Override public String account() { return account; } + /** + * Returns the private key associated with the service account credentials. + */ public PrivateKey privateKey() { return privateKey; } + @Override + public byte[] sign(byte[] toSign) { + try { + Signature signer = Signature.getInstance("SHA256withRSA"); + signer.initSign(privateKey()); + signer.update(toSign); + return signer.sign(); + } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException ex) { + throw new SigningException("Failed to sign the provided bytes", ex); + } + } + @Override public RestorableState capture() { return new ServiceAccountAuthCredentialsState(account, privateKey); @@ -242,6 +317,10 @@ public boolean equals(Object obj) { } } + ApplicationDefaultAuthCredentials(GoogleCredentials credentials) { + googleCredentials = credentials; + } + ApplicationDefaultAuthCredentials() throws IOException { googleCredentials = GoogleCredentials.getApplicationDefault(); } @@ -320,7 +399,12 @@ public static AuthCredentials createForAppEngine() { * @throws IOException if the credentials cannot be created in the current environment */ public static AuthCredentials createApplicationDefaults() throws IOException { - return new ApplicationDefaultAuthCredentials(); + GoogleCredentials credentials = GoogleCredentials.getApplicationDefault(); + if (credentials instanceof ServiceAccountCredentials) { + ServiceAccountCredentials serviceAccountCredentials = (ServiceAccountCredentials) credentials; + return new ServiceAccountAuthCredentials(serviceAccountCredentials); + } + return new ApplicationDefaultAuthCredentials(credentials); } /** diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceAccountSigner.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceAccountSigner.java new file mode 100644 index 0000000000..2456d85e98 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceAccountSigner.java @@ -0,0 +1,67 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud; + +import java.util.Objects; + +/** + * Interface for a service account signer. A signer for a service account is capable of signing + * bytes using the private key associated with its service account. + */ +public interface ServiceAccountSigner { + + class SigningException extends RuntimeException { + + private static final long serialVersionUID = 8962780757822799255L; + + SigningException(String message, Exception cause) { + super(message, cause); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof SigningException)) { + return false; + } + SigningException other = (SigningException) obj; + return Objects.equals(getCause(), other.getCause()) + && Objects.equals(getMessage(), other.getMessage()); + } + + @Override + public int hashCode() { + return Objects.hash(getMessage(), getCause()); + } + } + + /** + * Returns the service account associated with the signer. + */ + String account(); + + /** + * Signs the provided bytes using the private key associated with the service account. + * + * @param toSign bytes to sign + * @return signed bytes + * @throws SigningException if the attempt to sign the provided bytes failed + */ + byte[] sign(byte[] toSign); +} diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java index 3255a17333..8cf58f554d 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java @@ -17,6 +17,7 @@ package com.google.gcloud; import com.google.common.collect.ImmutableList; +import com.google.gcloud.ServiceAccountSigner.SigningException; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -24,34 +25,14 @@ public class SerializationTest extends BaseSerializationTest { - private static class SomeIamPolicy extends IamPolicy { - - private static final long serialVersionUID = 271243551016958285L; - - private static class Builder extends IamPolicy.Builder { - - @Override - public SomeIamPolicy build() { - return new SomeIamPolicy(this); - } - } - - protected SomeIamPolicy(Builder builder) { - super(builder); - } - - @Override - public Builder toBuilder() { - return new Builder(); - } - } - private static final BaseServiceException BASE_SERVICE_EXCEPTION = new BaseServiceException(42, "message", "reason", true); private static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.defaultInstance(); private static final Identity IDENTITY = Identity.allAuthenticatedUsers(); private static final PageImpl PAGE = new PageImpl<>(null, "cursor", ImmutableList.of("string1", "string2")); + private static final SigningException SIGNING_EXCEPTION = + new SigningException("message", BASE_SERVICE_EXCEPTION); private static final RetryParams RETRY_PARAMS = RetryParams.defaultInstance(); private static final SomeIamPolicy SOME_IAM_POLICY = new SomeIamPolicy.Builder().build(); private static final String JSON_KEY = "{\n" @@ -81,10 +62,32 @@ public Builder toBuilder() { + " \"type\": \"service_account\"\n" + "}"; + private static class SomeIamPolicy extends IamPolicy { + + private static final long serialVersionUID = 271243551016958285L; + + private static class Builder extends IamPolicy.Builder { + + @Override + public SomeIamPolicy build() { + return new SomeIamPolicy(this); + } + } + + protected SomeIamPolicy(Builder builder) { + super(builder); + } + + @Override + public Builder toBuilder() { + return new Builder(); + } + } + @Override protected Serializable[] serializableObjects() { return new Serializable[]{BASE_SERVICE_EXCEPTION, EXCEPTION_HANDLER, IDENTITY, PAGE, - RETRY_PARAMS, SOME_IAM_POLICY}; + RETRY_PARAMS, SOME_IAM_POLICY, SIGNING_EXCEPTION}; } @Override From 4d2a3fac2561543947f30815ea9e260e6ac22784 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 7 Apr 2016 18:05:45 +0200 Subject: [PATCH 158/663] Fix checkstyle issues in gcloud-java-core (#871) * Fix checkstyle issues in gcloud-java-core --- .../main/java/com/google/gcloud/FieldSelector.java | 2 +- .../src/main/java/com/google/gcloud/Page.java | 7 +++---- .../src/main/java/com/google/gcloud/Restorable.java | 5 ++--- .../java/com/google/gcloud/RestorableState.java | 2 +- .../main/java/com/google/gcloud/ServiceOptions.java | 13 ++++++------- .../com/google/gcloud/spi/ServiceRpcFactory.java | 6 ++---- .../com/google/gcloud/BaseWriteChannelTest.java | 4 ++-- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java index be6ab73d00..fc6e772420 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java @@ -54,7 +54,7 @@ public String apply(FieldSelector fieldSelector) { }; private static String selector(List required, FieldSelector[] others, - String... extraResourceFields) { + String... extraResourceFields) { Set fieldStrings = Sets.newHashSetWithExpectedSize(required.size() + others.length); fieldStrings.addAll(Lists.transform(required, FIELD_TO_STRING_FUNCTION)); fieldStrings.addAll(Lists.transform(Arrays.asList(others), FIELD_TO_STRING_FUNCTION)); diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Page.java b/google-cloud-core/src/main/java/com/google/gcloud/Page.java index 53f3a3842a..fe192c0c0c 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Page.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/Page.java @@ -21,8 +21,7 @@ /** * Interface for Google Cloud paginated results. * - *

    - * Use {@code Page} to iterate through all values (also in next pages): + *

    Use {@code Page} to iterate through all values (also in next pages): *

     {@code
      * Page page = ...; // get a Page instance
      * Iterator iterator = page.iterateAll();
    @@ -30,8 +29,8 @@
      *   T value = iterator.next();
      *   // do something with value
      * }}
    - *

    - * Or handle pagination explicitly: + * + *

    Or handle pagination explicitly: *

     {@code
      * Page page = ...; // get a Page instance
      * while (page != null) {
    diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java
    index 0b573522e3..d92c70eb98 100644
    --- a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java
    +++ b/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java
    @@ -19,15 +19,14 @@
     /**
      * Implementation of this interface can persist their state and restore from it.
      *
    - * 

    - * A typical capture usage: + *

    A typical capture usage: *

     {@code
      * X restorableObj; // X instanceof Restorable
      * RestorableState state = restorableObj.capture();
      * .. persist state
      * }
    * - * A typical restore usage: + *

    A typical restore usage: *

     {@code
      * RestorableState state = ... // read from persistence
      * X restorableObj = state.restore();
    diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java b/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java
    index d6ce736ae8..009a86e545 100644
    --- a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java
    +++ b/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java
    @@ -20,7 +20,7 @@
      * A common interface for restorable states. Implementations of {@code RestorableState} are capable
      * of saving the state of an object to restore it for later use.
      *
    - * Implementations of this class must implement {@link java.io.Serializable} to ensure that the
    + * 

    Implementations of this class must implement {@link java.io.Serializable} to ensure that the * state of a the object can be correctly serialized. * * @param the restored object's type diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index d53cfcdafe..6a8656fcfa 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -100,8 +100,8 @@ public abstract class ServiceOptions, Service /** * A base interface for all {@link HttpTransport} factories. * - * Implementation must provide a public no-arg constructor. Loading of a factory implementation is - * done via {@link java.util.ServiceLoader}. + *

    Implementation must provide a public no-arg constructor. Loading of a factory implementation + * is done via {@link java.util.ServiceLoader}. */ public interface HttpTransportFactory { HttpTransport create(); @@ -129,7 +129,7 @@ public HttpTransport create() { * A class providing access to the current time in milliseconds. This class is mainly used for * testing and will be replaced by Java8's {@code java.time.Clock}. * - * Implementations should implement {@code Serializable} wherever possible and must document + *

    Implementations should implement {@code Serializable} wherever possible and must document * whether or not they do support serialization. */ public abstract static class Clock { @@ -490,7 +490,7 @@ protected static String appEngineProjectId() { protected static String serviceAccountProjectId() { String project = null; String credentialsPath = System.getenv("GOOGLE_APPLICATION_CREDENTIALS"); - if(credentialsPath != null) { + if (credentialsPath != null) { try (InputStream credentialsStream = new FileInputStream(credentialsPath)) { JSONObject json = new JSONObject(new JSONTokener(credentialsStream)); project = json.getString("project_id"); @@ -518,9 +518,8 @@ public ServiceRpcT rpc() { } /** - * Returns the project id. - * - * Return value can be null (for services that don't require a project id). + * Returns the project id. Return value can be null (for services that don't require a project + * id). */ public String projectId() { return projectId; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java index d19f6047e4..8ee964ca8f 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java @@ -19,10 +19,8 @@ import com.google.gcloud.ServiceOptions; /** - * A base interface for all service RPC factories. - * - * Implementation must provide a public no-arg constructor. - * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. + * A base interface for all service RPC factories. Implementation must provide a public no-arg + * constructor. Loading of a factory implementation is done via {@link java.util.ServiceLoader}. */ @SuppressWarnings("rawtypes") public interface ServiceRpcFactory { diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java index 6d5306a3bc..b44157b655 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java @@ -82,7 +82,7 @@ protected BaseState.Builder stateBuilder() { } @Test - public void testConstructor() throws IOException { + public void testConstructor() { assertEquals(null, channel.options()); assertEquals(ENTITY, channel.entity()); assertEquals(0, channel.position()); @@ -108,7 +108,7 @@ public void testValidateOpen() throws IOException { } @Test - public void testChunkSize() throws IOException { + public void testChunkSize() { channel.chunkSize(42); assertEquals(MIN_CHUNK_SIZE, channel.chunkSize()); channel.chunkSize(2 * MIN_CHUNK_SIZE); From 1f06bfd7f150e6bbf30ea14ea7761859271e25fe Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 7 Apr 2016 09:36:54 -0700 Subject: [PATCH 159/663] Add default retry params that align with SLA (#860) * Add default retry params that align with SLA * modify default retry params to conform with datastore, storage, and bigquery sla * Javadoc adjustments --- .../java/com/google/gcloud/RetryParams.java | 21 +++++++++++++++---- .../com/google/gcloud/ServiceOptions.java | 11 +++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java b/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java index ab3644c6d7..0b7381b9c3 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java @@ -48,12 +48,16 @@ public final class RetryParams implements Serializable { private static final long serialVersionUID = -8492751576749007700L; + /** + * Note that App Engine Standard Environment front-end modules have a 60 second deadline for HTTP + * requests. For that reason, we set the default total retry period to less than 60 seconds. + */ + public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L; public static final int DEFAULT_RETRY_MIN_ATTEMPTS = 3; public static final int DEFAULT_RETRY_MAX_ATTEMPTS = 6; - public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 250L; - public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 10_000L; + public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 1000L; + public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 32_000L; public static final double DEFAULT_RETRY_DELAY_BACKOFF_FACTOR = 2.0; - public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L; private final int retryMinAttempts; private final int retryMaxAttempts; @@ -62,6 +66,9 @@ public final class RetryParams implements Serializable { private final double retryDelayBackoffFactor; private final long totalRetryPeriodMillis; + // Some services may have different backoff requirements listed in their SLAs. Be sure to override + // ServiceOptions.defaultRetryParams() in options subclasses when the service's backoff + // requirement differs from the default parameters used here. private static final RetryParams DEFAULT_INSTANCE = new RetryParams(new Builder()); private static final RetryParams NO_RETRIES = builder().retryMaxAttempts(1).retryMinAttempts(1).build(); @@ -156,7 +163,9 @@ public Builder retryDelayBackoffFactor(double retryDelayBackoffFactor) { } /** - * Sets totalRetryPeriodMillis. + * Sets totalRetryPeriodMillis. Note that App Engine Standard Environment front-end modules have + * a 60 second deadline for HTTP requests. For that reason, you should set the total retry + * period to under 60 seconds if you are using it on an App Engine front-end module. * * @param totalRetryPeriodMillis the totalRetryPeriodMillis to set * @return the Builder for chaining @@ -295,4 +304,8 @@ public String toString() { public static Builder builder() { return new Builder(); } + + public Builder toBuilder() { + return new Builder(this); + } } diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index 6a8656fcfa..c523b1f34a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -333,7 +333,7 @@ protected ServiceOptions(Class> ser authCredentials = builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials(); authCredentialsState = authCredentials != null ? authCredentials.capture() : null; - retryParams = firstNonNull(builder.retryParams, RetryParams.defaultInstance()); + retryParams = firstNonNull(builder.retryParams, defaultRetryParams()); serviceFactory = firstNonNull(builder.serviceFactory, getFromServiceLoader(serviceFactoryClass, defaultServiceFactory())); serviceFactoryClassName = serviceFactory.getClass().getName(); @@ -654,6 +654,15 @@ private static T newInstance(String className) throws IOException, ClassNotF public abstract > B toBuilder(); + /** + * Some services may have different backoff requirements listed in their SLAs. Be sure to override + * this method in options subclasses when the service's backoff requirement differs from the + * default parameters listed in {@link RetryParams}. + */ + protected RetryParams defaultRetryParams() { + return RetryParams.defaultInstance(); + } + private static T getFromServiceLoader(Class clazz, T defaultInstance) { return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance); } From 7b59795a627a1f1ec7869cdc30dbb97fedd49ab9 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Fri, 8 Apr 2016 09:20:01 -0700 Subject: [PATCH 160/663] Clean up LocalGcdHelper and docs (#821) * Cleans up local gcd helper and docs to be more consistent with other test helpers * Renames LocalGcdHelper to LocalDatastoreHelper and RemoteGcsHelper to RemoteStorageHelper * Updates the gcd.sh script version --- .../src/main/java/com/google/gcloud/AuthCredentials.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 080d49ed3c..18370ec01f 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -339,7 +339,7 @@ public RestorableState capture() { /** * A placeholder for credentials to signify that requests sent to the server should not be * authenticated. This is typically useful when using the local service emulators, such as - * {@code LocalGcdHelper} and {@code LocalResourceManagerHelper}. + * {@code LocalDatastoreHelper} and {@code LocalResourceManagerHelper}. */ public static class NoAuthCredentials extends AuthCredentials { @@ -425,7 +425,7 @@ public static ServiceAccountAuthCredentials createFor(String account, PrivateKey /** * Creates a placeholder denoting that no credentials should be used. This is typically useful - * when using the local service emulators, such as {@code LocalGcdHelper} and + * when using the local service emulators, such as {@code LocalDatastoreHelper} and * {@code LocalResourceManagerHelper}. */ public static AuthCredentials noAuth() { From 65c70d24f1a1f048f09fff5e7639ee8a75689a92 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Sat, 9 Apr 2016 00:36:02 +0200 Subject: [PATCH 161/663] Suppress unchecked warning for defaultServiceFactory, defaultRpcFactory and toBuilder (#881) --- .../src/main/java/com/google/gcloud/ServiceOptions.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java index c523b1f34a..5f47b2cd05 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -646,9 +646,9 @@ private static T newInstance(String className) throws IOException, ClassNotF } } - protected abstract > T defaultServiceFactory(); + protected abstract ServiceFactory defaultServiceFactory(); - protected abstract > T defaultRpcFactory(); + protected abstract ServiceRpcFactory defaultRpcFactory(); protected abstract Set scopes(); From d5cdca2e6528b482e39a9bcda91d80a63dbfc7fe Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 11 Apr 2016 14:29:14 -0700 Subject: [PATCH 162/663] Add expiration date to App Engine credentials (#894) --- .../src/main/java/com/google/gcloud/AuthCredentials.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java index 18370ec01f..4cd424bed9 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -33,6 +33,7 @@ import java.security.Signature; import java.security.SignatureException; import java.util.Collection; +import java.util.Date; import java.util.Objects; /** @@ -58,6 +59,7 @@ private static class AppEngineCredentials extends GoogleCredentials private final String account; private final Method getAccessToken; private final Method getAccessTokenResult; + private final Method getExpirationTime; private final Method signForApp; private final Method getSignature; private final Collection scopes; @@ -74,6 +76,7 @@ private static class AppEngineCredentials extends GoogleCredentials "com.google.appengine.api.appidentity.AppIdentityService$GetAccessTokenResult"); this.getAccessTokenResult = serviceClass.getMethod("getAccessToken", Iterable.class); this.getAccessToken = tokenResultClass.getMethod("getAccessToken"); + this.getExpirationTime = tokenResultClass.getMethod("getExpirationTime"); this.account = (String) serviceClass.getMethod("getServiceAccountName") .invoke(appIdentityService); this.signForApp = serviceClass.getMethod("signForApp", byte[].class); @@ -90,6 +93,7 @@ private static class AppEngineCredentials extends GoogleCredentials this.appIdentityService = unscoped.appIdentityService; this.getAccessToken = unscoped.getAccessToken; this.getAccessTokenResult = unscoped.getAccessTokenResult; + this.getExpirationTime = unscoped.getExpirationTime; this.account = unscoped.account; this.signForApp = unscoped.signForApp; this.getSignature = unscoped.getSignature; @@ -107,7 +111,8 @@ public AccessToken refreshAccessToken() throws IOException { try { Object accessTokenResult = getAccessTokenResult.invoke(appIdentityService, scopes); String accessToken = (String) getAccessToken.invoke(accessTokenResult); - return new AccessToken(accessToken, null); + Date expirationTime = (Date) getExpirationTime.invoke(accessTokenResult); + return new AccessToken(accessToken, expirationTime); } catch (Exception e) { throw new IOException("Could not get the access token.", e); } @@ -131,7 +136,7 @@ public String account() { @Override public byte[] sign(byte[] toSign) { try { - Object signingResult = signForApp.invoke(appIdentityService, (Object) toSign); + Object signingResult = signForApp.invoke(appIdentityService, toSign); return (byte[]) getSignature.invoke(signingResult); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new SigningException("Failed to sign the provided bytes", ex); From db0e2dd73ef7182ddc94580347ff8cb9f5979d4d Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 12 Apr 2016 11:04:17 -0700 Subject: [PATCH 163/663] Rename com.google.gcloud to com.google.cloud (#899) * Rename com.google.gcloud to com.google.cloud * Update readmes with package name change * Fix links in readmes * Update link used to check for artifact deployment --- google-cloud-core/README.md | 10 +++++----- google-cloud-core/pom.xml | 2 +- .../{gcloud => cloud}/AuthCredentials.java | 2 +- .../google/{gcloud => cloud}/BaseService.java | 4 ++-- .../{gcloud => cloud}/BaseServiceException.java | 2 +- .../{gcloud => cloud}/BaseWriteChannel.java | 2 +- .../{gcloud => cloud}/ExceptionHandler.java | 2 +- .../google/{gcloud => cloud}/FieldSelector.java | 2 +- .../com/google/{gcloud => cloud}/IamPolicy.java | 2 +- .../com/google/{gcloud => cloud}/Identity.java | 2 +- .../java/com/google/{gcloud => cloud}/Page.java | 2 +- .../com/google/{gcloud => cloud}/PageImpl.java | 2 +- .../google/{gcloud => cloud}/ReadChannel.java | 2 +- .../com/google/{gcloud => cloud}/Restorable.java | 2 +- .../{gcloud => cloud}/RestorableState.java | 2 +- .../google/{gcloud => cloud}/RetryHelper.java | 2 +- .../google/{gcloud => cloud}/RetryParams.java | 2 +- .../com/google/{gcloud => cloud}/Service.java | 2 +- .../{gcloud => cloud}/ServiceAccountSigner.java | 2 +- .../google/{gcloud => cloud}/ServiceFactory.java | 2 +- .../google/{gcloud => cloud}/ServiceOptions.java | 4 ++-- .../google/{gcloud => cloud}/WriteChannel.java | 2 +- .../google/{gcloud => cloud}/package-info.java | 2 +- .../{gcloud => cloud}/spi/ServiceRpcFactory.java | 4 ++-- .../{gcloud => cloud}/BaseSerializationTest.java | 2 +- .../BaseServiceExceptionTest.java | 4 ++-- .../{gcloud => cloud}/BaseWriteChannelTest.java | 4 ++-- .../{gcloud => cloud}/ExceptionHandlerTest.java | 6 +++--- .../FieldSelectorHelperTest.java | 4 ++-- .../google/{gcloud => cloud}/IamPolicyTest.java | 2 +- .../google/{gcloud => cloud}/IdentityTest.java | 2 +- .../google/{gcloud => cloud}/PageImplTest.java | 2 +- .../{gcloud => cloud}/RetryHelperTest.java | 6 +++--- .../{gcloud => cloud}/RetryParamsTest.java | 16 ++++++++-------- .../{gcloud => cloud}/SerializationTest.java | 4 ++-- .../{gcloud => cloud}/ServiceOptionsTest.java | 10 +++++----- 36 files changed, 62 insertions(+), 62 deletions(-) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/AuthCredentials.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/BaseService.java (95%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/BaseServiceException.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/BaseWriteChannel.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/ExceptionHandler.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/FieldSelector.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/IamPolicy.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/Identity.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/Page.java (98%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/PageImpl.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/ReadChannel.java (98%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/Restorable.java (98%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/RestorableState.java (97%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/RetryHelper.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/RetryParams.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/Service.java (96%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/ServiceAccountSigner.java (98%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/ServiceFactory.java (97%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/ServiceOptions.java (99%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/WriteChannel.java (98%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/package-info.java (96%) rename google-cloud-core/src/main/java/com/google/{gcloud => cloud}/spi/ServiceRpcFactory.java (93%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/BaseSerializationTest.java (99%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/BaseServiceExceptionTest.java (98%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/BaseWriteChannelTest.java (98%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/ExceptionHandlerTest.java (97%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/FieldSelectorHelperTest.java (97%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/IamPolicyTest.java (99%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/IdentityTest.java (99%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/PageImplTest.java (98%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/RetryHelperTest.java (98%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/RetryParamsTest.java (87%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/SerializationTest.java (98%) rename google-cloud-core/src/test/java/com/google/{gcloud => cloud}/ServiceOptionsTest.java (97%) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 067505179b..ca34b9789d 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -5,30 +5,30 @@ This module provides common functionality required by service-specific modules o [![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java) [![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master) -[![Maven](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg)](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg) +[![Maven](https://img.shields.io/maven-central/v/com.google.cloud/gcloud-java-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/gcloud-java-core.svg) [![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/gcloud-java) [![Dependency Status](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969) - [Homepage] (https://googlecloudplatform.github.io/gcloud-java/) -- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/package-summary.html) +- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/cloud/package-summary.html) Quickstart ---------- If you are using Maven, add this to your pom.xml file ```xml - com.google.gcloud + com.google.cloud gcloud-java-core 0.1.7 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.gcloud:gcloud-java-core:0.1.7' +compile 'com.google.cloud:gcloud-java-core:0.1.7' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.7" +libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.1.7" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index df116b0b1b..2a164ae328 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -8,7 +8,7 @@ Core module for the gcloud-java. - com.google.gcloud + com.google.cloud gcloud-java-pom 0.1.8-SNAPSHOT diff --git a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java rename to google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java index 4cd424bed9..ec5a631f5f 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java similarity index 95% rename from google-cloud-core/src/main/java/com/google/gcloud/BaseService.java rename to google-cloud-core/src/main/java/com/google/cloud/BaseService.java index d9e6f2db7c..d0476b66c2 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; -import com.google.gcloud.ExceptionHandler.Interceptor; +import com.google.cloud.ExceptionHandler.Interceptor; /** * Base class for service objects. diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java rename to google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index 4e0d03e007..6dc87f4abb 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import com.google.api.client.googleapis.json.GoogleJsonError; import com.google.api.client.googleapis.json.GoogleJsonResponseException; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java rename to google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index 1d18a5a27e..f803cd6bba 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import com.google.common.base.MoreObjects; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java rename to google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java index 0b3c923d1e..e72eb1edcf 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java rename to google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java index fc6e772420..a2b92d752e 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/FieldSelector.java +++ b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import com.google.common.base.Function; import com.google.common.base.Joiner; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/cloud/IamPolicy.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java rename to google-cloud-core/src/main/java/com/google/cloud/IamPolicy.java index 9cce4b23c8..1f214e1b0f 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/IamPolicy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/IamPolicy.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Identity.java b/google-cloud-core/src/main/java/com/google/cloud/Identity.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/Identity.java rename to google-cloud-core/src/main/java/com/google/cloud/Identity.java index 687a76ffc4..fab70dfe6d 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Identity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Page.java b/google-cloud-core/src/main/java/com/google/cloud/Page.java similarity index 98% rename from google-cloud-core/src/main/java/com/google/gcloud/Page.java rename to google-cloud-core/src/main/java/com/google/cloud/Page.java index fe192c0c0c..8881a98b46 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Page.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Page.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import java.util.Iterator; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java rename to google-cloud-core/src/main/java/com/google/cloud/PageImpl.java index 2dc031ab9b..de1a3506b7 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableMap; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ReadChannel.java b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java similarity index 98% rename from google-cloud-core/src/main/java/com/google/gcloud/ReadChannel.java rename to google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java index 7537c5a8ce..2afb8b2d5b 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ReadChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import java.io.Closeable; import java.io.IOException; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java b/google-cloud-core/src/main/java/com/google/cloud/Restorable.java similarity index 98% rename from google-cloud-core/src/main/java/com/google/gcloud/Restorable.java rename to google-cloud-core/src/main/java/com/google/cloud/Restorable.java index d92c70eb98..e2a515c786 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Restorable.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Restorable.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; /** * Implementation of this interface can persist their state and restore from it. diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java b/google-cloud-core/src/main/java/com/google/cloud/RestorableState.java similarity index 97% rename from google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java rename to google-cloud-core/src/main/java/com/google/cloud/RestorableState.java index 009a86e545..4874756527 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RestorableState.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RestorableState.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; /** * A common interface for restorable states. Implementations of {@code RestorableState} are capable diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java rename to google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index 9b9c1f6a31..48bd5fcf93 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static com.google.common.base.Preconditions.checkNotNull; import static java.lang.StrictMath.max; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java b/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java rename to google-cloud-core/src/main/java/com/google/cloud/RetryParams.java index 0b7381b9c3..02ffda1813 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/RetryParams.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static com.google.common.base.Preconditions.checkArgument; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/Service.java b/google-cloud-core/src/main/java/com/google/cloud/Service.java similarity index 96% rename from google-cloud-core/src/main/java/com/google/gcloud/Service.java rename to google-cloud-core/src/main/java/com/google/cloud/Service.java index 60bc26670f..a3797eca30 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/Service.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Service.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; /** * Interface for service objects. diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceAccountSigner.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java similarity index 98% rename from google-cloud-core/src/main/java/com/google/gcloud/ServiceAccountSigner.java rename to google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java index 2456d85e98..c68d14116a 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceAccountSigner.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import java.util.Objects; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java similarity index 97% rename from google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java rename to google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java index 1727e9c397..bb06127c77 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceFactory.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; /** * A base interface for all service factories. diff --git a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java similarity index 99% rename from google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java rename to google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 5f47b2cd05..e08d0cd9d1 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; @@ -28,7 +28,7 @@ import com.google.auth.http.HttpCredentialsAdapter; import com.google.common.collect.Iterables; import com.google.common.io.Files; -import com.google.gcloud.spi.ServiceRpcFactory; +import com.google.cloud.spi.ServiceRpcFactory; import org.json.JSONException; import org.json.JSONObject; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/WriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java similarity index 98% rename from google-cloud-core/src/main/java/com/google/gcloud/WriteChannel.java rename to google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java index e6f06e23dc..636bc60d02 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/WriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import java.io.Closeable; import java.nio.channels.WritableByteChannel; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/package-info.java b/google-cloud-core/src/main/java/com/google/cloud/package-info.java similarity index 96% rename from google-cloud-core/src/main/java/com/google/gcloud/package-info.java rename to google-cloud-core/src/main/java/com/google/cloud/package-info.java index d527640c99..8b548e3d26 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/package-info.java +++ b/google-cloud-core/src/main/java/com/google/cloud/package-info.java @@ -17,4 +17,4 @@ /** * Core classes for the {@code gcloud-java} library. */ -package com.google.gcloud; +package com.google.cloud; diff --git a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java b/google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java similarity index 93% rename from google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java rename to google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java index 8ee964ca8f..21a061f4a5 100644 --- a/google-cloud-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java +++ b/google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.gcloud.spi; +package com.google.cloud.spi; -import com.google.gcloud.ServiceOptions; +import com.google.cloud.ServiceOptions; /** * A base interface for all service RPC factories. Implementation must provide a public no-arg diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java similarity index 99% rename from google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java rename to google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java index e9ab3d4798..57603b9026 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BaseSerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static com.google.common.base.MoreObjects.firstNonNull; import static org.junit.Assert.assertEquals; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java similarity index 98% rename from google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java rename to google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index e3c6abb7d1..52bc3b2b51 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; -import static com.google.gcloud.BaseServiceException.UNKNOWN_CODE; +import static com.google.cloud.BaseServiceException.UNKNOWN_CODE; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java similarity index 98% rename from google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java rename to google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java index b44157b655..fc476b11ae 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertTrue; @@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import com.google.gcloud.spi.ServiceRpcFactory; +import com.google.cloud.spi.ServiceRpcFactory; import org.junit.Before; import org.junit.Rule; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java similarity index 97% rename from google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java rename to google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java index cedc995ddb..ddbd2ced84 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java @@ -14,14 +14,14 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.gcloud.ExceptionHandler.Interceptor; -import com.google.gcloud.ExceptionHandler.Interceptor.RetryResult; +import com.google.cloud.ExceptionHandler.Interceptor; +import com.google.cloud.ExceptionHandler.Interceptor.RetryResult; import org.junit.Rule; import org.junit.Test; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/FieldSelectorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java similarity index 97% rename from google-cloud-core/src/test/java/com/google/gcloud/FieldSelectorHelperTest.java rename to google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java index 9871c94218..6cdc4bdfb9 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/FieldSelectorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableList; -import com.google.gcloud.FieldSelector.Helper; +import com.google.cloud.FieldSelector.Helper; import org.junit.Test; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java b/google-cloud-core/src/test/java/com/google/cloud/IamPolicyTest.java similarity index 99% rename from google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java rename to google-cloud-core/src/test/java/com/google/cloud/IamPolicyTest.java index 235c2c2b1c..e79cfd9655 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/IamPolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/IamPolicyTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java similarity index 99% rename from google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java rename to google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java index a42bc9db7a..e720503c54 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/IdentityTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java similarity index 98% rename from google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java rename to google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java index 4389171fb4..07d979ad85 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/PageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static org.junit.Assert.assertEquals; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java similarity index 98% rename from google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java rename to google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java index 9a7cc2104f..7012813be2 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/RetryHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static java.util.concurrent.Executors.callable; import static org.junit.Assert.assertEquals; @@ -24,8 +24,8 @@ import com.google.common.base.Stopwatch; import com.google.common.base.Ticker; -import com.google.gcloud.RetryHelper.NonRetriableException; -import com.google.gcloud.RetryHelper.RetriesExhaustedException; +import com.google.cloud.RetryHelper.NonRetriableException; +import com.google.cloud.RetryHelper.RetriesExhaustedException; import org.junit.Test; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java similarity index 87% rename from google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java rename to google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java index eae4469392..c304105311 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/RetryParamsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java @@ -14,18 +14,18 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; -import static com.google.gcloud.RetryParams.DEFAULT_INITIAL_RETRY_DELAY_MILLIS; -import static com.google.gcloud.RetryParams.DEFAULT_MAX_RETRY_DELAY_MILLIS; -import static com.google.gcloud.RetryParams.DEFAULT_RETRY_DELAY_BACKOFF_FACTOR; -import static com.google.gcloud.RetryParams.DEFAULT_RETRY_MAX_ATTEMPTS; -import static com.google.gcloud.RetryParams.DEFAULT_RETRY_MIN_ATTEMPTS; -import static com.google.gcloud.RetryParams.DEFAULT_TOTAL_RETRY_PERIOD_MILLIS; +import static com.google.cloud.RetryParams.DEFAULT_INITIAL_RETRY_DELAY_MILLIS; +import static com.google.cloud.RetryParams.DEFAULT_MAX_RETRY_DELAY_MILLIS; +import static com.google.cloud.RetryParams.DEFAULT_RETRY_DELAY_BACKOFF_FACTOR; +import static com.google.cloud.RetryParams.DEFAULT_RETRY_MAX_ATTEMPTS; +import static com.google.cloud.RetryParams.DEFAULT_RETRY_MIN_ATTEMPTS; +import static com.google.cloud.RetryParams.DEFAULT_TOTAL_RETRY_PERIOD_MILLIS; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.gcloud.RetryParams.Builder; +import com.google.cloud.RetryParams.Builder; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java similarity index 98% rename from google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java rename to google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 8cf58f554d..72d622239f 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import com.google.common.collect.ImmutableList; -import com.google.gcloud.ServiceAccountSigner.SigningException; +import com.google.cloud.ServiceAccountSigner.SigningException; import java.io.ByteArrayInputStream; import java.io.IOException; diff --git a/google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java similarity index 97% rename from google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java rename to google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index d0e3db2d2a..b6f7a5453d 100644 --- a/google-cloud-core/src/test/java/com/google/gcloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud; +package com.google.cloud; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -22,10 +22,10 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.gcloud.ServiceOptions.Clock; -import com.google.gcloud.ServiceOptions.DefaultHttpTransportFactory; -import com.google.gcloud.ServiceOptions.HttpTransportFactory; -import com.google.gcloud.spi.ServiceRpcFactory; +import com.google.cloud.ServiceOptions.Clock; +import com.google.cloud.ServiceOptions.DefaultHttpTransportFactory; +import com.google.cloud.ServiceOptions.HttpTransportFactory; +import com.google.cloud.spi.ServiceRpcFactory; import org.easymock.EasyMock; import org.junit.Test; From 4c402563c2bfd899fcbe3f6e8026f5b0fcb58304 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 12 Apr 2016 11:28:30 -0700 Subject: [PATCH 164/663] Release 0.2.0 with repackaging note (#904) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2a164ae328..2d8eb4e440 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -10,7 +10,7 @@ com.google.cloud gcloud-java-pom - 0.1.8-SNAPSHOT + 0.2.0 gcloud-java-core From f47a823574cd5355ba3df65a08649ccf4f4b8347 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Tue, 12 Apr 2016 18:42:18 +0000 Subject: [PATCH 165/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index ca34b9789d..9a659c0f8c 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud gcloud-java-core - 0.1.7 + 0.2.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:gcloud-java-core:0.1.7' +compile 'com.google.cloud:gcloud-java-core:0.2.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.1.7" +libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.0" ``` Troubleshooting From ce61a2a2c239c4441193728372732fa4be06c12a Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 12 Apr 2016 12:14:00 -0700 Subject: [PATCH 166/663] update version to 0.2.1-SNAPSHOT (#905) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2d8eb4e440..4e2ecb69a0 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -10,7 +10,7 @@ com.google.cloud gcloud-java-pom - 0.2.0 + 0.2.1-SNAPSHOT gcloud-java-core From b6db6ce7f1095320867529d0ea658e5647cecb36 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 12 Apr 2016 23:50:02 +0200 Subject: [PATCH 167/663] Remove unused apt files and fix homepage URLs (#906) * Remove unused apt files * Fix URLs to homepage for each module --- google-cloud-core/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4e2ecb69a0..22648d2e6f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -4,6 +4,7 @@ gcloud-java-core jar GCloud Java core + https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-core Core module for the gcloud-java. From cad93bb7baa5e42bee033751f98a67f667d561f9 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Tue, 12 Apr 2016 16:31:54 -0700 Subject: [PATCH 168/663] reorder imports --- .../src/main/java/com/google/cloud/BaseWriteChannel.java | 1 + .../src/main/java/com/google/cloud/ServiceOptions.java | 2 +- .../test/java/com/google/cloud/FieldSelectorHelperTest.java | 2 +- .../src/test/java/com/google/cloud/RetryHelperTest.java | 4 ++-- .../src/test/java/com/google/cloud/SerializationTest.java | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index f803cd6bba..038ef8c362 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -16,6 +16,7 @@ package com.google.cloud; +import com.google.cloud.BaseWriteChannel.BaseState; import com.google.common.base.MoreObjects; import java.io.IOException; diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index e08d0cd9d1..194f61b45c 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -26,9 +26,9 @@ import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.auth.http.HttpCredentialsAdapter; +import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.collect.Iterables; import com.google.common.io.Files; -import com.google.cloud.spi.ServiceRpcFactory; import org.json.JSONException; import org.json.JSONObject; diff --git a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java index 6cdc4bdfb9..9aa892c7b0 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java @@ -19,8 +19,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import com.google.common.collect.ImmutableList; import com.google.cloud.FieldSelector.Helper; +import com.google.common.collect.ImmutableList; import org.junit.Test; diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java index 7012813be2..3887cecd6a 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java @@ -22,10 +22,10 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.common.base.Stopwatch; -import com.google.common.base.Ticker; import com.google.cloud.RetryHelper.NonRetriableException; import com.google.cloud.RetryHelper.RetriesExhaustedException; +import com.google.common.base.Stopwatch; +import com.google.common.base.Ticker; import org.junit.Test; diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 72d622239f..75347b2502 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -16,8 +16,8 @@ package com.google.cloud; -import com.google.common.collect.ImmutableList; import com.google.cloud.ServiceAccountSigner.SigningException; +import com.google.common.collect.ImmutableList; import java.io.ByteArrayInputStream; import java.io.IOException; From cf6fd32caf2542715975d49d6385307116dcd605 Mon Sep 17 00:00:00 2001 From: Martin Derka Date: Thu, 14 Apr 2016 18:07:13 -0400 Subject: [PATCH 169/663] Marked exceptions for create and deletes in DNS as non-idempotent. (#883) Add the notion of "rejected" to BaseServiceException to indicate that the service rejected the request and it should be safe to retry it even if request is not idempotent. --- .../google/cloud/BaseServiceException.java | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index 6dc87f4abb..ad2d6bf071 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -48,10 +48,16 @@ protected static final class Error implements Serializable { private final Integer code; private final String reason; + private final boolean rejected; public Error(Integer code, String reason) { + this(code, reason, false); + } + + public Error(Integer code, String reason, boolean rejected) { this.code = code; this.reason = reason; + this.rejected = rejected; } /** @@ -61,6 +67,15 @@ public Integer code() { return code; } + /** + * Returns true if the error indicates that the API call was certainly not accepted by the + * server. For instance, if the server returns a rate limit exceeded error, it certainly did not + * process the request and this method will return {@code true}. + */ + public boolean rejected() { + return rejected; + } + /** * Returns the reason that caused the exception. */ @@ -68,11 +83,11 @@ public String reason() { return reason; } - boolean isRetryable(Set retryableErrors) { + boolean isRetryable(boolean idempotent, Set retryableErrors) { for (Error retryableError : retryableErrors) { if ((retryableError.code() == null || retryableError.code().equals(this.code())) && (retryableError.reason() == null || retryableError.reason().equals(this.reason()))) { - return true; + return idempotent || retryableError.rejected(); } } return false; @@ -95,12 +110,14 @@ public BaseServiceException(IOException exception, boolean idempotent) { String reason = null; String location = null; String debugInfo = null; + Boolean retryable = null; if (exception instanceof GoogleJsonResponseException) { GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails(); if (jsonError != null) { - Error error = error(jsonError); + Error error = new Error(jsonError.getCode(), reason(jsonError)); code = error.code; reason = error.reason; + retryable = isRetryable(idempotent, error); if (reason != null) { GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0); location = errorInfo.getLocation(); @@ -110,8 +127,8 @@ public BaseServiceException(IOException exception, boolean idempotent) { code = ((GoogleJsonResponseException) exception).getStatusCode(); } } + this.retryable = MoreObjects.firstNonNull(retryable, isRetryable(idempotent, exception)); this.code = code; - this.retryable = idempotent && isRetryable(exception); this.reason = reason; this.idempotent = idempotent; this.location = location; @@ -119,13 +136,7 @@ public BaseServiceException(IOException exception, boolean idempotent) { } public BaseServiceException(GoogleJsonError error, boolean idempotent) { - super(error.getMessage()); - this.code = error.getCode(); - this.reason = reason(error); - this.idempotent = idempotent; - this.retryable = idempotent && isRetryable(error); - this.location = null; - this.debugInfo = null; + this(error.getCode(), error.getMessage(), reason(error), idempotent); } public BaseServiceException(int code, String message, String reason, boolean idempotent) { @@ -138,7 +149,7 @@ public BaseServiceException(int code, String message, String reason, boolean ide this.code = code; this.reason = reason; this.idempotent = idempotent; - this.retryable = idempotent && new Error(code, reason).isRetryable(retryableErrors()); + this.retryable = isRetryable(idempotent, new Error(code, reason)); this.location = null; this.debugInfo = null; } @@ -147,15 +158,12 @@ protected Set retryableErrors() { return Collections.emptySet(); } - protected boolean isRetryable(GoogleJsonError error) { - return error != null && error(error).isRetryable(retryableErrors()); + protected boolean isRetryable(boolean idempotent, Error error) { + return error.isRetryable(idempotent, retryableErrors()); } - protected boolean isRetryable(IOException exception) { - if (exception instanceof GoogleJsonResponseException) { - return isRetryable(((GoogleJsonResponseException) exception).getDetails()); - } - return exception instanceof SocketTimeoutException; + protected boolean isRetryable(boolean idempotent, IOException exception) { + return idempotent && exception instanceof SocketTimeoutException; } /** @@ -187,8 +195,8 @@ public boolean idempotent() { } /** - * Returns the service location where the error causing the exception occurred. Returns - * {@code null} if not set. + * Returns the service location where the error causing the exception occurred. Returns {@code + * null} if not available. */ public String location() { return location; @@ -223,18 +231,14 @@ public int hashCode() { debugInfo); } - protected static String reason(GoogleJsonError error) { - if (error.getErrors() != null && !error.getErrors().isEmpty()) { + private static String reason(GoogleJsonError error) { + if (error.getErrors() != null && !error.getErrors().isEmpty()) { return error.getErrors().get(0).getReason(); } return null; } - protected static Error error(GoogleJsonError error) { - return new Error(error.getCode(), reason(error)); - } - - protected static String message(IOException exception) { + private static String message(IOException exception) { if (exception instanceof GoogleJsonResponseException) { GoogleJsonError details = ((GoogleJsonResponseException) exception).getDetails(); if (details != null) { From 0c89f93e9d21d545bdee375fe996cb80c6f74090 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 15 Apr 2016 00:19:58 +0200 Subject: [PATCH 170/663] Enable mocking of functional classes and configurations (#892) * Enable mocking of functional classes and configurations * Refactor classes to be either final or have final equals/hashCode * Make job configuration classes final --- .../src/main/java/com/google/cloud/IamPolicy.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/cloud/IamPolicy.java index 1f214e1b0f..2d15d99076 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/IamPolicy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/IamPolicy.java @@ -219,7 +219,10 @@ public final int hashCode() { @Override public final boolean equals(Object obj) { - if (obj == null || !getClass().equals(obj.getClass())) { + if (obj == this) { + return true; + } + if (obj == null || !obj.getClass().equals(getClass())) { return false; } @SuppressWarnings("rawtypes") From fe5db1749956008faf430b061a22853ff2d30c77 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Sat, 16 Apr 2016 01:31:16 +0200 Subject: [PATCH 171/663] Add prefixes field to field selector when listing blobs (#933) --- .../java/com/google/cloud/FieldSelector.java | 40 ++++++++++++++----- .../google/cloud/FieldSelectorHelperTest.java | 17 ++++++++ 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java index a2b92d752e..5a46d05864 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java +++ b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java @@ -43,6 +43,8 @@ public interface FieldSelector { */ class Helper { + private static final String[] EMPTY_FIELDS = {}; + private Helper() {} private static final Function FIELD_TO_STRING_FUNCTION = @@ -63,18 +65,18 @@ private static String selector(List required, FieldSele } /** - * Returns a composite selector given a number of fields. The string selector returned by this - * method can be used for field selection in API calls that return a single resource. This - * method is not supposed to be used directly by users. + * Returns a composite selector given a number of resource fields. The string selector returned + * by this method can be used for field selection in API calls that return a single resource. + * This method is not supposed to be used directly by users. */ public static String selector(List required, FieldSelector... others) { return selector(required, others, new String[]{}); } /** - * Returns a composite selector given a number of fields and a container name. The string - * selector returned by this method can be used for field selection in API calls that return a - * list of resources. This method is not supposed to be used directly by users. + * Returns a composite selector given a number of resource fields and a container name. The + * string selector returned by this method can be used for field selection in API calls that + * return a list of resources. This method is not supposed to be used directly by users. */ public static String listSelector(String containerName, List required, FieldSelector... others) { @@ -82,14 +84,30 @@ public static String listSelector(String containerName, List required, FieldSelector[] others, String... extraResourceFields) { - return "nextPageToken," + containerName + '(' + return listSelector(EMPTY_FIELDS, containerName, required, others, extraResourceFields); + } + + /** + * Returns a composite selector given a number of top level fields as strings, a number of + * resource fields and a container name. This method also takes an {@code extraResourceFields} + * parameter to specify some extra resource fields as strings. The string selector returned by + * this method can be used for field selection in API calls that return a list of resources. + * This method is not supposed to be used directly by users. + */ + public static String listSelector(String[] topLevelFields, String containerName, + List required, FieldSelector[] others, + String... extraResourceFields) { + Set topLevelStrings = Sets.newHashSetWithExpectedSize(topLevelFields.length + 1); + topLevelStrings.addAll(Lists.asList("nextPageToken", topLevelFields)); + return Joiner.on(',').join(topLevelStrings) + "," + containerName + '(' + selector(required, others, extraResourceFields) + ')'; } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java index 9aa892c7b0..02d5847946 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java @@ -46,6 +46,7 @@ public String selector() { return "field3"; } }; + private static final String[] FIRST_LEVEL_FIELDS = {"firstLevel1", "firstLevel2"}; private static final List REQUIRED_FIELDS = ImmutableList.of(FIELD1, FIELD2); private static final String CONTAINER = "container"; @@ -81,4 +82,20 @@ public void testListSelectorWithExtraFields() { assertTrue(selector.endsWith(")")); assertEquals(52, selector.length()); } + + @Test + public void testListSelectorWithFirstLevelFields() { + String selector = Helper.listSelector(FIRST_LEVEL_FIELDS, CONTAINER, REQUIRED_FIELDS, + new FieldSelector[]{FIELD3}, "field4"); + assertTrue(selector.contains("firstLevel1")); + assertTrue(selector.contains("firstLevel2")); + assertTrue(selector.contains("nextPageToken")); + assertTrue(selector.contains("container(")); + assertTrue(selector.contains("field1")); + assertTrue(selector.contains("field2")); + assertTrue(selector.contains("field3")); + assertTrue(selector.contains("field4")); + assertTrue(selector.endsWith(")")); + assertEquals(76, selector.length()); + } } From a13dd69237b8919a18dc290aba27aa47a56ef0cd Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 20 Apr 2016 13:46:55 +0200 Subject: [PATCH 172/663] Add support for batches to DNS (#940) --- .../java/com/google/cloud/BatchResult.java | 108 +++++++++++++++++ .../com/google/cloud/BatchResultTest.java | 113 ++++++++++++++++++ 2 files changed, 221 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/BatchResult.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java b/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java new file mode 100644 index 0000000000..fb78409ea3 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java @@ -0,0 +1,108 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import java.util.LinkedList; +import java.util.List; + +/** + * This class holds a single result of a batch call. The class is not thread-safe. + * + * @param the type of the result + * @param the type of the service-dependent exception thrown when a processing error occurs + * + */ +public abstract class BatchResult { + + private T result; + private boolean completed = false; + private E error; + private final List> toBeNotified = new LinkedList<>(); + + /** + * Returns {@code true} if the batch has been completed and the result is available; {@code false} + * otherwise. + */ + public boolean completed() { + return completed; + } + + /** + * Returns the result of this call. + * + * @throws IllegalStateException if the batch has not been completed yet + * @throws E if an error occurred when processing the batch request + */ + public T get() throws E { + checkState(completed(), "Batch has not been completed yet"); + if (error != null) { + throw error; + } + return result; + } + + /** + * Adds a callback for the batch operation. + * + * @throws IllegalStateException if the batch has been completed already + */ + public void notify(Callback callback) { + checkState(!completed, "The batch has been completed. All the calls to the notify()" + + " method should be done prior to submitting the batch."); + toBeNotified.add(callback); + } + + /** + * Sets an error and status as completed. Notifies all callbacks. + */ + protected void error(E error) { + this.error = checkNotNull(error); + this.completed = true; + for (Callback callback : toBeNotified) { + callback.error(error); + } + } + + /** + * Sets a result and status as completed. Notifies all callbacks. + */ + protected void success(T result) { + this.result = result; + this.completed = true; + for (Callback callback : toBeNotified) { + callback.success(result); + } + } + + /** + * An interface for the batch callbacks. + */ + public interface Callback { + /** + * The method to be called when the batched operation succeeds. + */ + void success(T result); + + /** + * The method to be called when the batched operation fails. + */ + void error(E exception); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java b/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java new file mode 100644 index 0000000000..8fb26bc8ce --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java @@ -0,0 +1,113 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +public class BatchResultTest { + + private BatchResult result; + + @Before + public void setUp() { + result = new BatchResult() {}; + } + + @Test + public void testSuccess() { + assertFalse(result.completed()); + try { + result.get(); + fail("This was not completed yet."); + } catch (IllegalStateException ex) { + // expected + } + result.success(true); + assertTrue(result.get()); + // test that null is allowed + result.success(null); + } + + @Test + public void testError() { + assertFalse(result.completed()); + try { + result.get(); + fail("This was not completed yet."); + } catch (IllegalStateException ex) { + // expected + } + try { + result.error(null); + fail(); + } catch (NullPointerException exc) { + // expected + } + BaseServiceException ex = new BaseServiceException(0, "message", "reason", false); + result.error(ex); + try { + result.get(); + fail("This is a failed operation and should have thrown a DnsException."); + } catch (BaseServiceException real) { + assertSame(ex, real); + } + } + + @Test + public void testNotifyError() { + final BaseServiceException ex = new BaseServiceException(0, "message", "reason", false); + assertFalse(result.completed()); + BatchResult.Callback callback = + EasyMock.createStrictMock(BatchResult.Callback.class); + callback.error(ex); + EasyMock.replay(callback); + result.notify(callback); + result.error(ex); + try { + result.notify(callback); + fail("The batch has been completed."); + } catch (IllegalStateException exception) { + // expected + } + EasyMock.verify(callback); + } + + @Test + public void testNotifySuccess() { + assertFalse(result.completed()); + BatchResult.Callback callback = + EasyMock.createStrictMock(BatchResult.Callback.class); + callback.success(true); + EasyMock.replay(callback); + result.notify(callback); + result.success(true); + try { + result.notify(callback); + fail("The batch has been completed."); + } catch (IllegalStateException exception) { + // expected + } + EasyMock.verify(callback); + } +} From 8f9a2390391db38edb79ca030b2e331864a3299a Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 22 Apr 2016 21:29:07 +0200 Subject: [PATCH 173/663] Make DNS batch get zone/changerequest return null for NOT_FOUND (#953) --- .../com/google/cloud/BaseServiceException.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index ad2d6bf071..7cc55fd7a1 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -135,8 +135,21 @@ public BaseServiceException(IOException exception, boolean idempotent) { this.debugInfo = debugInfo; } - public BaseServiceException(GoogleJsonError error, boolean idempotent) { - this(error.getCode(), error.getMessage(), reason(error), idempotent); + public BaseServiceException(GoogleJsonError googleJsonError, boolean idempotent) { + super(googleJsonError.getMessage()); + Error error = new Error(googleJsonError.getCode(), reason(googleJsonError)); + this.code = error.code; + this.reason = error.reason; + this.retryable = isRetryable(idempotent, error); + if (this.reason != null) { + GoogleJsonError.ErrorInfo errorInfo = googleJsonError.getErrors().get(0); + this.location = errorInfo.getLocation(); + this.debugInfo = (String) errorInfo.get("debugInfo"); + } else { + this.location = null; + this.debugInfo = null; + } + this.idempotent = idempotent; } public BaseServiceException(int code, String message, String reason, boolean idempotent) { From e30800f19f960981bbbe5c61102af2ac3e44ae1a Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 29 Apr 2016 22:40:21 +0200 Subject: [PATCH 174/663] Release 0.2.1 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 22648d2e6f..c2ffc35d2f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.1-SNAPSHOT + 0.2.1 gcloud-java-core From 8e8a2070857b84cf0ca91637ac4b05c0620919a7 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Fri, 29 Apr 2016 21:26:09 +0000 Subject: [PATCH 175/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 9a659c0f8c..ac137785f4 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud gcloud-java-core - 0.2.0 + 0.2.1 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:gcloud-java-core:0.2.0' +compile 'com.google.cloud:gcloud-java-core:0.2.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.0" +libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.1" ``` Troubleshooting From 1a3e84228e5b78b48cb4970b27d0cbe7e1bd5ac6 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Sat, 30 Apr 2016 00:16:13 +0200 Subject: [PATCH 176/663] update version to 0.2.2-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c2ffc35d2f..e7b1242f0f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.1 + 0.2.2-SNAPSHOT gcloud-java-core From a3800338d26bc334917c3c989891a7009f216fe8 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 20 May 2016 15:30:26 +0200 Subject: [PATCH 177/663] Move Clock out of ServiceOptions, use it in RetryHelper (#954) * Move Clock out of ServiceOptions, use it in RetryHelper * Always pass options.clock() to RetryHelper.runWithRetries --- .../src/main/java/com/google/cloud/Clock.java | 59 +++++++++++++++++++ .../java/com/google/cloud/RetryHelper.java | 23 ++++---- .../java/com/google/cloud/ServiceOptions.java | 40 ------------- .../com/google/cloud/RetryHelperTest.java | 22 ++++--- .../com/google/cloud/ServiceOptionsTest.java | 1 - 5 files changed, 79 insertions(+), 66 deletions(-) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/Clock.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/Clock.java b/google-cloud-core/src/main/java/com/google/cloud/Clock.java new file mode 100644 index 0000000000..447200b03b --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/Clock.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import java.io.ObjectStreamException; +import java.io.Serializable; + +/** + * A class providing access to the current time in milliseconds. This class is mainly used for + * testing and will be replaced by Java8's {@code java.time.Clock}. + * + *

    Implementations should implement {@code Serializable} wherever possible and must document + * whether or not they do support serialization. + */ +public abstract class Clock { + + private static final Clock DEFAULT_TIME_SOURCE = new DefaultClock(); + + /** + * Returns current time in milliseconds according to this clock. + */ + public abstract long millis(); + + /** + * Returns the default clock. Default clock uses {@link System#currentTimeMillis()} to get time + * in milliseconds. + */ + public static Clock defaultClock() { + return DEFAULT_TIME_SOURCE; + } + + private static class DefaultClock extends Clock implements Serializable { + + private static final long serialVersionUID = -5077300394286703864L; + + @Override + public long millis() { + return System.currentTimeMillis(); + } + + private Object readResolve() throws ObjectStreamException { + return DEFAULT_TIME_SOURCE; + } + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index 48bd5fcf93..bd59070d47 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -21,12 +21,10 @@ import static java.lang.StrictMath.min; import static java.lang.StrictMath.pow; import static java.lang.StrictMath.random; -import static java.util.concurrent.TimeUnit.MILLISECONDS; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; -import com.google.common.base.Stopwatch; import java.io.InterruptedIOException; import java.nio.channels.ClosedByInterruptException; @@ -45,7 +43,7 @@ public class RetryHelper { private static final Logger log = Logger.getLogger(RetryHelper.class.getName()); - private final Stopwatch stopwatch; + private final Clock clock; private final Callable callable; private final RetryParams params; private final ExceptionHandler exceptionHandler; @@ -153,10 +151,10 @@ static Context getContext() { @VisibleForTesting RetryHelper(Callable callable, RetryParams params, ExceptionHandler exceptionHandler, - Stopwatch stopwatch) { + Clock clock) { this.callable = checkNotNull(callable); this.params = checkNotNull(params); - this.stopwatch = checkNotNull(stopwatch); + this.clock = checkNotNull(clock); this.exceptionHandler = checkNotNull(exceptionHandler); exceptionHandler.verifyCaller(callable); } @@ -165,7 +163,7 @@ static Context getContext() { public String toString() { ToStringHelper toStringHelper = MoreObjects.toStringHelper(this); toStringHelper.add("params", params); - toStringHelper.add("stopwatch", stopwatch); + toStringHelper.add("clock", clock); toStringHelper.add("attemptNumber", attemptNumber); toStringHelper.add("callable", callable); toStringHelper.add("exceptionHandler", exceptionHandler); @@ -173,7 +171,7 @@ public String toString() { } private V doRetry() throws RetryHelperException { - stopwatch.start(); + long start = clock.millis(); while (true) { attemptNumber++; Exception exception; @@ -196,7 +194,7 @@ private V doRetry() throws RetryHelperException { } if (attemptNumber >= params.retryMaxAttempts() || attemptNumber >= params.retryMinAttempts() - && stopwatch.elapsed(MILLISECONDS) >= params.totalRetryPeriodMillis()) { + && clock.millis() - start >= params.totalRetryPeriodMillis()) { throw new RetriesExhaustedException(this + ": Too many failures, giving up", exception); } long sleepDurationMillis = getSleepDuration(params, attemptNumber); @@ -234,13 +232,12 @@ public static V runWithRetries(Callable callable) throws RetryHelperExcep public static V runWithRetries(Callable callable, RetryParams params, ExceptionHandler exceptionHandler) throws RetryHelperException { - return runWithRetries(callable, params, exceptionHandler, Stopwatch.createUnstarted()); + return runWithRetries(callable, params, exceptionHandler, Clock.defaultClock()); } - @VisibleForTesting - static V runWithRetries(Callable callable, RetryParams params, - ExceptionHandler exceptionHandler, Stopwatch stopwatch) throws RetryHelperException { - RetryHelper retryHelper = new RetryHelper<>(callable, params, exceptionHandler, stopwatch); + public static V runWithRetries(Callable callable, RetryParams params, + ExceptionHandler exceptionHandler, Clock clock) throws RetryHelperException { + RetryHelper retryHelper = new RetryHelper<>(callable, params, exceptionHandler, clock); Context previousContext = getContext(); setContext(new Context(retryHelper)); try { diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 194f61b45c..d2f648b01f 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -43,7 +43,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.ObjectInputStream; -import java.io.ObjectStreamException; import java.io.Serializable; import java.lang.reflect.Method; import java.net.HttpURLConnection; @@ -125,45 +124,6 @@ public HttpTransport create() { } } - /** - * A class providing access to the current time in milliseconds. This class is mainly used for - * testing and will be replaced by Java8's {@code java.time.Clock}. - * - *

    Implementations should implement {@code Serializable} wherever possible and must document - * whether or not they do support serialization. - */ - public abstract static class Clock { - - private static final ServiceOptions.Clock DEFAULT_TIME_SOURCE = new DefaultClock(); - - /** - * Returns current time in milliseconds according to this clock. - */ - public abstract long millis(); - - /** - * Returns the default clock. Default clock uses {@link System#currentTimeMillis()} to get time - * in milliseconds. - */ - public static ServiceOptions.Clock defaultClock() { - return DEFAULT_TIME_SOURCE; - } - - private static class DefaultClock extends ServiceOptions.Clock implements Serializable { - - private static final long serialVersionUID = -5077300394286703864L; - - @Override - public long millis() { - return System.currentTimeMillis(); - } - - private Object readResolve() throws ObjectStreamException { - return DEFAULT_TIME_SOURCE; - } - } - } - /** * Builder for {@code ServiceOptions}. * diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java index 3887cecd6a..fcb404a462 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java @@ -24,8 +24,6 @@ import com.google.cloud.RetryHelper.NonRetriableException; import com.google.cloud.RetryHelper.RetriesExhaustedException; -import com.google.common.base.Stopwatch; -import com.google.common.base.Ticker; import org.junit.Test; @@ -157,24 +155,24 @@ public void testTriesNoMoreThanMaxTimes() { } } - private static class FakeTicker extends Ticker { - private final AtomicLong nanos = new AtomicLong(); + private static class FakeClock extends Clock { - // Advances the ticker value by {@code time} in {@code timeUnit}. + private final AtomicLong millis = new AtomicLong(); + + // Advances the clock value by {@code time} in {@code timeUnit}. void advance(long time, TimeUnit timeUnit) { - nanos.addAndGet(timeUnit.toNanos(time)); + millis.addAndGet(timeUnit.toMillis(time)); } @Override - public long read() { - return nanos.get(); + public long millis() { + return millis.get(); } } @Test public void testTriesNoMoreLongerThanTotalRetryPeriod() { - final FakeTicker ticker = new FakeTicker(); - Stopwatch stopwatch = Stopwatch.createUnstarted(ticker); + final FakeClock fakeClock = new FakeClock(); // The 8th attempt (after min and before max) will trigger a 1 second (virtual) delay exceeding // total retry period which is set just under 1 second. Test occurs faster than realtime. RetryParams params = RetryParams.builder().initialRetryDelayMillis(0) @@ -190,11 +188,11 @@ public void testTriesNoMoreLongerThanTotalRetryPeriod() { @Override public void run() { timesCalled.incrementAndGet(); if (timesCalled.get() == sleepOnAttempt) { - ticker.advance(1000, TimeUnit.MILLISECONDS); + fakeClock.advance(1000, TimeUnit.MILLISECONDS); } throw new RuntimeException(); } - }), params, handler, stopwatch); + }), params, handler, fakeClock); fail(); } catch (RetriesExhaustedException expected) { // verify timesCalled diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index b6f7a5453d..bcbecbe3c6 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.cloud.ServiceOptions.Clock; import com.google.cloud.ServiceOptions.DefaultHttpTransportFactory; import com.google.cloud.ServiceOptions.HttpTransportFactory; import com.google.cloud.spi.ServiceRpcFactory; From 8e03a11af8b0e871d319499157cc7a50b392b826 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 20 May 2016 20:58:15 +0200 Subject: [PATCH 178/663] Release 0.2.2 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e7b1242f0f..a902906a95 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.2-SNAPSHOT + 0.2.2 gcloud-java-core From 49fd88cf5f13915ee5479c1028f014c6e7f04669 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Fri, 20 May 2016 20:40:30 +0000 Subject: [PATCH 179/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index ac137785f4..b9d33a7243 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud gcloud-java-core - 0.2.1 + 0.2.2 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:gcloud-java-core:0.2.1' +compile 'com.google.cloud:gcloud-java-core:0.2.2' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.1" +libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.2" ``` Troubleshooting From 321a86dbd3478fc1541f9b466facfae00542ffcb Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 20 May 2016 23:05:49 +0200 Subject: [PATCH 180/663] Update version to 0.2.3-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a902906a95..8ebc30a629 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.2 + 0.2.3-SNAPSHOT gcloud-java-core From 316afc85213b2bd54a0743a0d8f206b4d7b3c215 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Sat, 28 May 2016 22:37:10 +0200 Subject: [PATCH 181/663] Add OAuth2AuthCredentials class and tests (#1030) --- .../com/google/cloud/AuthCredentials.java | 83 ++++++++++++ .../com/google/cloud/AuthCredentialsTest.java | 128 ++++++++++++++++++ .../com/google/cloud/SerializationTest.java | 4 +- 3 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java index ec5a631f5f..792831bb9e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java @@ -341,6 +341,67 @@ public RestorableState capture() { } } + /** + * Represents OAuth2 credentials. These credentials can be created given an OAuth2 access token. + * The access token will not be automatically refreshed. + */ + public static class OAuth2AuthCredentials extends AuthCredentials { + + private final GoogleCredentials credentials; + private final String accessToken; + private final Date expirationTime; + + private static class OAuth2AuthCredentialsState + implements RestorableState, Serializable { + + private static final long serialVersionUID = -7760693952274496205L; + + private final String accessToken; + private final Date expirationTime; + + private OAuth2AuthCredentialsState(String accessToken, Date expirationTime) { + this.accessToken = accessToken; + this.expirationTime = expirationTime; + } + + @Override + public AuthCredentials restore() { + return new OAuth2AuthCredentials(accessToken, expirationTime); + } + + @Override + public int hashCode() { + return Objects.hash(accessToken, expirationTime); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof OAuth2AuthCredentialsState)) { + return false; + } + OAuth2AuthCredentialsState other = (OAuth2AuthCredentialsState) obj; + return Objects.equals(accessToken, other.accessToken) + && Objects.equals(expirationTime, other.expirationTime); + } + } + + OAuth2AuthCredentials(String accessToken, Date expirationTime) { + this.accessToken = checkNotNull(accessToken); + this.expirationTime = expirationTime; + this.credentials = new GoogleCredentials(new AccessToken(accessToken, expirationTime)); + } + + @Override + public GoogleCredentials credentials() { + return credentials; + } + + @Override + public RestorableState capture() { + return new OAuth2AuthCredentialsState(accessToken, expirationTime); + } + } + /** * A placeholder for credentials to signify that requests sent to the server should not be * authenticated. This is typically useful when using the local service emulators, such as @@ -428,6 +489,28 @@ public static ServiceAccountAuthCredentials createFor(String account, PrivateKey return new ServiceAccountAuthCredentials(account, privateKey); } + /** + * Creates OAuth2 Credentials given the string representation of an access token. The access token + * will not be automatically refreshed. + * + * @param accessToken string representation of an access token + * @return the credentials instance + */ + public static OAuth2AuthCredentials createFor(String accessToken) { + return createFor(accessToken, (Date) null); + } + + /** + * Creates OAuth2 Credentials given the string representation of an access token and its + * expiration time. The access token will not be automatically refreshed. + * + * @param accessToken string representation of an access token + * @return the credentials instance + */ + public static OAuth2AuthCredentials createFor(String accessToken, Date expirationTime) { + return new OAuth2AuthCredentials(accessToken, expirationTime); + } + /** * Creates a placeholder denoting that no credentials should be used. This is typically useful * when using the local service emulators, such as {@code LocalDatastoreHelper} and diff --git a/google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java b/google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java new file mode 100644 index 0000000000..9074c2d103 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java @@ -0,0 +1,128 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.base.Charsets.UTF_8; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + +import com.google.auth.oauth2.AccessToken; +import com.google.auth.oauth2.ServiceAccountCredentials; +import com.google.cloud.AuthCredentials.OAuth2AuthCredentials; +import com.google.cloud.AuthCredentials.ServiceAccountAuthCredentials; +import com.google.common.io.BaseEncoding; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.security.InvalidKeyException; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.Signature; +import java.security.SignatureException; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.PKCS8EncodedKeySpec; +import java.util.Date; + +public class AuthCredentialsTest { + + private static final String ACCESS_TOKEN = "accessToken"; + private static final Date EXPIRATION_DATE = new Date(); + private static final String SERVICE_ACCOUNT = "someclientid@developer.gserviceaccount.com"; + private static final String PRIVATE_KEY_STRING = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoG" + + "BAL2xolH1zrISQ8+GzOV29BNjjzq4/HIP8Psd1+cZb81vDklSF+95wB250MSE0BDc81pvIMwj5OmIfLg1NY6uB1xav" + + "OPpVdx1z664AGc/BEJ1zInXGXaQ6s+SxGenVq40Yws57gikQGMZjttpf1Qbz4DjkxsbRoeaRHn06n9pH1ejAgMBAAE" + + "CgYEAkWcm0AJF5LMhbWKbjkxm/LG06UNApkHX6vTOOOODkonM/qDBnhvKCj8Tan+PaU2j7679Cd19qxCm4SBQJET7e" + + "BhqLD9L2j9y0h2YUQnLbISaqUS1/EXcr2C1Lf9VCEn1y/GYuDYqs85rGoQ4ZYfM9ClROSq86fH+cbIIssqJqukCQQD" + + "18LjfJz/ichFeli5/l1jaFid2XoCH3T6TVuuysszVx68fh60gSIxEF/0X2xB+wuPxTP4IQ+t8tD/ktd232oWXAkEAx" + + "XPych2QBHePk9/lek4tOkKBgfnDzex7S/pI0G1vpB3VmzBbCsokn9lpOv7JV8071GDlW/7R6jlLfpQy3hN31QJAE10" + + "osSk99m5Uv8XDU3hvHnywDrnSFOBulNs7I47AYfSe7TSZhPkxUgsxejddTR27JLyTI8N1PxRSE4feNSOXcQJAMMKJR" + + "JT4U6IS2rmXubREhvaVdLtxFxEnAYQ1JwNfZm/XqBMw6GEy2iaeTetNXVlZRQEIoscyn1y2v/No/F5iYQJBAKBOGAS" + + "oQcBjGTOg/H/SfcE8QVNsKEpthRrs6CkpT80aZ/AV+ksfoIf2zw2M3mAHfrO+TBLdz4sicuFQvlN9SEc="; + private static final String JSON_KEY = "{\n" + + " \"private_key_id\": \"somekeyid\",\n" + + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\n" + PRIVATE_KEY_STRING + + "\\n-----END PRIVATE KEY-----\\n\",\n" + + " \"client_email\": \"someclientid@developer.gserviceaccount.com\",\n" + + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" + + " \"type\": \"service_account\"\n" + + "}"; + private static final AuthCredentials NO_AUTH_CREDENTIALS = AuthCredentials.noAuth(); + private static final OAuth2AuthCredentials OAUTH2_AUTH_CREDENTIALS = + AuthCredentials.createFor(ACCESS_TOKEN, EXPIRATION_DATE); + private static final byte[] BYTES_TO_SIGN = PRIVATE_KEY_STRING.getBytes(UTF_8); + + private static PrivateKey privateKey; + private static byte[] signedBytes; + + @BeforeClass + public static void beforeClass() throws NoSuchAlgorithmException, InvalidKeySpecException, + InvalidKeyException, SignatureException { + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + privateKey = keyFactory.generatePrivate( + new PKCS8EncodedKeySpec(BaseEncoding.base64().decode(PRIVATE_KEY_STRING))); + Signature signature = Signature.getInstance("SHA256withRSA"); + signature.initSign(privateKey); + signature.update(BYTES_TO_SIGN); + signedBytes = signature.sign(); + } + + @Test + public void testNoAuthCredentials() { + assertSame(NO_AUTH_CREDENTIALS, AuthCredentials.noAuth()); + assertNull(NO_AUTH_CREDENTIALS.credentials()); + } + + @Test + public void testOAuth2AuthCredentials() { + AccessToken accessToken = OAUTH2_AUTH_CREDENTIALS.credentials().getAccessToken(); + assertEquals(ACCESS_TOKEN, accessToken.getTokenValue()); + assertEquals(EXPIRATION_DATE, accessToken.getExpirationTime()); + OAuth2AuthCredentials oAuth2AuthCredentials = + AuthCredentials.createFor(ACCESS_TOKEN); + accessToken = oAuth2AuthCredentials.credentials().getAccessToken(); + assertEquals(ACCESS_TOKEN, accessToken.getTokenValue()); + assertNull(accessToken.getExpirationTime()); + } + + @Test + public void testServiceAccountFromJson() throws IOException, SignatureException { + ServiceAccountAuthCredentials serviceAccountAuthCredentials = + AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes())); + ServiceAccountCredentials credentials = serviceAccountAuthCredentials.credentials(); + assertEquals(SERVICE_ACCOUNT, serviceAccountAuthCredentials.account()); + assertEquals(SERVICE_ACCOUNT, credentials.getClientEmail()); + assertEquals(privateKey, credentials.getPrivateKey()); + assertArrayEquals(signedBytes, serviceAccountAuthCredentials.sign(BYTES_TO_SIGN)); + } + + @Test + public void testServiceAccountFromKey() throws IOException, SignatureException { + ServiceAccountAuthCredentials serviceAccountAuthCredentials = + AuthCredentials.createFor(SERVICE_ACCOUNT, privateKey); + ServiceAccountCredentials credentials = serviceAccountAuthCredentials.credentials(); + assertEquals(SERVICE_ACCOUNT, serviceAccountAuthCredentials.account()); + assertEquals(SERVICE_ACCOUNT, credentials.getClientEmail()); + assertEquals(privateKey, credentials.getPrivateKey()); + assertArrayEquals(signedBytes, serviceAccountAuthCredentials.sign(BYTES_TO_SIGN)); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 75347b2502..7fa778a524 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.Serializable; +import java.util.Date; public class SerializationTest extends BaseSerializationTest { @@ -94,7 +95,8 @@ protected Serializable[] serializableObjects() { protected Restorable[] restorableObjects() { try { return new Restorable[]{AuthCredentials.createForAppEngine(), AuthCredentials.noAuth(), - AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes()))}; + AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes())), + AuthCredentials.createFor("accessToken", new Date())}; } catch (IOException ex) { // never reached throw new RuntimeException(ex); From 770d99d69216ffce975fb4e0a0b831f13f42bf24 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 9 Jun 2016 14:57:17 +0200 Subject: [PATCH 182/663] Add whenDone method and CompletionCallback to Job and Operation (#1016) --- .../java/com/google/cloud/WaitForOption.java | 225 ++++++++++++++++++ .../com/google/cloud/SerializationTest.java | 5 +- .../com/google/cloud/WaitForOptionTest.java | 124 ++++++++++ 3 files changed, 353 insertions(+), 1 deletion(-) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java b/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java new file mode 100644 index 0000000000..8af7a074ab --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java @@ -0,0 +1,225 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.base.MoreObjects; + +import java.io.Serializable; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +/** + * This class represents options for methods that wait for changes in the status of a resource. + */ +public abstract class WaitForOption implements Serializable { + + private static final long serialVersionUID = 8443451708032349243L; + + private final OptionType optionType; + + enum OptionType { + CHECKING_PERIOD, + TIMEOUT + } + + private WaitForOption(OptionType optionType) { + this.optionType = optionType; + } + + /** + * This class represents an option to set how frequently the resource status should be checked. + * Objects of this class keep the actual period and related time unit for the checking period. + */ + public static final class CheckingPeriod extends WaitForOption { + + private static final long serialVersionUID = -2481062893220539210L; + private static final CheckingPeriod DEFAULT = new CheckingPeriod(500, TimeUnit.MILLISECONDS); + + private final long period; + private final TimeUnit unit; + + private CheckingPeriod(long period, TimeUnit unit) { + super(OptionType.CHECKING_PERIOD); + this.period = period; + this.unit = unit; + } + + /** + * Returns the checking period. + */ + public long period() { + return period; + } + + /** + * Returns the time unit for {@link #period()}. + */ + public TimeUnit unit() { + return unit; + } + + /** + * Blocks the current thread for the amount of time specified by this object. + * + * @throws InterruptedException if the current thread was interrupted + */ + public void sleep() throws InterruptedException { + unit.sleep(period); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj == null || !(obj instanceof CheckingPeriod)) { + return false; + } + CheckingPeriod other = (CheckingPeriod) obj; + return baseEquals(other) + && Objects.equals(period, other.period) + && Objects.equals(unit, other.unit); + } + + @Override + public int hashCode() { + return Objects.hash(baseHashCode(), period, unit); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("period", period) + .add("unit", unit) + .toString(); + } + + /** + * Returns the {@code CheckingPeriod} option specified in {@code options}. If no + * {@code CheckingPeriod} could be found among {@code options}, the default checking period (500 + * milliseconds) is used. + */ + public static CheckingPeriod getOrDefault(WaitForOption... options) { + return getOrDefaultInternal(OptionType.CHECKING_PERIOD, DEFAULT, options); + } + } + + /** + * This class represents an option to set the maximum time to wait for the resource's status to + * reach the desired state. + */ + public static final class Timeout extends WaitForOption { + + private static final long serialVersionUID = -7120401111985321932L; + private static final Timeout DEFAULT = new Timeout(-1); + + private final long timeoutMillis; + + private Timeout(long timeoutMillis) { + super(OptionType.TIMEOUT); + this.timeoutMillis = timeoutMillis; + } + + /** + * Returns the timeout in milliseconds. + */ + public long timeoutMillis() { + return timeoutMillis; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj == null || !(obj instanceof Timeout)) { + return false; + } + Timeout other = (Timeout) obj; + return baseEquals(other) && Objects.equals(timeoutMillis, other.timeoutMillis); + } + + @Override + public int hashCode() { + return Objects.hash(baseHashCode(), timeoutMillis); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("timeoutMillis", timeoutMillis) + .toString(); + } + + /** + * Returns the {@code Timeout} option specified in {@code options}. If no {@code Timeout} could + * be found among {@code options}, no timeout will be used. + */ + public static Timeout getOrDefault(WaitForOption... options) { + return getOrDefaultInternal(OptionType.TIMEOUT, DEFAULT, options); + } + } + + OptionType optionType() { + return optionType; + } + + final boolean baseEquals(WaitForOption option) { + return Objects.equals(option.optionType, option.optionType); + } + + final int baseHashCode() { + return Objects.hash(optionType); + } + + @SuppressWarnings("unchecked") + private static T getOrDefaultInternal(OptionType optionType, + T defaultValue, WaitForOption... options) { + T foundOption = null; + for (WaitForOption option : options) { + if (option.optionType.equals(optionType)) { + checkArgument(foundOption == null, "Duplicate option %s", option); + foundOption = (T) option; + } + } + return foundOption != null ? foundOption : defaultValue; + } + + /** + * Returns an option to set how frequently the resource status should be checked. + * + * @param checkEvery the checking period + * @param unit the time unit of the checking period + */ + public static CheckingPeriod checkEvery(long checkEvery, TimeUnit unit) { + checkArgument(checkEvery >= 0, "checkEvery must be >= 0"); + return new CheckingPeriod(checkEvery, unit); + } + + /** + * Returns an option to set the maximum time to wait. + * + * @param timeout the maximum time to wait, expressed in {@code unit} + * @param unit the time unit of the timeout + */ + public static Timeout timeout(long timeout, TimeUnit unit) { + checkArgument(timeout >= 0, "timeout must be >= 0"); + return new Timeout(unit.toMillis(timeout)); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 7fa778a524..53baa57b96 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.Serializable; import java.util.Date; +import java.util.concurrent.TimeUnit; public class SerializationTest extends BaseSerializationTest { @@ -36,6 +37,8 @@ public class SerializationTest extends BaseSerializationTest { new SigningException("message", BASE_SERVICE_EXCEPTION); private static final RetryParams RETRY_PARAMS = RetryParams.defaultInstance(); private static final SomeIamPolicy SOME_IAM_POLICY = new SomeIamPolicy.Builder().build(); + private static final WaitForOption CHECKING_PERIOD = + WaitForOption.checkEvery(42, TimeUnit.SECONDS); private static final String JSON_KEY = "{\n" + " \"private_key_id\": \"somekeyid\",\n" + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" @@ -88,7 +91,7 @@ public Builder toBuilder() { @Override protected Serializable[] serializableObjects() { return new Serializable[]{BASE_SERVICE_EXCEPTION, EXCEPTION_HANDLER, IDENTITY, PAGE, - RETRY_PARAMS, SOME_IAM_POLICY, SIGNING_EXCEPTION}; + RETRY_PARAMS, SOME_IAM_POLICY, SIGNING_EXCEPTION, CHECKING_PERIOD}; } @Override diff --git a/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java new file mode 100644 index 0000000000..82996e1ca3 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java @@ -0,0 +1,124 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import com.google.cloud.WaitForOption.CheckingPeriod; +import com.google.cloud.WaitForOption.OptionType; +import com.google.cloud.WaitForOption.Timeout; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.concurrent.TimeUnit; + +public class WaitForOptionTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private static final CheckingPeriod CHECKING_PERIOD_OPTION = + WaitForOption.checkEvery(42, TimeUnit.MILLISECONDS); + private static final Timeout TIMEOUT_OPTION = WaitForOption.timeout(43, TimeUnit.MILLISECONDS); + + @Test + public void testCheckEvery() { + assertEquals(OptionType.CHECKING_PERIOD, CHECKING_PERIOD_OPTION.optionType()); + assertEquals(42, CHECKING_PERIOD_OPTION.period()); + assertEquals(TimeUnit.MILLISECONDS, CHECKING_PERIOD_OPTION.unit()); + } + + @Test + public void testCheckEvery_InvalidPeriod() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("checkEvery must be >= 0"); + WaitForOption.checkEvery(-1, TimeUnit.MILLISECONDS); + } + + @Test + public void testTimeout() { + assertEquals(OptionType.TIMEOUT, TIMEOUT_OPTION.optionType()); + assertEquals(43, TIMEOUT_OPTION.timeoutMillis()); + Timeout timeoutOption = WaitForOption.timeout(43, TimeUnit.SECONDS); + assertEquals(43_000, timeoutOption.timeoutMillis()); + } + + @Test + public void testTimeout_InvalidTimeout() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("timeout must be >= 0"); + WaitForOption.timeout(-1, TimeUnit.MILLISECONDS); + } + + @Test + public void testEqualsAndHashCode() { + assertEquals(CHECKING_PERIOD_OPTION, CHECKING_PERIOD_OPTION); + assertEquals(TIMEOUT_OPTION, TIMEOUT_OPTION); + assertEquals(CHECKING_PERIOD_OPTION.hashCode(), CHECKING_PERIOD_OPTION.hashCode()); + assertEquals(TIMEOUT_OPTION.hashCode(), TIMEOUT_OPTION.hashCode()); + WaitForOption checkingPeriodOption = WaitForOption.checkEvery(42, TimeUnit.MILLISECONDS); + assertEquals(CHECKING_PERIOD_OPTION, checkingPeriodOption); + assertEquals(CHECKING_PERIOD_OPTION.hashCode(), checkingPeriodOption.hashCode()); + WaitForOption timeoutOption = WaitForOption.timeout(43, TimeUnit.MILLISECONDS); + assertEquals(TIMEOUT_OPTION, timeoutOption); + assertEquals(TIMEOUT_OPTION.hashCode(), timeoutOption.hashCode()); + assertNotEquals(CHECKING_PERIOD_OPTION, TIMEOUT_OPTION); + assertNotEquals(CHECKING_PERIOD_OPTION.hashCode(), TIMEOUT_OPTION.hashCode()); + checkingPeriodOption = WaitForOption.checkEvery(43, TimeUnit.MILLISECONDS); + assertNotEquals(CHECKING_PERIOD_OPTION, checkingPeriodOption); + assertNotEquals(CHECKING_PERIOD_OPTION.hashCode(), checkingPeriodOption.hashCode()); + checkingPeriodOption = WaitForOption.checkEvery(42, TimeUnit.SECONDS); + assertNotEquals(CHECKING_PERIOD_OPTION, checkingPeriodOption); + assertNotEquals(CHECKING_PERIOD_OPTION.hashCode(), checkingPeriodOption.hashCode()); + timeoutOption = WaitForOption.timeout(42, TimeUnit.MILLISECONDS); + assertNotEquals(TIMEOUT_OPTION, timeoutOption); + assertNotEquals(TIMEOUT_OPTION.hashCode(), timeoutOption.hashCode()); + timeoutOption = WaitForOption.timeout(43, TimeUnit.SECONDS); + assertNotEquals(TIMEOUT_OPTION, timeoutOption); + assertNotEquals(TIMEOUT_OPTION.hashCode(), timeoutOption.hashCode()); + } + + @Test + public void testGetOrDefault() { + assertEquals(CHECKING_PERIOD_OPTION, + CheckingPeriod.getOrDefault(CHECKING_PERIOD_OPTION, TIMEOUT_OPTION)); + assertEquals(TIMEOUT_OPTION, + Timeout.getOrDefault(CHECKING_PERIOD_OPTION, TIMEOUT_OPTION)); + CheckingPeriod checkingPeriod = CheckingPeriod.getOrDefault(TIMEOUT_OPTION); + assertEquals(500, checkingPeriod.period()); + assertEquals(TimeUnit.MILLISECONDS, checkingPeriod.unit()); + Timeout timeout = Timeout.getOrDefault(CHECKING_PERIOD_OPTION); + assertEquals(-1, timeout.timeoutMillis()); + } + + @Test + public void testCheckingPeriodGetOrDefault_DuplicateOption() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage(String.format("Duplicate option %s", CHECKING_PERIOD_OPTION)); + CheckingPeriod.getOrDefault(CHECKING_PERIOD_OPTION, CHECKING_PERIOD_OPTION); + } + + @Test + public void testTimeoutGetOrDefault_DuplicateOption() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage(String.format("Duplicate option %s", TIMEOUT_OPTION)); + Timeout.getOrDefault(TIMEOUT_OPTION, TIMEOUT_OPTION); + } +} From d79e07ac340c8ed38ff58f0b93bbce833df0a61b Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 10 Jun 2016 16:17:16 +0200 Subject: [PATCH 183/663] Release 0.2.3 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 8ebc30a629..2a41f628b1 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.3-SNAPSHOT + 0.2.3 gcloud-java-core From 05bb72dea61453ad3caccc6dc15d56e7108aa61b Mon Sep 17 00:00:00 2001 From: travis-ci Date: Fri, 10 Jun 2016 15:23:17 +0000 Subject: [PATCH 184/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index b9d33a7243..abd95a563c 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud gcloud-java-core - 0.2.2 + 0.2.3 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:gcloud-java-core:0.2.2' +compile 'com.google.cloud:gcloud-java-core:0.2.3' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.2" +libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.3" ``` Troubleshooting From 61504a0d1ecc0fa337cbf0bcd1b526ad3f130a38 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 10 Jun 2016 18:14:06 +0200 Subject: [PATCH 185/663] Update version to 0.2.4-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2a41f628b1..927256b577 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.3 + 0.2.4-SNAPSHOT gcloud-java-core From 689e7230e2b05235a119d02528ac47f7e0ce5490 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 28 Apr 2016 16:04:50 +0200 Subject: [PATCH 186/663] Add PubSub API prototype and related classes (#962) * adding PubSubOptions, PubSub and its factories * Adding data types and define API * Add ReceivedMessage and fix review comments * Fix code review comments and add DefaultPubSubRpc * - Fix some codacy issues - Make messages consistent with proto defaults - Rename acknowledge to ack - Add nack - Add PullCallback * applying code review comments * add ByteArray * translate exceptions and add more info regarding pull * consider returnNullOn before throwing * Fix pubsub-related codacy issues --- google-cloud-core/pom.xml | 10 ++ .../main/java/com/google/cloud/AsyncPage.java | 23 +++ .../google/cloud/BaseServiceException.java | 11 ++ .../main/java/com/google/cloud/ByteArray.java | 165 ++++++++++++++++++ 4 files changed, 209 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/ByteArray.java diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 927256b577..e892583d1e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -98,5 +98,15 @@ 3.4 test + + com.google.protobuf + protobuf-java + 3.0.0-beta-1 + + + com.google.api + gax + 0.0.11 + diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java new file mode 100644 index 0000000000..ea2905795e --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java @@ -0,0 +1,23 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import java.util.concurrent.Future; + +public interface AsyncPage extends Page { + Future> nextPageAsync(); +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index 7cc55fd7a1..79afed2a3a 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -18,6 +18,7 @@ import com.google.api.client.googleapis.json.GoogleJsonError; import com.google.api.client.googleapis.json.GoogleJsonResponseException; +import com.google.api.gax.grpc.ApiException; import com.google.common.base.MoreObjects; import java.io.IOException; @@ -167,6 +168,16 @@ public BaseServiceException(int code, String message, String reason, boolean ide this.debugInfo = null; } + public BaseServiceException(ApiException apiException, boolean idempotent) { + super(apiException.getMessage(), apiException); + this.code = apiException.getStatusCode().value(); + this.reason = apiException.getStatusCode().name(); + this.idempotent = idempotent; + this.retryable = apiException.isRetryable(); + this.location = null; + this.debugInfo = null; + } + protected Set retryableErrors() { return Collections.emptySet(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java new file mode 100644 index 0000000000..f23fb0876b --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -0,0 +1,165 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.protobuf.ByteString; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.Serializable; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Iterator; + +/** + * An immutable byte array holder. + */ +public class ByteArray implements Iterable, Serializable { + + private static final long serialVersionUID = -1908809133893782840L; + private final ByteString byteString; + + protected ByteArray(ByteString byteString) { + this.byteString = byteString; + } + + protected ByteArray(ByteArray byteArray) { + this.byteString = byteArray.byteString(); + } + + @Override + public final Iterator iterator() { + return byteString.iterator(); + } + + @Override + public String toString() { + ToStringHelper toStringHelper = MoreObjects.toStringHelper(this); + StringBuilder stBuilder = new StringBuilder(); + for (int i = 0; i < Math.min(256, byteString.size()); i++) { + stBuilder.append(String.format("%02x", byteString.byteAt(i))); + } + if (byteString.size() > 256) { + stBuilder.append("..."); + } + return toStringHelper.add("bytes", stBuilder.toString()).toString(); + } + + @Override + public final int hashCode() { + return byteString.hashCode(); + } + + @Override + public final boolean equals(Object obj) { + return obj == this + || obj instanceof ByteArray && byteString.equals(((ByteArray) obj).byteString); + } + + /** + * Returns the size of this blob. + */ + public final int length() { + return byteString.size(); + } + + /** + * Returns a copy as byte array. + */ + public final byte[] toByteArray() { + return byteString.toByteArray(); + } + + /** + * Returns the content as {@code UTF-8} string. + */ + public final String toStringUtf8() { + return byteString.toStringUtf8(); + } + + /** + * Returns a read-only {@link ByteBuffer} for this blob content. + */ + public final ByteBuffer asReadOnlyByteBuffer() { + return byteString.asReadOnlyByteBuffer(); + } + + /** + * Returns an {@link InputStream} for this blob content. + */ + public final InputStream asInputStream() { + final ByteBuffer byteBuffer = asReadOnlyByteBuffer(); + return new InputStream() { + @Override public int read() { + return !byteBuffer.hasRemaining() ? -1 : byteBuffer.get() & 0xFF; + } + }; + } + + protected ByteString byteString() { + return byteString; + } + + /** + * Copies bytes into a ByteBuffer. + * + * @throws java.nio.ReadOnlyBufferException if the target is read-only + * @throws java.nio.BufferOverflowException if the target's remaining() space is not large + * enough to hold the data + */ + public final void copyTo(ByteBuffer target) { + byteString.copyTo(target); + } + + /** + * Copies bytes into a buffer. + * + * @throws IndexOutOfBoundsException if an offset or size is negative or too large + */ + public final void copyTo(byte[] target) { + byteString.copyTo(target, 0, 0, length()); + } + + public static final ByteArray copyFrom(byte[] bytes) { + return new ByteArray(ByteString.copyFrom(bytes)); + } + + /** + * Copy the bytes using {@code UTF-8} decoding. + */ + public static final ByteArray copyFrom(String string) { + return new ByteArray(ByteString.copyFrom(string, StandardCharsets.UTF_8)); + } + + public static final ByteArray copyFrom(ByteBuffer bytes) { + return new ByteArray(ByteString.copyFrom(bytes)); + } + + public static final ByteArray copyFrom(InputStream input) throws IOException { + BufferedInputStream bufferedInput = new BufferedInputStream(input); + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + int value; + while ((value = bufferedInput.read()) != -1) { + bytes.write(value); + } + return copyFrom(bytes.toByteArray()); + } +} From 437714e6a9cb6b857c39f8f3f3dcc0f72093578d Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 4 May 2016 09:34:56 +0200 Subject: [PATCH 187/663] Add AsyncPage implementation and docs. Add related tests (#974) --- .../main/java/com/google/cloud/AsyncPage.java | 28 ++++ .../java/com/google/cloud/AsyncPageImpl.java | 82 +++++++++++ .../com/google/cloud/AsyncPageImplTest.java | 128 ++++++++++++++++++ .../java/com/google/cloud/PageImplTest.java | 2 + 4 files changed, 240 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java index ea2905795e..d82d46f19b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java @@ -18,6 +18,34 @@ import java.util.concurrent.Future; +/** + * Interface for asynchronously consuming Google Cloud paginated results. + * + *

    Use {@code AsyncPage} to iterate through all values (also in next pages): + *

     {@code
    + * AsyncPage page = ...; // get an AsyncPage instance
    + * Iterator iterator = page.iterateAll();
    + * while (iterator.hasNext()) {
    + *   T value = iterator.next();
    + *   // do something with value
    + * }}
    + * + *

    Or handle pagination explicitly: + *

     {@code
    + * AsyncPage page = ...; // get a AsyncPage instance
    + * while (page != null) {
    + *   for (T value : page.values()) {
    + *     // do something with value
    + *   }
    + *   page = page.nextPage().get();
    + * }}
    + * + * @param the value type that the page holds + */ public interface AsyncPage extends Page { + + /** + * Returns a {@link Future} object for the next page. + */ Future> nextPageAsync(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java new file mode 100644 index 0000000000..42af7b34a9 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -0,0 +1,82 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.common.base.Throwables; +import com.google.common.util.concurrent.Uninterruptibles; + +import java.io.Serializable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +/** + * Base implementation for asynchronously consuming Google Cloud paginated results. + * + * @param the value type that the page holds + */ +public class AsyncPageImpl extends PageImpl implements AsyncPage { + + private static final long serialVersionUID = -6009473188630364906L; + + private final NextPageFetcher asyncPageFetcher; + + /** + * Interface for asynchronously fetching the next page of results from the service. + * + * @param the value type that the page holds + */ + public interface NextPageFetcher extends Serializable { + Future> nextPage(); + } + + private static class SyncNextPageFetcher implements PageImpl.NextPageFetcher { + + private static final long serialVersionUID = -4124568632363525351L; + + private NextPageFetcher asyncPageFetcher; + + private SyncNextPageFetcher(NextPageFetcher asyncPageFetcher) { + this.asyncPageFetcher = asyncPageFetcher; + } + + @Override + public Page nextPage() { + try { + return asyncPageFetcher != null + ? Uninterruptibles.getUninterruptibly(asyncPageFetcher.nextPage()) : null; + } catch (ExecutionException ex) { + throw Throwables.propagate(ex.getCause()); + } + } + } + + /** + * Creates an {@code AsyncPageImpl} object. + */ + public AsyncPageImpl(NextPageFetcher asyncPageFetcher, String cursor, Iterable results) { + super(new SyncNextPageFetcher(asyncPageFetcher), cursor, results); + this.asyncPageFetcher = asyncPageFetcher; + } + + @Override + public Future> nextPageAsync() { + if (nextPageCursor() == null || asyncPageFetcher == null) { + return null; + } + return asyncPageFetcher.nextPage(); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java new file mode 100644 index 0000000000..60189a0554 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java @@ -0,0 +1,128 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import com.google.common.util.concurrent.Futures; + +import org.junit.Test; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +public class AsyncPageImplTest { + + private static final ImmutableList VALUES1 = ImmutableList.of("1", "2"); + private static final ImmutableList VALUES2 = ImmutableList.of("3", "4"); + private static final ImmutableList VALUES3 = ImmutableList.of("5", "6"); + private static final ImmutableList ALL_VALUES = ImmutableList.builder() + .addAll(VALUES1) + .addAll(VALUES2) + .addAll(VALUES3) + .build(); + private static final ImmutableList SOME_VALUES = ImmutableList.builder() + .addAll(VALUES2) + .addAll(VALUES3) + .build(); + + @Test + public void testPage() { + final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2); + AsyncPageImpl.NextPageFetcher fetcher = new AsyncPageImpl.NextPageFetcher() { + private static final long serialVersionUID = 4703765400378593176L; + + @Override + public Future> nextPage() { + return Futures.>immediateFuture(nextResult); + } + }; + AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1); + assertEquals(nextResult, result.nextPage()); + assertEquals("c", result.nextPageCursor()); + assertEquals(VALUES1, result.values()); + } + + @Test + public void testPageAsync() throws ExecutionException, InterruptedException { + final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2); + AsyncPageImpl.NextPageFetcher fetcher = new AsyncPageImpl.NextPageFetcher() { + private static final long serialVersionUID = 4703765400378593176L; + + @Override + public Future> nextPage() { + return Futures.>immediateFuture(nextResult); + } + }; + AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1); + assertEquals(nextResult, result.nextPageAsync().get()); + assertEquals("c", result.nextPageCursor()); + assertEquals(VALUES1, result.values()); + } + + @Test + public void testIterateAll() { + final AsyncPageImpl nextResult2 = new AsyncPageImpl<>(null, "c3", VALUES3); + AsyncPageImpl.NextPageFetcher fetcher2 = new AsyncPageImpl.NextPageFetcher() { + private static final long serialVersionUID = -9203621430631884026L; + + @Override + public Future> nextPage() { + return Futures.>immediateFuture(nextResult2); + } + }; + final AsyncPageImpl nextResult1 = new AsyncPageImpl<>(fetcher2, "c2", VALUES2); + AsyncPageImpl.NextPageFetcher fetcher1 = new AsyncPageImpl.NextPageFetcher() { + private static final long serialVersionUID = -9203621430631884026L; + + @Override + public Future> nextPage() { + return Futures.>immediateFuture(nextResult1); + } + }; + AsyncPageImpl result = new AsyncPageImpl<>(fetcher1, "c1", VALUES1); + assertEquals(ALL_VALUES, ImmutableList.copyOf(result.iterateAll())); + } + + @Test + public void testAsyncPageAndIterateAll() throws ExecutionException, InterruptedException { + final AsyncPageImpl nextResult2 = new AsyncPageImpl<>(null, "c3", VALUES3); + AsyncPageImpl.NextPageFetcher fetcher2 = new AsyncPageImpl.NextPageFetcher() { + private static final long serialVersionUID = -9203621430631884026L; + + @Override + public Future> nextPage() { + return Futures.>immediateFuture(nextResult2); + } + }; + final AsyncPageImpl nextResult1 = new AsyncPageImpl<>(fetcher2, "c2", VALUES2); + AsyncPageImpl.NextPageFetcher fetcher1 = new AsyncPageImpl.NextPageFetcher() { + private static final long serialVersionUID = -9203621430631884026L; + + @Override + public Future> nextPage() { + return Futures.>immediateFuture(nextResult1); + } + }; + AsyncPageImpl result = new AsyncPageImpl<>(fetcher1, "c1", VALUES1); + assertEquals(nextResult1, result.nextPageAsync().get()); + assertEquals("c1", result.nextPageCursor()); + assertEquals(VALUES1, result.values()); + assertEquals(SOME_VALUES, ImmutableList.copyOf(result.nextPageAsync().get().iterateAll())); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java index 07d979ad85..40db43b61d 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java @@ -35,6 +35,8 @@ public class PageImplTest { public void testPage() { final PageImpl nextResult = new PageImpl<>(null, "c", NEXT_VALUES); PageImpl.NextPageFetcher fetcher = new PageImpl.NextPageFetcher() { + private static final long serialVersionUID = -1714571149183431798L; + @Override public PageImpl nextPage() { return nextResult; From 0658191fc8bf2dd3fb0ccf2c979df40b273108af Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 10 May 2016 15:58:04 +0200 Subject: [PATCH 188/663] Add TopicId and SubscriptionId classes (#984) * Add TopicId class and tests. Use TopicId in SubscriptionInfo * Add SubscriptionId class and tests. Use SubscriptionId in listSubscriptions(topic) * Minor javadoc fixes * Add identity for deleted topics --- .../src/main/java/com/google/cloud/AsyncPage.java | 5 +++-- .../src/main/java/com/google/cloud/AsyncPageImpl.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java index d82d46f19b..8d7ff026e7 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java @@ -37,7 +37,7 @@ * for (T value : page.values()) { * // do something with value * } - * page = page.nextPage().get(); + * page = page.nextPageAsync().get(); * }}
    * * @param the value type that the page holds @@ -45,7 +45,8 @@ public interface AsyncPage extends Page { /** - * Returns a {@link Future} object for the next page. + * Returns a {@link Future} object for the next page. {@link Future#get()} returns {@code null} if + * the last page has been reached. */ Future> nextPageAsync(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index 42af7b34a9..706316e362 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -17,6 +17,7 @@ package com.google.cloud; import com.google.common.base.Throwables; +import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Uninterruptibles; import java.io.Serializable; @@ -47,7 +48,7 @@ private static class SyncNextPageFetcher implements PageImpl.NextPageFetcher< private static final long serialVersionUID = -4124568632363525351L; - private NextPageFetcher asyncPageFetcher; + private final NextPageFetcher asyncPageFetcher; private SyncNextPageFetcher(NextPageFetcher asyncPageFetcher) { this.asyncPageFetcher = asyncPageFetcher; @@ -75,7 +76,7 @@ public AsyncPageImpl(NextPageFetcher asyncPageFetcher, String cursor, Iterabl @Override public Future> nextPageAsync() { if (nextPageCursor() == null || asyncPageFetcher == null) { - return null; + return Futures.immediateCheckedFuture(null); } return asyncPageFetcher.nextPage(); } From bedad4a857acdc0a1bc12ebfde5949fff41eef9a Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 12 May 2016 08:40:31 +0200 Subject: [PATCH 189/663] Add tests and javadoc for Message and ByteArray (#1000) * Add tests and javadoc for Message and ByteArray * Add final on static ByteArray methods back --- .../main/java/com/google/cloud/ByteArray.java | 61 +++++---- .../java/com/google/cloud/ByteArrayTest.java | 116 ++++++++++++++++++ 2 files changed, 146 insertions(+), 31 deletions(-) create mode 100644 google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java index f23fb0876b..6a8e3dddd0 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import com.google.common.base.MoreObjects.ToStringHelper; import com.google.protobuf.ByteString; -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; @@ -35,6 +33,7 @@ public class ByteArray implements Iterable, Serializable { private static final long serialVersionUID = -1908809133893782840L; + private final ByteString byteString; protected ByteArray(ByteString byteString) { @@ -75,43 +74,38 @@ public final boolean equals(Object obj) { } /** - * Returns the size of this blob. + * Returns the number of bytes in this {@code ByteArray}. */ public final int length() { return byteString.size(); } /** - * Returns a copy as byte array. + * Returns a copy of this {@code ByteArray} as an array of bytes. */ public final byte[] toByteArray() { return byteString.toByteArray(); } /** - * Returns the content as {@code UTF-8} string. + * Returns a copy of this {@code ByteArray} as an {@code UTF-8} string. */ public final String toStringUtf8() { return byteString.toStringUtf8(); } /** - * Returns a read-only {@link ByteBuffer} for this blob content. + * Returns the content of this {@code ByteArray} as a read-only {@link ByteBuffer}. */ public final ByteBuffer asReadOnlyByteBuffer() { return byteString.asReadOnlyByteBuffer(); } /** - * Returns an {@link InputStream} for this blob content. + * Returns an {@link InputStream} for this {@code ByteArray} content. */ public final InputStream asInputStream() { - final ByteBuffer byteBuffer = asReadOnlyByteBuffer(); - return new InputStream() { - @Override public int read() { - return !byteBuffer.hasRemaining() ? -1 : byteBuffer.get() & 0xFF; - } - }; + return byteString.newInput(); } protected ByteString byteString() { @@ -119,47 +113,52 @@ protected ByteString byteString() { } /** - * Copies bytes into a ByteBuffer. + * Copies the content of this {@code ByteArray} into an existing {@code ByteBuffer}. * * @throws java.nio.ReadOnlyBufferException if the target is read-only - * @throws java.nio.BufferOverflowException if the target's remaining() space is not large - * enough to hold the data + * @throws java.nio.BufferOverflowException if the target's {@link ByteBuffer#remaining()} space + * is not large enough to hold the data */ public final void copyTo(ByteBuffer target) { byteString.copyTo(target); } /** - * Copies bytes into a buffer. + * Copies the content of this {@code ByteArray} into an array of bytes. * - * @throws IndexOutOfBoundsException if an offset or size is negative or too large + * @throws IndexOutOfBoundsException if the target is not large enough to hold the data */ public final void copyTo(byte[] target) { byteString.copyTo(target, 0, 0, length()); } - public static final ByteArray copyFrom(byte[] bytes) { + /** + * Creates a {@code ByteArray} object given an array of bytes. The bytes are copied. + */ + public final static ByteArray copyFrom(byte[] bytes) { return new ByteArray(ByteString.copyFrom(bytes)); } /** - * Copy the bytes using {@code UTF-8} decoding. + * Creates a {@code ByteArray} object given a string. The string is encoded in {@code UTF-8}. The + * bytes are copied. */ - public static final ByteArray copyFrom(String string) { + public final static ByteArray copyFrom(String string) { return new ByteArray(ByteString.copyFrom(string, StandardCharsets.UTF_8)); } - public static final ByteArray copyFrom(ByteBuffer bytes) { + /** + * Creates a {@code ByteArray} object given a {@link ByteBuffer}. The bytes are copied. + */ + public final static ByteArray copyFrom(ByteBuffer bytes) { return new ByteArray(ByteString.copyFrom(bytes)); } - public static final ByteArray copyFrom(InputStream input) throws IOException { - BufferedInputStream bufferedInput = new BufferedInputStream(input); - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - int value; - while ((value = bufferedInput.read()) != -1) { - bytes.write(value); - } - return copyFrom(bytes.toByteArray()); + /** + * Creates a {@code ByteArray} object given an {@link InputStream}. The stream is read into the + * created object. + */ + public final static ByteArray copyFrom(InputStream input) throws IOException { + return new ByteArray(ByteString.readFrom(input)); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java b/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java new file mode 100644 index 0000000000..0adf2fe8be --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java @@ -0,0 +1,116 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import com.google.common.io.ByteStreams; +import com.google.protobuf.ByteString; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + +public class ByteArrayTest { + + private static final String STRING_CONTENT = "Hello, ByteArray!"; + private static final byte[] BYTES_CONTENT = STRING_CONTENT.getBytes(StandardCharsets.UTF_8); + private static final ByteBuffer BYTE_BUFFER_CONTENT = ByteBuffer.wrap(BYTES_CONTENT); + private static final InputStream STREAM_CONTENT = new ByteArrayInputStream(BYTES_CONTENT); + private static final ByteArray STRING_ARRAY = ByteArray.copyFrom(STRING_CONTENT); + private static final ByteArray BYTES_ARRAY = ByteArray.copyFrom(BYTES_CONTENT); + private static final ByteArray BYTE_BUFFER_ARRAY = ByteArray.copyFrom(BYTE_BUFFER_CONTENT); + private static final ByteArray ARRAY = new ByteArray(ByteString.copyFrom(BYTES_CONTENT)); + + private static ByteArray streamArray; + + @BeforeClass + public static void beforeClass() throws IOException { + streamArray = ByteArray.copyFrom(STREAM_CONTENT); + BYTE_BUFFER_CONTENT.flip(); + } + + @Test + public void testCopyFromString() throws IOException { + assertEquals(STRING_CONTENT, STRING_ARRAY.toStringUtf8()); + assertArrayEquals(BYTES_CONTENT, STRING_ARRAY.toByteArray()); + assertEquals(BYTE_BUFFER_CONTENT.asReadOnlyBuffer(), STRING_ARRAY.asReadOnlyByteBuffer()); + assertArrayEquals(BYTES_CONTENT, ByteStreams.toByteArray(STRING_ARRAY.asInputStream())); + } + + @Test + public void testCopyFromByteArray() throws IOException { + assertEquals(STRING_CONTENT, BYTES_ARRAY.toStringUtf8()); + assertArrayEquals(BYTES_CONTENT, BYTES_ARRAY.toByteArray()); + assertEquals(BYTE_BUFFER_CONTENT.asReadOnlyBuffer(), BYTES_ARRAY.asReadOnlyByteBuffer()); + assertArrayEquals(BYTES_CONTENT, ByteStreams.toByteArray(BYTES_ARRAY.asInputStream())); + } + + @Test + public void testCopyFromByteBuffer() throws IOException { + assertEquals(STRING_CONTENT, BYTE_BUFFER_ARRAY.toStringUtf8()); + assertArrayEquals(BYTES_CONTENT, BYTE_BUFFER_ARRAY.toByteArray()); + assertEquals(BYTE_BUFFER_CONTENT.asReadOnlyBuffer(), BYTE_BUFFER_ARRAY.asReadOnlyByteBuffer()); + assertArrayEquals(BYTES_CONTENT, ByteStreams.toByteArray(BYTE_BUFFER_ARRAY.asInputStream())); + } + + @Test + public void testCopyFromStream() throws IOException { + assertEquals(STRING_CONTENT, streamArray.toStringUtf8()); + assertArrayEquals(BYTES_CONTENT, streamArray.toByteArray()); + assertEquals(BYTE_BUFFER_CONTENT.asReadOnlyBuffer(), streamArray.asReadOnlyByteBuffer()); + assertArrayEquals(BYTES_CONTENT, ByteStreams.toByteArray(streamArray.asInputStream())); + } + + @Test + public void testLength() { + assertEquals(BYTES_CONTENT.length, ARRAY.length()); + } + + @Test + public void testToStringUtf8() { + assertEquals(STRING_CONTENT, ARRAY.toStringUtf8()); + } + + @Test + public void testToByteArray() { + assertArrayEquals(BYTES_CONTENT, ARRAY.toByteArray()); + } + + @Test + public void testAsReadOnlyByteBuffer() { + assertEquals(BYTE_BUFFER_CONTENT.asReadOnlyBuffer(), ARRAY.asReadOnlyByteBuffer()); + } + + @Test + public void testAsInputStream() throws IOException { + assertArrayEquals(BYTES_CONTENT, ByteStreams.toByteArray(ARRAY.asInputStream())); + } + + @Test + public void testHashCode() { + assertEquals(STRING_ARRAY.hashCode(), BYTES_ARRAY.hashCode()); + assertEquals(BYTES_ARRAY.hashCode(), BYTE_BUFFER_ARRAY.hashCode()); + assertEquals(BYTE_BUFFER_ARRAY.hashCode(), streamArray.hashCode()); + } +} From 827a94d9ae14eefb6aea4a991259db8f1c142ee6 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 16 May 2016 20:26:09 +0200 Subject: [PATCH 190/663] Add base service option classes for gRPC and HTTP services (#1011) * Add base service option classes for gRPC and HTTP services * Rename ExecutorProvider to ExecutorFactory, refactor shutdown and serialization --- .../com/google/cloud/GrpcServiceOptions.java | 256 ++++++++++++++++++ .../com/google/cloud/HttpServiceOptions.java | 227 ++++++++++++++++ .../java/com/google/cloud/ServiceOptions.java | 146 +--------- .../google/cloud/GrpcServiceOptionsTest.java | 218 +++++++++++++++ .../google/cloud/HttpServiceOptionsTest.java | 163 +++++++++++ .../com/google/cloud/ServiceOptionsTest.java | 18 -- 6 files changed, 869 insertions(+), 159 deletions(-) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java new file mode 100644 index 0000000000..2a1110c936 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java @@ -0,0 +1,256 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.base.MoreObjects.firstNonNull; + +import com.google.cloud.spi.ServiceRpcFactory; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; + +import io.grpc.internal.SharedResourceHolder; +import io.grpc.internal.SharedResourceHolder.Resource; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.util.Objects; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * Abstract class representing service options for those services that use gRPC as the transport + * layer. + * + * @param the service subclass + * @param the spi-layer class corresponding to the service + * @param the {@code ServiceOptions} subclass corresponding to the service + */ +public abstract class GrpcServiceOptions, ServiceRpcT, + OptionsT extends GrpcServiceOptions> + extends ServiceOptions { + + private static final long serialVersionUID = 6415982522610509549L; + private final String executorFactoryClassName; + private final int initialTimeout; + private final double timeoutMultiplier; + private final int maxTimeout; + + private transient ExecutorFactory executorFactory; + + /** + * Shared thread pool executor. + */ + private static final Resource EXECUTOR = + new Resource() { + @Override + public ScheduledExecutorService create() { + ScheduledThreadPoolExecutor service = new ScheduledThreadPoolExecutor(8); + service.setKeepAliveTime(5, TimeUnit.SECONDS); + service.allowCoreThreadTimeOut(true); + service.setRemoveOnCancelPolicy(true); + return service; + } + + @Override + public void close(ScheduledExecutorService instance) { + instance.shutdown(); + } + }; + + /** + * An interface for {@link ScheduledExecutorService} factories. Implementations of this interface + * can be used to provide an user-defined scheduled executor to execute requests. Any + * implementation of this interface must override the {@code get()} method to return the desired + * executor. The {@code release(executor)} method should be overriden to free resources used by + * the executor (if needed) according to application's logic. + * + *

    Implementation must provide a public no-arg constructor. Loading of a factory implementation + * is done via {@link java.util.ServiceLoader}. + */ + public interface ExecutorFactory { + + /** + * Gets a scheduled executor service instance. + */ + ScheduledExecutorService get(); + + /** + * Releases resources used by the executor and possibly shuts it down. + */ + void release(ScheduledExecutorService executor); + } + + @VisibleForTesting + static class DefaultExecutorFactory implements ExecutorFactory { + + private static final DefaultExecutorFactory INSTANCE = new DefaultExecutorFactory(); + + @Override + public ScheduledExecutorService get() { + return SharedResourceHolder.get(EXECUTOR); + } + + @Override + public synchronized void release(ScheduledExecutorService executor) { + SharedResourceHolder.release(EXECUTOR, executor); + } + } + + /** + * Builder for {@code GrpcServiceOptions}. + * + * @param the service subclass + * @param the spi-layer class corresponding to the service + * @param the {@code GrpcServiceOptions} subclass corresponding to the service + * @param the {@code ServiceOptions} builder + */ + protected abstract static class Builder, ServiceRpcT, + OptionsT extends GrpcServiceOptions, + B extends Builder> + extends ServiceOptions.Builder { + + private ExecutorFactory executorFactory; + private int initialTimeout = 20_000; + private double timeoutMultiplier = 1.5; + private int maxTimeout = 100_000; + + protected Builder() {} + + protected Builder(GrpcServiceOptions options) { + super(options); + executorFactory = options.executorFactory; + initialTimeout = options.initialTimeout; + timeoutMultiplier = options.timeoutMultiplier; + maxTimeout = options.maxTimeout; + } + + @Override + protected abstract GrpcServiceOptions build(); + + /** + * Sets the scheduled executor factory. This method can be used to provide an user-defined + * scheduled executor to execute requests. + * + * @return the builder + */ + public B executorFactory(ExecutorFactory executorFactory) { + this.executorFactory = executorFactory; + return self(); + } + + /** + * Sets the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value + * adjusted according to {@link #timeoutMultiplier(double)}. Default value is 20000. + * + * @throws IllegalArgumentException if the provided timeout is < 0 + * @return the builder + */ + public B initialTimeout(int initialTimeout) { + Preconditions.checkArgument(initialTimeout > 0, "Initial timeout must be > 0"); + this.initialTimeout = initialTimeout; + return self(); + } + + /** + * Sets the timeout multiplier. This value is used to compute the timeout for a retried RPC. + * Timeout is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. + * + * @throws IllegalArgumentException if the provided timeout multiplier is < 0 + * @return the builder + */ + public B timeoutMultiplier(double timeoutMultiplier) { + Preconditions.checkArgument(timeoutMultiplier >= 1.0, "Timeout multiplier must be >= 1"); + this.timeoutMultiplier = timeoutMultiplier; + return self(); + } + + /** + * Sets the maximum timeout for a RPC call, in milliseconds. Default value is 100000. If + * {@code maxTimeout} is lower than the initial timeout the {@link #initialTimeout(int)} value + * is used instead. + * + * @return the builder + */ + public B maxTimeout(int maxTimeout) { + this.maxTimeout = maxTimeout; + return self(); + } + } + + protected GrpcServiceOptions( + Class> serviceFactoryClass, + Class> rpcFactoryClass, Builder builder) { + super(serviceFactoryClass, rpcFactoryClass, builder); + executorFactory = firstNonNull(builder.executorFactory, + getFromServiceLoader(ExecutorFactory.class, DefaultExecutorFactory.INSTANCE)); + executorFactoryClassName = executorFactory.getClass().getName(); + initialTimeout = builder.initialTimeout; + timeoutMultiplier = builder.timeoutMultiplier; + maxTimeout = builder.maxTimeout <= initialTimeout ? initialTimeout : builder.maxTimeout; + } + + /** + * Returns a scheduled executor service provider. + */ + protected ExecutorFactory executorFactory() { + return executorFactory; + } + + /** + * Returns the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value + * adjusted according to {@link #timeoutMultiplier()}. Default value is 20000. + */ + public int initialTimeout() { + return initialTimeout; + } + + /** + * Returns the timeout multiplier. This values is used to compute the timeout for a RPC. Timeout + * is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. + */ + public double timeoutMultiplier() { + return timeoutMultiplier; + } + + /** + * Returns the maximum timeout for a RPC call, in milliseconds. Default value is 100000. + */ + public int maxTimeout() { + return maxTimeout; + } + + @Override + protected int baseHashCode() { + return Objects.hash(super.baseHashCode(), executorFactoryClassName, initialTimeout, + timeoutMultiplier, maxTimeout); + } + + protected boolean baseEquals(GrpcServiceOptions other) { + return super.baseEquals(other) + && Objects.equals(executorFactoryClassName, other.executorFactoryClassName) + && Objects.equals(initialTimeout, other.initialTimeout) + && Objects.equals(timeoutMultiplier, other.timeoutMultiplier) + && Objects.equals(maxTimeout, other.maxTimeout); + } + + private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException { + input.defaultReadObject(); + executorFactory = newInstance(executorFactoryClassName); + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java new file mode 100644 index 0000000000..eca411849e --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java @@ -0,0 +1,227 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.base.MoreObjects.firstNonNull; + +import com.google.api.client.extensions.appengine.http.UrlFetchTransport; +import com.google.api.client.http.HttpRequest; +import com.google.api.client.http.HttpRequestInitializer; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.auth.http.HttpCredentialsAdapter; +import com.google.cloud.spi.ServiceRpcFactory; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.util.Objects; + +/** + * Abstract class representing service options for those services that use HTTP as the transport + * layer. + * + * @param the service subclass + * @param the spi-layer class corresponding to the service + * @param the {@code ServiceOptions} subclass corresponding to the service + */ +public abstract class HttpServiceOptions, ServiceRpcT, + OptionsT extends HttpServiceOptions> + extends ServiceOptions { + + private static final long serialVersionUID = 3652819407083815771L; + private final int connectTimeout; + private final int readTimeout; + private final String httpTransportFactoryClassName; + + private transient HttpTransportFactory httpTransportFactory; + + /** + * A base interface for all {@link HttpTransport} factories. + * + *

    Implementation must provide a public no-arg constructor. Loading of a factory implementation + * is done via {@link java.util.ServiceLoader}. + */ + public interface HttpTransportFactory { + HttpTransport create(); + } + + public static class DefaultHttpTransportFactory implements HttpTransportFactory { + + private static final HttpTransportFactory INSTANCE = new DefaultHttpTransportFactory(); + + @Override + public HttpTransport create() { + // Consider App Engine + if (appEngineAppId() != null) { + try { + return new UrlFetchTransport(); + } catch (Exception ignore) { + // Maybe not on App Engine + } + } + return new NetHttpTransport(); + } + } + + /** + * Builder for {@code HttpServiceOptions}. + * + * @param the service subclass + * @param the spi-layer class corresponding to the service + * @param the {@code HttpServiceOptions} subclass corresponding to the service + * @param the {@code ServiceOptions} builder + */ + protected abstract static class Builder, ServiceRpcT, + OptionsT extends HttpServiceOptions, + B extends Builder> + extends ServiceOptions.Builder { + + private HttpTransportFactory httpTransportFactory; + private int connectTimeout = -1; + private int readTimeout = -1; + + protected Builder() {} + + protected Builder(HttpServiceOptions options) { + super(options); + httpTransportFactory = options.httpTransportFactory; + connectTimeout = options.connectTimeout; + readTimeout = options.readTimeout; + } + + @Override + protected abstract HttpServiceOptions build(); + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + + /** + * Sets the HTTP transport factory. + * + * @return the builder + */ + public B httpTransportFactory(HttpTransportFactory httpTransportFactory) { + this.httpTransportFactory = httpTransportFactory; + return self(); + } + + /** + * Sets the timeout in milliseconds to establish a connection. + * + * @param connectTimeout connection timeout in milliseconds. 0 for an infinite timeout, a + * negative number for the default value (20000). + * @return the builder + */ + public B connectTimeout(int connectTimeout) { + this.connectTimeout = connectTimeout; + return self(); + } + + /** + * Sets the timeout in milliseconds to read data from an established connection. + * + * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a negative number + * for the default value (20000). + * @return the builder + */ + public B readTimeout(int readTimeout) { + this.readTimeout = readTimeout; + return self(); + } + } + + protected HttpServiceOptions( + Class> serviceFactoryClass, + Class> rpcFactoryClass, Builder builder) { + super(serviceFactoryClass, rpcFactoryClass, builder); + httpTransportFactory = firstNonNull(builder.httpTransportFactory, + getFromServiceLoader(HttpTransportFactory.class, DefaultHttpTransportFactory.INSTANCE)); + httpTransportFactoryClassName = httpTransportFactory.getClass().getName(); + connectTimeout = builder.connectTimeout; + readTimeout = builder.readTimeout; + } + + /** + * Returns the HTTP transport factory. + */ + public HttpTransportFactory httpTransportFactory() { + return httpTransportFactory; + } + + + /** + * Returns a request initializer responsible for initializing requests according to service + * options. + */ + public HttpRequestInitializer httpRequestInitializer() { + final HttpRequestInitializer delegate = + authCredentials() != null && authCredentials().credentials() != null + ? new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes())) + : null; + return new HttpRequestInitializer() { + @Override + public void initialize(HttpRequest httpRequest) throws IOException { + if (delegate != null) { + delegate.initialize(httpRequest); + } + if (connectTimeout >= 0) { + httpRequest.setConnectTimeout(connectTimeout); + } + if (readTimeout >= 0) { + httpRequest.setReadTimeout(readTimeout); + } + } + }; + } + + /** + * Returns the timeout in milliseconds to establish a connection. 0 is an infinite timeout, a + * negative number is the default value (20000). + */ + public int connectTimeout() { + return connectTimeout; + } + + /** + * Returns the timeout in milliseconds to read from an established connection. 0 is an infinite + * timeout, a negative number is the default value (20000). + */ + public int readTimeout() { + return readTimeout; + } + + @Override + protected int baseHashCode() { + return Objects.hash(super.baseHashCode(), httpTransportFactoryClassName, connectTimeout, + readTimeout); + } + + protected boolean baseEquals(HttpServiceOptions other) { + return super.baseEquals(other) + && Objects.equals(httpTransportFactoryClassName, other.httpTransportFactoryClassName) + && Objects.equals(connectTimeout, other.connectTimeout) + && Objects.equals(readTimeout, other.readTimeout); + } + + private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException { + input.defaultReadObject(); + httpTransportFactory = newInstance(httpTransportFactoryClassName); + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index d2f648b01f..8a1d95f32e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -20,12 +20,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static java.nio.charset.StandardCharsets.UTF_8; -import com.google.api.client.extensions.appengine.http.UrlFetchTransport; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpRequestInitializer; -import com.google.api.client.http.HttpTransport; -import com.google.api.client.http.javanet.NetHttpTransport; -import com.google.auth.http.HttpCredentialsAdapter; import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.collect.Iterables; import com.google.common.io.Files; @@ -70,60 +64,28 @@ public abstract class ServiceOptions, Service OptionsT extends ServiceOptions> implements Serializable { private static final String DEFAULT_HOST = "https://www.googleapis.com"; - private static final long serialVersionUID = 1203687993961393350L; private static final String PROJECT_ENV_NAME = "GCLOUD_PROJECT"; private static final String MANIFEST_ARTIFACT_ID_KEY = "artifactId"; private static final String MANIFEST_VERSION_KEY = "Implementation-Version"; private static final String ARTIFACT_ID = "gcloud-java-core"; private static final String APPLICATION_BASE_NAME = "gcloud-java"; private static final String APPLICATION_NAME = getApplicationName(); + private static final long serialVersionUID = -6410263550484023006L; private final String projectId; private final String host; - private final String httpTransportFactoryClassName; private final RestorableState authCredentialsState; private final RetryParams retryParams; private final String serviceRpcFactoryClassName; private final String serviceFactoryClassName; - private final int connectTimeout; - private final int readTimeout; private final Clock clock; - private transient HttpTransportFactory httpTransportFactory; private transient AuthCredentials authCredentials; private transient ServiceRpcFactory serviceRpcFactory; private transient ServiceFactory serviceFactory; private transient ServiceT service; private transient ServiceRpcT rpc; - /** - * A base interface for all {@link HttpTransport} factories. - * - *

    Implementation must provide a public no-arg constructor. Loading of a factory implementation - * is done via {@link java.util.ServiceLoader}. - */ - public interface HttpTransportFactory { - HttpTransport create(); - } - - public static class DefaultHttpTransportFactory implements HttpTransportFactory { - - private static final HttpTransportFactory INSTANCE = new DefaultHttpTransportFactory(); - - @Override - public HttpTransport create() { - // Consider App Engine - if (appEngineAppId() != null) { - try { - return new UrlFetchTransport(); - } catch (Exception ignore) { - // Maybe not on App Engine - } - } - return new NetHttpTransport(); - } - } - /** * Builder for {@code ServiceOptions}. * @@ -138,13 +100,10 @@ protected abstract static class Builder, Serv private String projectId; private String host; - private HttpTransportFactory httpTransportFactory; private AuthCredentials authCredentials; private RetryParams retryParams; private ServiceFactory serviceFactory; private ServiceRpcFactory serviceRpcFactory; - private int connectTimeout = -1; - private int readTimeout = -1; private Clock clock; protected Builder() {} @@ -152,13 +111,10 @@ protected Builder() {} protected Builder(ServiceOptions options) { projectId = options.projectId; host = options.host; - httpTransportFactory = options.httpTransportFactory; authCredentials = options.authCredentials; retryParams = options.retryParams; serviceFactory = options.serviceFactory; serviceRpcFactory = options.serviceRpcFactory; - connectTimeout = options.connectTimeout; - readTimeout = options.readTimeout; clock = options.clock; } @@ -209,16 +165,6 @@ public B host(String host) { return self(); } - /** - * Sets the transport factory. - * - * @return the builder - */ - public B httpTransportFactory(HttpTransportFactory httpTransportFactory) { - this.httpTransportFactory = httpTransportFactory; - return self(); - } - /** * Sets the service authentication credentials. * @@ -250,30 +196,6 @@ public B serviceRpcFactory(ServiceRpcFactory serviceRpcFa this.serviceRpcFactory = serviceRpcFactory; return self(); } - - /** - * Sets the timeout in milliseconds to establish a connection. - * - * @param connectTimeout connection timeout in milliseconds. 0 for an infinite timeout, a - * negative number for the default value (20000). - * @return the builder - */ - public B connectTimeout(int connectTimeout) { - this.connectTimeout = connectTimeout; - return self(); - } - - /** - * Sets the timeout in milliseconds to read data from an established connection. - * - * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a negative number - * for the default value (20000). - * @return the builder - */ - public B readTimeout(int readTimeout) { - this.readTimeout = readTimeout; - return self(); - } } protected ServiceOptions(Class> serviceFactoryClass, @@ -287,9 +209,6 @@ protected ServiceOptions(Class> ser + "or the environment. Please set a project ID using the builder."); } host = firstNonNull(builder.host, defaultHost()); - httpTransportFactory = firstNonNull(builder.httpTransportFactory, - getFromServiceLoader(HttpTransportFactory.class, DefaultHttpTransportFactory.INSTANCE)); - httpTransportFactoryClassName = httpTransportFactory.getClass().getName(); authCredentials = builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials(); authCredentialsState = authCredentials != null ? authCredentials.capture() : null; @@ -300,8 +219,6 @@ protected ServiceOptions(Class> ser serviceRpcFactory = firstNonNull(builder.serviceRpcFactory, getFromServiceLoader(rpcFactoryClass, defaultRpcFactory())); serviceRpcFactoryClassName = serviceRpcFactory.getClass().getName(); - connectTimeout = builder.connectTimeout; - readTimeout = builder.readTimeout; clock = firstNonNull(builder.clock, Clock.defaultClock()); } @@ -492,13 +409,6 @@ public String host() { return host; } - /** - * Returns the transport factory. - */ - public HttpTransportFactory httpTransportFactory() { - return httpTransportFactory; - } - /** * Returns the authentication credentials. */ @@ -514,47 +424,6 @@ public RetryParams retryParams() { return retryParams; } - /** - * Returns a request initializer responsible for initializing requests according to service - * options. - */ - public HttpRequestInitializer httpRequestInitializer() { - final HttpRequestInitializer delegate = - authCredentials() != null && authCredentials.credentials() != null - ? new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes())) - : null; - return new HttpRequestInitializer() { - @Override - public void initialize(HttpRequest httpRequest) throws IOException { - if (delegate != null) { - delegate.initialize(httpRequest); - } - if (connectTimeout >= 0) { - httpRequest.setConnectTimeout(connectTimeout); - } - if (readTimeout >= 0) { - httpRequest.setReadTimeout(readTimeout); - } - } - }; - } - - /** - * Returns the timeout in milliseconds to establish a connection. 0 is an infinite timeout, a - * negative number is the default value (20000). - */ - public int connectTimeout() { - return connectTimeout; - } - - /** - * Returns the timeout in milliseconds to read from an established connection. 0 is an infinite - * timeout, a negative number is the default value (20000). - */ - public int readTimeout() { - return readTimeout; - } - /** * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to get * current time. @@ -571,34 +440,29 @@ public String applicationName() { } protected int baseHashCode() { - return Objects.hash(projectId, host, httpTransportFactoryClassName, authCredentialsState, - retryParams, serviceFactoryClassName, serviceRpcFactoryClassName, connectTimeout, - readTimeout, clock); + return Objects.hash(projectId, host, authCredentialsState, retryParams, serviceFactoryClassName, + serviceRpcFactoryClassName, clock); } protected boolean baseEquals(ServiceOptions other) { return Objects.equals(projectId, other.projectId) && Objects.equals(host, other.host) - && Objects.equals(httpTransportFactoryClassName, other.httpTransportFactoryClassName) && Objects.equals(authCredentialsState, other.authCredentialsState) && Objects.equals(retryParams, other.retryParams) && Objects.equals(serviceFactoryClassName, other.serviceFactoryClassName) && Objects.equals(serviceRpcFactoryClassName, other.serviceRpcFactoryClassName) - && Objects.equals(connectTimeout, other.connectTimeout) - && Objects.equals(readTimeout, other.readTimeout) && Objects.equals(clock, clock); } private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException { input.defaultReadObject(); - httpTransportFactory = newInstance(httpTransportFactoryClassName); serviceFactory = newInstance(serviceFactoryClassName); serviceRpcFactory = newInstance(serviceRpcFactoryClassName); authCredentials = authCredentialsState != null ? authCredentialsState.restore() : null; } @SuppressWarnings("unchecked") - private static T newInstance(String className) throws IOException, ClassNotFoundException { + static T newInstance(String className) throws IOException, ClassNotFoundException { try { return (T) Class.forName(className).newInstance(); } catch (InstantiationException | IllegalAccessException e) { @@ -623,7 +487,7 @@ protected RetryParams defaultRetryParams() { return RetryParams.defaultInstance(); } - private static T getFromServiceLoader(Class clazz, T defaultInstance) { + static T getFromServiceLoader(Class clazz, T defaultInstance) { return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java new file mode 100644 index 0000000000..0a3c34f879 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java @@ -0,0 +1,218 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.google.cloud.GrpcServiceOptions.DefaultExecutorFactory; +import com.google.cloud.GrpcServiceOptions.ExecutorFactory; +import com.google.cloud.spi.ServiceRpcFactory; + +import org.easymock.EasyMock; +import org.junit.Test; + +import java.util.Set; +import java.util.concurrent.ScheduledExecutorService; + +public class GrpcServiceOptionsTest { + + private static final ExecutorFactory MOCK_EXECUTOR_FACTORY = + EasyMock.createMock(ExecutorFactory.class); + private static final TestGrpcServiceOptions OPTIONS = TestGrpcServiceOptions.builder() + .projectId("project-id") + .initialTimeout(1234) + .timeoutMultiplier(1.6) + .maxTimeout(5678) + .executorFactory(MOCK_EXECUTOR_FACTORY) + .build(); + private static final TestGrpcServiceOptions DEFAULT_OPTIONS = + TestGrpcServiceOptions.builder().projectId("project-id").build(); + private static final TestGrpcServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); + + private interface TestService extends Service {} + + private static class TestServiceImpl + extends BaseService implements TestService { + private TestServiceImpl(TestGrpcServiceOptions options) { + super(options); + } + } + + private interface TestServiceFactory extends ServiceFactory { + } + + private static class DefaultTestServiceFactory implements TestServiceFactory { + private static final TestServiceFactory INSTANCE = new DefaultTestServiceFactory(); + + @Override + public TestService create(TestGrpcServiceOptions options) { + return new TestServiceImpl(options); + } + } + + private interface TestServiceRpcFactory + extends ServiceRpcFactory {} + + private static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory { + private static final TestServiceRpcFactory INSTANCE = new DefaultTestServiceRpcFactory(); + + @Override + public TestServiceRpc create(TestGrpcServiceOptions options) { + return new DefaultTestServiceRpc(options); + } + } + + private interface TestServiceRpc {} + + private static class DefaultTestServiceRpc implements TestServiceRpc { + DefaultTestServiceRpc(TestGrpcServiceOptions options) {} + } + + private static class TestGrpcServiceOptions + extends GrpcServiceOptions { + private static class Builder + extends GrpcServiceOptions.Builder { + private Builder() {} + + private Builder(TestGrpcServiceOptions options) { + super(options); + } + + @Override + protected TestGrpcServiceOptions build() { + return new TestGrpcServiceOptions(this); + } + } + + private TestGrpcServiceOptions(Builder builder) { + super(TestServiceFactory.class, TestServiceRpcFactory.class, builder); + } + + @Override + protected TestServiceFactory defaultServiceFactory() { + return DefaultTestServiceFactory.INSTANCE; + } + + @Override + protected TestServiceRpcFactory defaultRpcFactory() { + return DefaultTestServiceRpcFactory.INSTANCE; + } + + @Override + protected Set scopes() { + return null; + } + + @Override + public Builder toBuilder() { + return new Builder(this); + } + + private static Builder builder() { + return new Builder(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof TestGrpcServiceOptions && baseEquals((TestGrpcServiceOptions) obj); + } + + @Override + public int hashCode() { + return baseHashCode(); + } + } + + @Test + public void testBuilder() { + assertEquals(1234, OPTIONS.initialTimeout()); + assertEquals(1.6, OPTIONS.timeoutMultiplier(), 0.0); + assertEquals(5678, OPTIONS.maxTimeout()); + assertSame(MOCK_EXECUTOR_FACTORY, OPTIONS.executorFactory()); + assertEquals(20000, DEFAULT_OPTIONS.initialTimeout()); + assertEquals(1.5, DEFAULT_OPTIONS.timeoutMultiplier(), 0.0); + assertEquals(100000, DEFAULT_OPTIONS.maxTimeout()); + assertTrue(DEFAULT_OPTIONS.executorFactory() instanceof DefaultExecutorFactory); + } + + @Test + public void testBuilderError() { + try { + TestGrpcServiceOptions.builder().initialTimeout(0); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException ex) { + assertEquals("Initial timeout must be > 0", ex.getMessage()); + } + try { + TestGrpcServiceOptions.builder().initialTimeout(-1); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException ex) { + assertEquals("Initial timeout must be > 0", ex.getMessage()); + } + try { + TestGrpcServiceOptions.builder().timeoutMultiplier(0.9); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException ex) { + assertEquals("Timeout multiplier must be >= 1", ex.getMessage()); + } + } + + @Test + public void testBuilderInvalidMaxTimeout() { + TestGrpcServiceOptions options = TestGrpcServiceOptions.builder() + .projectId("project-id") + .initialTimeout(1234) + .timeoutMultiplier(1.6) + .maxTimeout(123) + .build(); + assertEquals(1234, options.initialTimeout()); + assertEquals(1.6, options.timeoutMultiplier(), 0.0); + assertEquals(1234, options.maxTimeout()); + } + + @Test + public void testBaseEquals() { + assertEquals(OPTIONS, OPTIONS_COPY); + assertNotEquals(DEFAULT_OPTIONS, OPTIONS); + TestGrpcServiceOptions options = OPTIONS.toBuilder() + .executorFactory(new DefaultExecutorFactory()) + .build(); + assertNotEquals(OPTIONS, options); + } + + @Test + public void testBaseHashCode() { + assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); + assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); + TestGrpcServiceOptions options = OPTIONS.toBuilder() + .executorFactory(new DefaultExecutorFactory()) + .build(); + assertNotEquals(OPTIONS.hashCode(), options.hashCode()); + } + + @Test + public void testDefaultExecutorFactory() { + ExecutorFactory executorFactory = new DefaultExecutorFactory(); + ScheduledExecutorService executorService = executorFactory.get(); + assertSame(executorService, executorFactory.get()); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java new file mode 100644 index 0000000000..de8dc8592e --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java @@ -0,0 +1,163 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import com.google.cloud.HttpServiceOptions.DefaultHttpTransportFactory; +import com.google.cloud.HttpServiceOptions.HttpTransportFactory; +import com.google.cloud.spi.ServiceRpcFactory; + +import org.easymock.EasyMock; +import org.junit.Test; + +import java.util.Set; + +public class HttpServiceOptionsTest { + + private static final HttpTransportFactory MOCK_HTTP_TRANSPORT_FACTORY = + EasyMock.createMock(HttpTransportFactory.class); + private static final TestHttpServiceOptions OPTIONS = TestHttpServiceOptions.builder() + .projectId("project-id") + .connectTimeout(1234) + .httpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) + .readTimeout(5678) + .build(); + private static final TestHttpServiceOptions DEFAULT_OPTIONS = + TestHttpServiceOptions.builder().projectId("project-id").build(); + private static final TestHttpServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); + + private interface TestService extends Service {} + + private static class TestServiceImpl + extends BaseService implements TestService { + private TestServiceImpl(TestHttpServiceOptions options) { + super(options); + } + } + + private interface TestServiceFactory extends ServiceFactory { + } + + private static class DefaultTestServiceFactory implements TestServiceFactory { + private static final TestServiceFactory INSTANCE = new DefaultTestServiceFactory(); + + @Override + public TestService create(TestHttpServiceOptions options) { + return new TestServiceImpl(options); + } + } + + private interface TestServiceRpcFactory + extends ServiceRpcFactory {} + + private static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory { + private static final TestServiceRpcFactory INSTANCE = new DefaultTestServiceRpcFactory(); + + @Override + public TestServiceRpc create(TestHttpServiceOptions options) { + return new DefaultTestServiceRpc(options); + } + } + + private interface TestServiceRpc {} + + private static class DefaultTestServiceRpc implements TestServiceRpc { + DefaultTestServiceRpc(TestHttpServiceOptions options) {} + } + + private static class TestHttpServiceOptions + extends HttpServiceOptions { + private static class Builder + extends HttpServiceOptions.Builder { + private Builder() {} + + private Builder(TestHttpServiceOptions options) { + super(options); + } + + @Override + protected TestHttpServiceOptions build() { + return new TestHttpServiceOptions(this); + } + } + + private TestHttpServiceOptions(Builder builder) { + super(TestServiceFactory.class, TestServiceRpcFactory.class, builder); + } + + @Override + protected TestServiceFactory defaultServiceFactory() { + return DefaultTestServiceFactory.INSTANCE; + } + + @Override + protected TestServiceRpcFactory defaultRpcFactory() { + return DefaultTestServiceRpcFactory.INSTANCE; + } + + @Override + protected Set scopes() { + return null; + } + + @Override + public Builder toBuilder() { + return new Builder(this); + } + + private static Builder builder() { + return new Builder(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof TestHttpServiceOptions && baseEquals((TestHttpServiceOptions) obj); + } + + @Override + public int hashCode() { + return baseHashCode(); + } + } + + @Test + public void testBuilder() { + assertEquals(1234, OPTIONS.connectTimeout()); + assertSame(MOCK_HTTP_TRANSPORT_FACTORY, OPTIONS.httpTransportFactory()); + assertEquals(5678, OPTIONS.readTimeout()); + assertEquals(-1, DEFAULT_OPTIONS.connectTimeout()); + assertTrue(DEFAULT_OPTIONS.httpTransportFactory() instanceof DefaultHttpTransportFactory); + assertEquals(-1, DEFAULT_OPTIONS.readTimeout()); + } + + @Test + public void testBaseEquals() { + assertEquals(OPTIONS, OPTIONS_COPY); + assertNotEquals(DEFAULT_OPTIONS, OPTIONS); + } + + @Test + public void testBaseHashCode() { + assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); + assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index bcbecbe3c6..7afc2b0b97 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -22,21 +22,15 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.cloud.ServiceOptions.DefaultHttpTransportFactory; -import com.google.cloud.ServiceOptions.HttpTransportFactory; import com.google.cloud.spi.ServiceRpcFactory; -import org.easymock.EasyMock; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Set; -@RunWith(JUnit4.class) public class ServiceOptionsTest { private static final String JSON_KEY = "{\n" @@ -74,18 +68,13 @@ public class ServiceOptionsTest { fail("Couldn't create fake JSON credentials."); } } - private static final HttpTransportFactory MOCK_HTTP_TRANSPORT_FACTORY = - EasyMock.createMock(HttpTransportFactory.class); private static final Clock TEST_CLOCK = new TestClock(); private static final TestServiceOptions OPTIONS = TestServiceOptions.builder() .authCredentials(authCredentials) .clock(TEST_CLOCK) - .connectTimeout(1234) .host("host") - .httpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) .projectId("project-id") - .readTimeout(5678) .retryParams(RetryParams.noRetries()) .build(); private static final TestServiceOptions DEFAULT_OPTIONS = @@ -196,18 +185,11 @@ public int hashCode() { public void testBuilder() { assertSame(authCredentials, OPTIONS.authCredentials()); assertSame(TEST_CLOCK, OPTIONS.clock()); - assertEquals(1234, OPTIONS.connectTimeout()); assertEquals("host", OPTIONS.host()); - assertSame(MOCK_HTTP_TRANSPORT_FACTORY, OPTIONS.httpTransportFactory()); assertEquals("project-id", OPTIONS.projectId()); - assertEquals(5678, OPTIONS.readTimeout()); assertSame(RetryParams.noRetries(), OPTIONS.retryParams()); - assertSame(Clock.defaultClock(), DEFAULT_OPTIONS.clock()); - assertEquals(-1, DEFAULT_OPTIONS.connectTimeout()); assertEquals("https://www.googleapis.com", DEFAULT_OPTIONS.host()); - assertTrue(DEFAULT_OPTIONS.httpTransportFactory() instanceof DefaultHttpTransportFactory); - assertEquals(-1, DEFAULT_OPTIONS.readTimeout()); assertSame(RetryParams.defaultInstance(), DEFAULT_OPTIONS.retryParams()); } From ad9bfd3f5e8deaef7a19033888f5697b7dd175ef Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 22 Jun 2016 23:19:27 +0200 Subject: [PATCH 191/663] Add MessageConsumerImpl class, implement pullAsync, add tests (#1043) --- .../com/google/cloud/GrpcServiceOptions.java | 30 +++++++++++-------- .../google/cloud/GrpcServiceOptionsTest.java | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java index 2a1110c936..67361dba6e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.util.Objects; +import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -50,7 +51,7 @@ public abstract class GrpcServiceOptions, Ser private final double timeoutMultiplier; private final int maxTimeout; - private transient ExecutorFactory executorFactory; + private transient ExecutorFactory executorFactory; /** * Shared thread pool executor. @@ -73,30 +74,32 @@ public void close(ScheduledExecutorService instance) { }; /** - * An interface for {@link ScheduledExecutorService} factories. Implementations of this interface - * can be used to provide an user-defined scheduled executor to execute requests. Any - * implementation of this interface must override the {@code get()} method to return the desired - * executor. The {@code release(executor)} method should be overriden to free resources used by - * the executor (if needed) according to application's logic. + * An interface for {@link ExecutorService} factories. Implementations of this interface can be + * used to provide an user-defined executor to execute requests. Any implementation of this + * interface must override the {@code get()} method to return the desired executor. The + * {@code release(executor)} method should be overriden to free resources used by the executor (if + * needed) according to application's logic. * *

    Implementation must provide a public no-arg constructor. Loading of a factory implementation * is done via {@link java.util.ServiceLoader}. + * + * @param the {@link ExecutorService} subclass created by this factory */ - public interface ExecutorFactory { + public interface ExecutorFactory { /** - * Gets a scheduled executor service instance. + * Gets an executor service instance. */ - ScheduledExecutorService get(); + T get(); /** * Releases resources used by the executor and possibly shuts it down. */ - void release(ScheduledExecutorService executor); + void release(T executor); } @VisibleForTesting - static class DefaultExecutorFactory implements ExecutorFactory { + static class DefaultExecutorFactory implements ExecutorFactory { private static final DefaultExecutorFactory INSTANCE = new DefaultExecutorFactory(); @@ -148,7 +151,7 @@ protected Builder(GrpcServiceOptions options) { * * @return the builder */ - public B executorFactory(ExecutorFactory executorFactory) { + public B executorFactory(ExecutorFactory executorFactory) { this.executorFactory = executorFactory; return self(); } @@ -192,6 +195,7 @@ public B maxTimeout(int maxTimeout) { } } + @SuppressWarnings("unchecked") protected GrpcServiceOptions( Class> serviceFactoryClass, Class> rpcFactoryClass, Builder executorFactory() { return executorFactory; } diff --git a/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java index 0a3c34f879..457f05cd0b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java @@ -211,7 +211,7 @@ public void testBaseHashCode() { @Test public void testDefaultExecutorFactory() { - ExecutorFactory executorFactory = new DefaultExecutorFactory(); + ExecutorFactory executorFactory = new DefaultExecutorFactory(); ScheduledExecutorService executorService = executorFactory.get(); assertSame(executorService, executorFactory.get()); } From e586c4e22d63f6f86afcc3f16d6869c5f9b90215 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 24 Jun 2016 20:40:29 +0200 Subject: [PATCH 192/663] Support setting library header in grpc services (#1078) - add libraryName() and libraryVersion() to ServiceOptions - use setClientLibHeader in DefaultPubSubRpc --- .../java/com/google/cloud/ServiceOptions.java | 26 +++++++++++++++---- .../com/google/cloud/ServiceOptionsTest.java | 14 ++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 8a1d95f32e..db24555a18 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -68,9 +68,11 @@ public abstract class ServiceOptions, Service private static final String MANIFEST_ARTIFACT_ID_KEY = "artifactId"; private static final String MANIFEST_VERSION_KEY = "Implementation-Version"; private static final String ARTIFACT_ID = "gcloud-java-core"; - private static final String APPLICATION_BASE_NAME = "gcloud-java"; - private static final String APPLICATION_NAME = getApplicationName(); - private static final long serialVersionUID = -6410263550484023006L; + private static final String LIBRARY_NAME = "gcloud-java"; + private static final String LIBRARY_VERSION = getLibraryVersion(); + private static final String APPLICATION_NAME = + LIBRARY_VERSION == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + LIBRARY_VERSION; + private static final long serialVersionUID = 3049375916337507361L; private final String projectId; private final String host; @@ -439,6 +441,20 @@ public String applicationName() { return APPLICATION_NAME; } + /** + * Returns the library's name, {@code gcloud-java}, as a string. + */ + public String libraryName() { + return LIBRARY_NAME; + } + + /** + * Returns the library's version as a string. + */ + public String libraryVersion() { + return LIBRARY_VERSION; + } + protected int baseHashCode() { return Objects.hash(projectId, host, authCredentialsState, retryParams, serviceFactoryClassName, serviceRpcFactoryClassName, clock); @@ -491,7 +507,7 @@ static T getFromServiceLoader(Class clazz, T defaultInstance) { return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance); } - private static String getApplicationName() { + private static String getLibraryVersion() { String version = null; try { Enumeration resources = @@ -507,6 +523,6 @@ private static String getApplicationName() { } catch (IOException e) { // ignore } - return version != null ? APPLICATION_BASE_NAME + "/" + version : APPLICATION_BASE_NAME; + return version; } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 7afc2b0b97..7792c63e82 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Set; +import java.util.regex.Pattern; public class ServiceOptionsTest { private static final String JSON_KEY = @@ -80,6 +81,9 @@ public class ServiceOptionsTest { private static final TestServiceOptions DEFAULT_OPTIONS = TestServiceOptions.builder().projectId("project-id").build(); private static final TestServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); + private static final String LIBRARY_NAME = "gcloud-java"; + private static final Pattern APPLICATION_NAME_PATTERN = + Pattern.compile(LIBRARY_NAME + "(/[0-9]+.[0-9]+.[0-9]+)?"); private static class TestClock extends Clock { @Override @@ -214,6 +218,16 @@ public void testBaseEquals() { assertNotEquals(DEFAULT_OPTIONS, OPTIONS); } + @Test + public void testLibraryName() { + assertEquals(LIBRARY_NAME, OPTIONS.libraryName()); + } + + @Test + public void testApplicationName() { + assertTrue(APPLICATION_NAME_PATTERN.matcher(OPTIONS.applicationName()).matches()); + } + @Test public void testBaseHashCode() { assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); From 462b9d2e6bfd1f4e8e1f2f46fed1b295290a1b8d Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 27 Jun 2016 13:07:33 +0200 Subject: [PATCH 193/663] Update grpc-related dependencies, remove gax dependency from pubsub --- google-cloud-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e892583d1e..c4d92f29ae 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -101,12 +101,12 @@ com.google.protobuf protobuf-java - 3.0.0-beta-1 + 3.0.0-beta-3 com.google.api gax - 0.0.11 + 0.0.13 From 144ff1ad8e28ac06fadc55c86313b50478b0b9b8 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 28 Jun 2016 20:04:29 +0200 Subject: [PATCH 194/663] Release 0.2.4 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c4d92f29ae..f9c97a8528 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.4-SNAPSHOT + 0.2.4 gcloud-java-core From bd92625b716a504583b3635d4820fd46731500c6 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Wed, 29 Jun 2016 09:09:30 +0200 Subject: [PATCH 195/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index abd95a563c..a3c05a2441 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud gcloud-java-core - 0.2.3 + 0.2.4 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:gcloud-java-core:0.2.3' +compile 'com.google.cloud:gcloud-java-core:0.2.4' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.3" +libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.4" ``` Troubleshooting From cada3ac7bdc9e02828fed0a77e4ce0a03522c4bb Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 29 Jun 2016 11:53:54 +0200 Subject: [PATCH 196/663] Update version to 0.2.5-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f9c97a8528..9ba7e75177 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.4 + 0.2.5-SNAPSHOT gcloud-java-core From 53281a8e7607284ef2188d551e604e42386eadc7 Mon Sep 17 00:00:00 2001 From: JP Martin Date: Tue, 21 Jun 2016 10:33:58 -0700 Subject: [PATCH 197/663] Handle files over 2GB (#1065) * Handle files over 2GB * Use Guava's checkArgument --- .../src/main/java/com/google/cloud/ReadChannel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java index 2afb8b2d5b..1ac45902b2 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java @@ -38,7 +38,7 @@ public interface ReadChannel extends ReadableByteChannel, Closeable, Restorable< @Override void close(); - void seek(int position) throws IOException; + void seek(long position) throws IOException; /** * Sets the minimum size that will be read by a single RPC. From 816f440fbe524b763a35e8acb8549c8ffcfa0331 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Sun, 3 Jul 2016 17:08:45 +0200 Subject: [PATCH 198/663] Release 0.2.5 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9ba7e75177..b24845ae17 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.5-SNAPSHOT + 0.2.5 gcloud-java-core From 20c2e9a2a5acf1d7a405fd24b1041a1e92539cc4 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Sun, 3 Jul 2016 16:39:33 +0000 Subject: [PATCH 199/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index a3c05a2441..cc1129848a 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud gcloud-java-core - 0.2.4 + 0.2.5 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:gcloud-java-core:0.2.4' +compile 'com.google.cloud:gcloud-java-core:0.2.5' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.4" +libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.5" ``` Troubleshooting From d74513517269218a84a532c55cd9eb6e78c28bc2 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Sun, 3 Jul 2016 20:41:40 +0200 Subject: [PATCH 200/663] Update version to 0.2.6-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b24845ae17..53bcd3c226 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.5 + 0.2.6-SNAPSHOT gcloud-java-core From 303b0220186684b9e4734dbde265d14998646efb Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 4 Jul 2016 15:44:11 +0200 Subject: [PATCH 201/663] Add MonitoredResourceDescriptor class and tests (#1062) * Add MonitoredResourceDescriptor class and tests * Move MonitoredResourceDescriptor to core module --- google-cloud-core/pom.xml | 5 + .../cloud/MonitoredResourceDescriptor.java | 345 ++++++++++++++++++ .../MonitoredResourceDescriptorTest.java | 126 +++++++ 3 files changed, 476 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 53bcd3c226..9f3ecdac9c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -108,5 +108,10 @@ gax 0.0.13 + + com.google.api.grpc + grpc-core-proto + 0.0.4 + diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java new file mode 100644 index 0000000000..d743e1d396 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java @@ -0,0 +1,345 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Function; +import com.google.common.base.MoreObjects; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * This class describes the schema of Cloud monitored resources. Monitored resource descriptors + * contain a type name and a set of labels. For example, the monitored resource descriptor for + * Google Compute Engine VM instances has a type of {@code gce_instance} and specifies the use of + * the labels {@code instance_id} and {@code zone} to identify particular VM instances. + */ +public class MonitoredResourceDescriptor implements Serializable { + + private static final long serialVersionUID = -3702077512777687441L; + public static final Function FROM_PB_FUNCTION = + new Function() { + @Override + public MonitoredResourceDescriptor apply( + com.google.api.MonitoredResourceDescriptor pb) { + return fromPb(pb); + } + }; + + private final String type; + private final String name; + private final String displayName; + private final String description; + private final List labels; + + /** + * This class describes a label for a monitored resource. Label descriptors contain the key for + * the label, the type of data that the label can hold and an optional description. + */ + public static class LabelDescriptor implements Serializable { + + private static final long serialVersionUID = -2811608103754481777L; + private static final Function + FROM_PB_FUNCTION = new Function() { + @Override + public LabelDescriptor apply(com.google.api.LabelDescriptor descriptorPb) { + return fromPb(descriptorPb); + } + }; + private static final Function + TO_PB_FUNCTION = new Function() { + @Override + public com.google.api.LabelDescriptor apply(LabelDescriptor descriptor) { + return descriptor.toPb(); + } + }; + + private final String key; + private final ValueType valueType; + private final String description; + + /** + * Value types that can be used as label values. + */ + public enum ValueType { + STRING(com.google.api.LabelDescriptor.ValueType.STRING), + BOOL(com.google.api.LabelDescriptor.ValueType.BOOL), + INT64(com.google.api.LabelDescriptor.ValueType.INT64); + + private com.google.api.LabelDescriptor.ValueType typePb; + + ValueType(com.google.api.LabelDescriptor.ValueType typePb) { + this.typePb = typePb; + } + + com.google.api.LabelDescriptor.ValueType toPb() { + return typePb; + } + + static ValueType fromPb(com.google.api.LabelDescriptor.ValueType typePb) { + switch (typePb) { + case STRING: + return ValueType.STRING; + case BOOL: + return ValueType.BOOL; + case INT64: + return ValueType.INT64; + default: + throw new IllegalArgumentException("Unrecognized label type"); + } + } + } + + LabelDescriptor(String key, ValueType valueType, String description) { + this.key = checkNotNull(key); + this.valueType = checkNotNull(valueType); + this.description = description; + } + + /** + * Returns the key associated to this label. + */ + public String key() { + return key; + } + + /** + * Returns the type of data that can be assigned to this label. + */ + public ValueType valueType() { + return valueType; + } + + /** + * Returns the optional human-readable description for this label. If not set, this method + * returns {@code null}. + */ + public String description() { + return description; + } + + @Override + public final int hashCode() { + return Objects.hash(key, valueType, description); + } + + @Override + public final boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj == null || !obj.getClass().equals(LabelDescriptor.class)) { + return false; + } + LabelDescriptor other = (LabelDescriptor) obj; + return Objects.equals(key, other.key) + && Objects.equals(valueType, other.valueType) + && Objects.equals(description, other.description); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("key", key) + .add("valueType", valueType) + .add("description", description) + .toString(); + } + + com.google.api.LabelDescriptor toPb() { + com.google.api.LabelDescriptor.Builder builder = com.google.api.LabelDescriptor.newBuilder() + .setKey(key) + .setValueType(valueType.toPb()); + if (description != null) { + builder.setDescription(description); + } + return builder.build(); + } + + static LabelDescriptor fromPb(com.google.api.LabelDescriptor descriptorPb) { + String description = null; + if (descriptorPb.getDescription() != null && !descriptorPb.getDescription().equals("")) { + description = descriptorPb.getDescription(); + } + return new LabelDescriptor(descriptorPb.getKey(), + ValueType.fromPb(descriptorPb.getValueType()), description); + } + } + + static class Builder { + + private final String type; + private String name; + private String displayName; + private String description; + private List labels = new ArrayList<>(); + + Builder(String type) { + this.type = type; + } + + Builder name(String name) { + this.name = name; + return this; + } + + Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + + Builder description(String description) { + this.description = description; + return this; + } + + Builder labels(List labels) { + this.labels = labels; + return this; + } + + MonitoredResourceDescriptor build() { + return new MonitoredResourceDescriptor(this); + } + } + + MonitoredResourceDescriptor(Builder builder) { + this.type = checkNotNull(builder.type); + this.name = builder.name; + this.displayName = builder.displayName; + this.description = builder.description; + this.labels = checkNotNull(builder.labels); + } + + /** + * Returns the monitored resource type. For example, the type {@code cloudsql_database} represents + * databases in Google Cloud SQL. + */ + public String type() { + return type; + } + + /** + * Returns an optional name for the monitored resource descriptor. If not set, this method returns + * {@code null}. + */ + public String name() { + return name; + } + + /** + * Returns an optional concise name for the monitored resource type. This value might be displayed + * in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method + * returns {@code null}. + */ + public String displayName() { + return displayName; + } + + /** + * Returns an optional detailed description of the monitored resource type. This value might be + * used in documentation. If not set, this method returns {@code null}. + */ + public String description() { + return description; + } + + /** + * Returns a list of labels used to describe instances of this monitored resource type. For + * example, an individual Google Cloud SQL database is identified by values for the labels + * {@code database_id} and {@code region}. + */ + public List labels() { + return labels; + } + + @Override + public final int hashCode() { + return Objects.hash(type, name, displayName, description, labels); + } + + @Override + public final boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj == null || !obj.getClass().equals(MonitoredResourceDescriptor.class)) { + return false; + } + MonitoredResourceDescriptor other = (MonitoredResourceDescriptor) obj; + return Objects.equals(type, other.type) + && Objects.equals(name, other.name) + && Objects.equals(displayName, other.displayName) + && Objects.equals(description, other.description) + && Objects.equals(labels, other.labels); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("type", type) + .add("name", name) + .add("displayName", displayName) + .add("description", description) + .add("labels", labels) + .toString(); + } + + public com.google.api.MonitoredResourceDescriptor toPb() { + com.google.api.MonitoredResourceDescriptor.Builder builder = + com.google.api.MonitoredResourceDescriptor.newBuilder() + .setType(type) + .addAllLabels(Iterables.transform(labels, LabelDescriptor.TO_PB_FUNCTION)); + if (name != null) { + builder.setName(name); + } + if (displayName != null) { + builder.setDisplayName(displayName); + } + if (description != null) { + builder.setDescription(description); + } + return builder.build(); + } + + static Builder builder(String type) { + return new Builder(type); + } + + public static MonitoredResourceDescriptor fromPb( + com.google.api.MonitoredResourceDescriptor descriptorPb) { + Builder builder = builder(descriptorPb.getType()); + if (descriptorPb.getName() != null && !descriptorPb.getName().equals("")) { + builder.name(descriptorPb.getName()); + } + if (descriptorPb.getDisplayName() != null && !descriptorPb.getDisplayName().equals("")) { + builder.displayName(descriptorPb.getDisplayName()); + } + if (descriptorPb.getDescription() != null && !descriptorPb.getDescription().equals("")) { + builder.description(descriptorPb.getDescription()); + } + builder.labels(Lists.transform(descriptorPb.getLabelsList(), LabelDescriptor.FROM_PB_FUNCTION)); + return builder.build(); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java new file mode 100644 index 0000000000..cab0438e05 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java @@ -0,0 +1,126 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor; +import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor.ValueType; +import com.google.common.collect.ImmutableList; + +import org.junit.Test; + +import java.util.List; + +public class MonitoredResourceDescriptorTest { + + private static final LabelDescriptor BOOLEAN_LABEL = + new LabelDescriptor("booleanKey", ValueType.BOOL, "Boolean label"); + private static final LabelDescriptor STRING_LABEL = + new LabelDescriptor("stringKey", ValueType.STRING, "String label"); + private static final LabelDescriptor INT_LABEL = + new LabelDescriptor("intKey", ValueType.INT64, "Int label"); + private static final LabelDescriptor INT_LABEL_NO_DESCRIPTION = + new LabelDescriptor("intKey", ValueType.INT64, null); + private static final String TYPE = "resource_type"; + private static final String NAME = "resourceName"; + private static final String DISPLAY_NAME = "Display Name"; + private static final String DESCRIPTION = "Resource Descriptor"; + private static final List LABELS = + ImmutableList.of(BOOLEAN_LABEL, STRING_LABEL, INT_LABEL); + private static final MonitoredResourceDescriptor RESOURCE_DESCRIPTOR = + MonitoredResourceDescriptor.builder(TYPE) + .name(NAME) + .displayName(DISPLAY_NAME) + .description(DESCRIPTION) + .labels(LABELS) + .build(); + + @Test + public void testLabelDescriptor() { + assertEquals("booleanKey", BOOLEAN_LABEL.key()); + assertEquals(ValueType.BOOL, BOOLEAN_LABEL.valueType()); + assertEquals("Boolean label", BOOLEAN_LABEL.description()); + assertEquals("stringKey", STRING_LABEL.key()); + assertEquals(ValueType.STRING, STRING_LABEL.valueType()); + assertEquals("String label", STRING_LABEL.description()); + assertEquals("intKey", INT_LABEL.key()); + assertEquals(ValueType.INT64, INT_LABEL.valueType()); + assertEquals("Int label", INT_LABEL.description()); + assertEquals("intKey", INT_LABEL_NO_DESCRIPTION.key()); + assertEquals(ValueType.INT64, INT_LABEL_NO_DESCRIPTION.valueType()); + assertNull(INT_LABEL_NO_DESCRIPTION.description()); + } + + @Test + public void testBuilder() { + assertEquals(TYPE, RESOURCE_DESCRIPTOR.type()); + assertEquals(NAME, RESOURCE_DESCRIPTOR.name()); + assertEquals(DISPLAY_NAME, RESOURCE_DESCRIPTOR.displayName()); + assertEquals(DESCRIPTION, RESOURCE_DESCRIPTOR.description()); + assertEquals(LABELS, RESOURCE_DESCRIPTOR.labels()); + MonitoredResourceDescriptor resourceDescriptor = + MonitoredResourceDescriptor.builder(TYPE).build(); + assertEquals(TYPE, resourceDescriptor.type()); + assertNull(resourceDescriptor.name()); + assertNull(resourceDescriptor.displayName()); + assertNull(resourceDescriptor.description()); + assertEquals(ImmutableList.of(), resourceDescriptor.labels()); + } + + + @Test + public void testToAndFromPbLabelDescriptor() { + compareLabelDescriptor(BOOLEAN_LABEL, LabelDescriptor.fromPb(BOOLEAN_LABEL.toPb())); + compareLabelDescriptor(STRING_LABEL, LabelDescriptor.fromPb(STRING_LABEL.toPb())); + compareLabelDescriptor(INT_LABEL, LabelDescriptor.fromPb(INT_LABEL.toPb())); + compareLabelDescriptor(INT_LABEL_NO_DESCRIPTION, + LabelDescriptor.fromPb(INT_LABEL_NO_DESCRIPTION.toPb())); + } + + @Test + public void testToAndFromPb() { + compareResourceDescriptor(RESOURCE_DESCRIPTOR, + MonitoredResourceDescriptor.fromPb(RESOURCE_DESCRIPTOR.toPb())); + MonitoredResourceDescriptor resourceDescriptor = + MonitoredResourceDescriptor.builder(TYPE).build(); + compareResourceDescriptor(resourceDescriptor, + MonitoredResourceDescriptor.fromPb(resourceDescriptor.toPb())); + } + + private void compareLabelDescriptor(LabelDescriptor expected, LabelDescriptor value) { + assertEquals(expected, value); + assertEquals(expected.key(), value.key()); + assertEquals(expected.valueType(), value.valueType()); + assertEquals(expected.description(), value.description()); + assertEquals(expected.hashCode(), value.hashCode()); + assertEquals(expected.toString(), value.toString()); + } + + private void compareResourceDescriptor(MonitoredResourceDescriptor expected, + MonitoredResourceDescriptor value) { + assertEquals(expected, value); + assertEquals(expected.type(), value.type()); + assertEquals(expected.name(), value.name()); + assertEquals(expected.displayName(), value.displayName()); + assertEquals(expected.description(), value.description()); + assertEquals(expected.labels(), value.labels()); + assertEquals(expected.hashCode(), value.hashCode()); + assertEquals(expected.toString(), value.toString()); + } +} From 2a9ea3519bad294a989522a1943027868c2059ee Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 6 Jul 2016 12:52:02 +0200 Subject: [PATCH 202/663] Add MonitoredResource class and tests (#1097) --- .../com/google/cloud/MonitoredResource.java | 184 ++++++++++++++++++ .../google/cloud/MonitoredResourceTest.java | 97 +++++++++ 2 files changed, 281 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java new file mode 100644 index 0000000000..584bc80ced --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java @@ -0,0 +1,184 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableMap; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Objects of this class represent a resource that can be used for monitoring, logging, billing, or + * other purposes. Examples include virtual machine instances, databases, and storage devices such + * as disks. The type field identifies a {@link MonitoredResourceDescriptor} object that describes + * the resource's schema. Information in the labels field identifies the actual resource and its + * attributes according to the schema. + * + *

    For example, the monitored resource for Google Compute Engine VM instances has + * {@code gce_instance} type and specifies values for the labels {@code instance_id} and + * {@code zone} to identify particular VM instances. + */ +public final class MonitoredResource implements Serializable { + + private static final long serialVersionUID = -4393604148752640581L; + + private final String type; + private final Map labels; + + /** + * A builder for {@code MonitoredResource} objects. + */ + public static class Builder { + + private String type; + private Map labels = new HashMap<>(); + + Builder(String type) { + this.type = type; + } + + Builder(MonitoredResource monitoredResource) { + this.type = monitoredResource.type; + this.labels = new HashMap<>(monitoredResource.labels); + } + + /** + * Sets the monitored resource type. This value must match the one of + * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. + * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. + */ + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * Sets the values for all the labels required by the corresponding monitored resource + * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute + * Engine VM instances use the labels {@code instance_id} and {@code zone}. + */ + public Builder labels(Map labels) { + this.labels = new HashMap<>(checkNotNull(labels)); + return this; + } + + /** + * Adds a label to the labels of the monitored resource. + */ + public Builder addLabel(String key, String value) { + this.labels.put(key, value); + return this; + } + + /** + * Clears all the labels of the monitored resource. + */ + public Builder clearLabels() { + this.labels.clear(); + return this; + } + + public MonitoredResource build() { + return new MonitoredResource(this); + } + } + + MonitoredResource(Builder builder) { + this.type = checkNotNull(builder.type); + this.labels = ImmutableMap.copyOf(builder.labels); + } + + /** + * Returns the monitored resource type. This value must match the one of + * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. + * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. + */ + public String type() { + return type; + } + + /** + * Returns the values for all the labels required by the corresponding monitored resource + * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute + * Engine VM instances use the labels {@code instance_id} and {@code zone}. + */ + public Map labels() { + return labels; + } + + @Override + public int hashCode() { + return Objects.hash(type, labels); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof MonitoredResource)) { + return false; + } + MonitoredResource other = (MonitoredResource) obj; + return Objects.equals(type, other.type) && Objects.equals(labels, other.labels); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("type", type) + .add("labels", labels) + .toString(); + } + + public com.google.api.MonitoredResource toPb() { + return com.google.api.MonitoredResource.newBuilder() + .setType(type) + .putAllLabels(labels) + .build(); + } + + /** + * Returns a builder for this {@code MonitoredResource} object. + */ + public Builder toBuilder() { + return new Builder(this); + } + + /** + * Returns a builder for {@code MonitoredResource} objects given the resource's type. + */ + public static Builder builder(String type) { + return new Builder(type); + } + + /** + * Creates a {@code MonitoredResource} object given the resource's type and labels. + */ + public static MonitoredResource of(String type, Map labels) { + return builder(type).labels(labels).build(); + } + + public static MonitoredResource fromPb(com.google.api.MonitoredResource descriptorPb) { + return new Builder(descriptorPb.getType()).labels(descriptorPb.getLabels()).build(); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java new file mode 100644 index 0000000000..b42dc0c0f6 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java @@ -0,0 +1,97 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableMap; + +import org.junit.Test; + +import java.util.Map; + +public class MonitoredResourceTest { + + private static final String TYPE = "cloudsql_database"; + private static final Map LABELS = + ImmutableMap.of("dataset-id", "myDataset", "zone", "myZone"); + private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.builder(TYPE) + .labels(LABELS) + .build(); + + @Test + public void testBuilder() { + assertEquals(TYPE, MONITORED_RESOURCE.type()); + assertEquals(LABELS, MONITORED_RESOURCE.labels()); + MonitoredResource monitoredResource = MonitoredResource.builder(TYPE) + .addLabel("dataset-id", "myDataset") + .addLabel("zone", "myZone") + .build(); + assertEquals(TYPE, monitoredResource.type()); + assertEquals(LABELS, monitoredResource.labels()); + compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); + monitoredResource = MonitoredResource.builder(TYPE) + .type("global") + .addLabel("dataset-id", "myDataset") + .addLabel("zone", "myZone") + .clearLabels() + .build(); + assertEquals("global", monitoredResource.type()); + assertEquals(ImmutableMap.of(), monitoredResource.labels()); + } + + @Test + public void testToBuilder() { + compareMonitoredResource(MONITORED_RESOURCE, MONITORED_RESOURCE.toBuilder().build()); + MonitoredResource monitoredResource = MONITORED_RESOURCE.toBuilder() + .type("global") + .clearLabels() + .build(); + assertEquals("global", monitoredResource.type()); + assertEquals(ImmutableMap.of(), monitoredResource.labels()); + monitoredResource = monitoredResource.toBuilder() + .type(TYPE) + .labels(ImmutableMap.of("dataset-id", "myDataset")) + .addLabel("zone", "myZone") + .build(); + compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); + } + + @Test + public void testOf() { + MonitoredResource monitoredResource = MonitoredResource.of(TYPE, LABELS); + assertEquals(TYPE, monitoredResource.type()); + assertEquals(LABELS, monitoredResource.labels()); + compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); + } + + @Test + public void testToAndFromPb() { + compareMonitoredResource(MONITORED_RESOURCE, + MonitoredResource.fromPb(MONITORED_RESOURCE.toPb())); + MonitoredResource monitoredResource = + MonitoredResource.of(TYPE, ImmutableMap.of()); + compareMonitoredResource(monitoredResource, MonitoredResource.fromPb(monitoredResource.toPb())); + } + + private void compareMonitoredResource(MonitoredResource expected, MonitoredResource value) { + assertEquals(expected, value); + assertEquals(expected.type(), value.type()); + assertEquals(expected.labels(), value.labels()); + assertEquals(expected.hashCode(), value.hashCode()); + } +} From d84b426655cdc489ec2d4f75b580fccecab826a4 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 19 Jul 2016 14:41:50 +0200 Subject: [PATCH 203/663] Add SerializationTest for logging and minor fixes (#1116) --- .../java/com/google/cloud/SerializationTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 53baa57b96..77f56ed3dd 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -16,8 +16,11 @@ package com.google.cloud; +import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor; +import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor.ValueType; import com.google.cloud.ServiceAccountSigner.SigningException; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -39,6 +42,15 @@ public class SerializationTest extends BaseSerializationTest { private static final SomeIamPolicy SOME_IAM_POLICY = new SomeIamPolicy.Builder().build(); private static final WaitForOption CHECKING_PERIOD = WaitForOption.checkEvery(42, TimeUnit.SECONDS); + private static final LabelDescriptor LABEL_DESCRIPTOR = + new LabelDescriptor("project_id", ValueType.STRING, "The project id"); + private static final MonitoredResourceDescriptor MONITORED_RESOURCE_DESCRIPTOR = + MonitoredResourceDescriptor.builder("global") + .labels(ImmutableList.of(LABEL_DESCRIPTOR)) + .build(); + private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.builder("global") + .labels(ImmutableMap.of("project_id", "project")) + .build(); private static final String JSON_KEY = "{\n" + " \"private_key_id\": \"somekeyid\",\n" + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" @@ -91,7 +103,8 @@ public Builder toBuilder() { @Override protected Serializable[] serializableObjects() { return new Serializable[]{BASE_SERVICE_EXCEPTION, EXCEPTION_HANDLER, IDENTITY, PAGE, - RETRY_PARAMS, SOME_IAM_POLICY, SIGNING_EXCEPTION, CHECKING_PERIOD}; + RETRY_PARAMS, SOME_IAM_POLICY, SIGNING_EXCEPTION, CHECKING_PERIOD, LABEL_DESCRIPTOR, + MONITORED_RESOURCE_DESCRIPTOR, MONITORED_RESOURCE}; } @Override From 828f45585d9370dd06f0e9e7b6e18640db3fc433 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 21 Jul 2016 11:57:21 +0200 Subject: [PATCH 204/663] Release 0.2.6 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9f3ecdac9c..2da8a24a1b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.6-SNAPSHOT + 0.2.6 gcloud-java-core From 16201d4b4af37a9182343092e0a060b0692c04d4 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Thu, 21 Jul 2016 11:02:12 +0000 Subject: [PATCH 205/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index cc1129848a..1ce1f94ec5 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud gcloud-java-core - 0.2.5 + 0.2.6 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:gcloud-java-core:0.2.5' +compile 'com.google.cloud:gcloud-java-core:0.2.6' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.5" +libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.6" ``` Troubleshooting From 28d55bf10e5a33c859222168d4c8bcbb5fabb723 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 21 Jul 2016 20:17:34 +0200 Subject: [PATCH 206/663] Update version to 0.2.7-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2da8a24a1b..98af8188e3 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.6 + 0.2.7-SNAPSHOT gcloud-java-core From e6b3139ca243fe21b16a3faeffa6b61e952a7b2f Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 11 Aug 2016 12:11:54 +0200 Subject: [PATCH 207/663] Release 0.2.7 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 98af8188e3..252a894bfe 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.7-SNAPSHOT + 0.2.7 gcloud-java-core From 0884a135015d2a5222311bb5f3c41abed767f4b4 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Thu, 11 Aug 2016 12:41:47 +0000 Subject: [PATCH 208/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 1ce1f94ec5..6f34f81917 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud gcloud-java-core - 0.2.6 + 0.2.7 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:gcloud-java-core:0.2.6' +compile 'com.google.cloud:gcloud-java-core:0.2.7' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.6" +libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.7" ``` Troubleshooting From 51b4433b93dc23dea88ac6552c9b242f2f61ec67 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 11 Aug 2016 16:01:29 +0200 Subject: [PATCH 209/663] Update version to 0.2.8-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 252a894bfe..c09367fccd 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.7 + 0.2.8-SNAPSHOT gcloud-java-core From 2fcf82bd221a7520325d709ecc09ab1b3a034867 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Fri, 12 Aug 2016 10:20:27 -0700 Subject: [PATCH 210/663] Regenerating Pub/Sub and Logging (#1156) --- google-cloud-core/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c09367fccd..4cfb7b84b0 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -106,12 +106,12 @@ com.google.api gax - 0.0.13 + 0.0.14 com.google.api.grpc - grpc-core-proto - 0.0.4 + grpc-google-common-protos + 0.0.7 From 11e6d81fb3fa6c7e66acc7288f173fb3e39b495f Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 18 Aug 2016 10:05:30 +0200 Subject: [PATCH 211/663] Refactor API call and connection settings for gRPC services (#1163) --- .../main/java/com/google/cloud/ByteArray.java | 8 ++-- .../com/google/cloud/GrpcServiceOptions.java | 43 ++++++++++++++++++- .../cloud/MonitoredResourceDescriptor.java | 14 +++--- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java index 6a8e3dddd0..3a23a17ba4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -135,7 +135,7 @@ public final void copyTo(byte[] target) { /** * Creates a {@code ByteArray} object given an array of bytes. The bytes are copied. */ - public final static ByteArray copyFrom(byte[] bytes) { + public static final ByteArray copyFrom(byte[] bytes) { return new ByteArray(ByteString.copyFrom(bytes)); } @@ -143,14 +143,14 @@ public final static ByteArray copyFrom(byte[] bytes) { * Creates a {@code ByteArray} object given a string. The string is encoded in {@code UTF-8}. The * bytes are copied. */ - public final static ByteArray copyFrom(String string) { + public static final ByteArray copyFrom(String string) { return new ByteArray(ByteString.copyFrom(string, StandardCharsets.UTF_8)); } /** * Creates a {@code ByteArray} object given a {@link ByteBuffer}. The bytes are copied. */ - public final static ByteArray copyFrom(ByteBuffer bytes) { + public static final ByteArray copyFrom(ByteBuffer bytes) { return new ByteArray(ByteString.copyFrom(bytes)); } @@ -158,7 +158,7 @@ public final static ByteArray copyFrom(ByteBuffer bytes) { * Creates a {@code ByteArray} object given an {@link InputStream}. The stream is read into the * created object. */ - public final static ByteArray copyFrom(InputStream input) throws IOException { + public static final ByteArray copyFrom(InputStream input) throws IOException { return new ByteArray(ByteString.readFrom(input)); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java index 67361dba6e..330a3dff2b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java @@ -18,13 +18,20 @@ import static com.google.common.base.MoreObjects.firstNonNull; +import com.google.api.gax.core.ConnectionSettings; +import com.google.api.gax.core.RetrySettings; +import com.google.api.gax.grpc.ApiCallSettings; +import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import com.google.common.net.HostAndPort; import io.grpc.internal.SharedResourceHolder; import io.grpc.internal.SharedResourceHolder.Resource; +import org.joda.time.Duration; + import java.io.IOException; import java.io.ObjectInputStream; import java.util.Objects; @@ -160,8 +167,8 @@ public B executorFactory(ExecutorFactory executorFacto * Sets the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value * adjusted according to {@link #timeoutMultiplier(double)}. Default value is 20000. * - * @throws IllegalArgumentException if the provided timeout is < 0 * @return the builder + * @throws IllegalArgumentException if the provided timeout is < 0 */ public B initialTimeout(int initialTimeout) { Preconditions.checkArgument(initialTimeout > 0, "Initial timeout must be > 0"); @@ -173,8 +180,8 @@ public B initialTimeout(int initialTimeout) { * Sets the timeout multiplier. This value is used to compute the timeout for a retried RPC. * Timeout is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. * - * @throws IllegalArgumentException if the provided timeout multiplier is < 0 * @return the builder + * @throws IllegalArgumentException if the provided timeout multiplier is < 0 */ public B timeoutMultiplier(double timeoutMultiplier) { Preconditions.checkArgument(timeoutMultiplier >= 1.0, "Timeout multiplier must be >= 1"); @@ -216,6 +223,38 @@ protected ExecutorFactory executorFactory() { return executorFactory; } + /** + * Returns a builder for API call settings. + */ + protected ApiCallSettings.Builder apiCallSettings() { + // todo(mziccard): specify timeout these settings: + // retryParams().retryMaxAttempts(), retryParams().retryMinAttempts() + final RetrySettings.Builder builder = RetrySettings.newBuilder() + .setTotalTimeout(Duration.millis(retryParams().totalRetryPeriodMillis())) + .setInitialRpcTimeout(Duration.millis(initialTimeout())) + .setRpcTimeoutMultiplier(timeoutMultiplier()) + .setMaxRpcTimeout(Duration.millis(maxTimeout())) + .setInitialRetryDelay(Duration.millis(retryParams().initialRetryDelayMillis())) + .setRetryDelayMultiplier(retryParams().retryDelayBackoffFactor()) + .setMaxRetryDelay(Duration.millis(retryParams().maxRetryDelayMillis())); + return ApiCallSettings.newBuilder().setRetrySettingsBuilder(builder); + } + + /** + * Returns a builder for connection-related settings. + */ + protected ConnectionSettings.Builder connectionSettings() { + HostAndPort hostAndPort = HostAndPort.fromString(host()); + ConnectionSettings.Builder builder = ConnectionSettings.newBuilder() + .setServiceAddress(hostAndPort.getHostText()) + .setPort(hostAndPort.getPort()); + GoogleCredentials credentials = authCredentials().credentials(); + if (credentials != null) { + builder.provideCredentialsWith(credentials.createScoped(scopes())); + } + return builder; + } + /** * Returns the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value * adjusted according to {@link #timeoutMultiplier()}. Default value is 20000. diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java index d743e1d396..cb121094ef 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java @@ -39,13 +39,13 @@ public class MonitoredResourceDescriptor implements Serializable { private static final long serialVersionUID = -3702077512777687441L; public static final Function FROM_PB_FUNCTION = - new Function() { - @Override - public MonitoredResourceDescriptor apply( - com.google.api.MonitoredResourceDescriptor pb) { - return fromPb(pb); - } - }; + new Function() { + @Override + public MonitoredResourceDescriptor apply( + com.google.api.MonitoredResourceDescriptor pb) { + return fromPb(pb); + } + }; private final String type; private final String name; From aabfa8e90c7566b6abf24b8343da17e65137c5da Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 23 Aug 2016 18:45:41 +0200 Subject: [PATCH 212/663] Add SocketException and 'insufficient data written' to retryable exceptions (#1187) --- .../com/google/cloud/BaseServiceException.java | 6 +++++- .../google/cloud/BaseServiceExceptionTest.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index 79afed2a3a..c22fcfd44a 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.Serializable; +import java.net.SocketException; import java.net.SocketTimeoutException; import java.util.Collections; import java.util.Objects; @@ -187,7 +188,10 @@ protected boolean isRetryable(boolean idempotent, Error error) { } protected boolean isRetryable(boolean idempotent, IOException exception) { - return idempotent && exception instanceof SocketTimeoutException; + boolean exceptionIsRetryable = exception instanceof SocketTimeoutException + || exception instanceof SocketException + || "insufficient data written".equals(exception.getMessage()); + return idempotent && exceptionIsRetryable; } /** diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index 52bc3b2b51..4517afff44 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -32,6 +32,7 @@ import org.junit.Test; import java.io.IOException; +import java.net.SocketException; import java.net.SocketTimeoutException; import java.util.Set; @@ -101,6 +102,21 @@ public void testBaseServiceException() { serviceException = new BaseServiceException(exception, true); assertTrue(serviceException.retryable()); assertTrue(serviceException.idempotent()); + assertNull(serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + + exception = new SocketException(); + serviceException = new BaseServiceException(exception, true); + assertTrue(serviceException.retryable()); + assertTrue(serviceException.idempotent()); + assertNull(serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + + exception = new IOException("insufficient data written"); + serviceException = new BaseServiceException(exception, true); + assertTrue(serviceException.retryable()); + assertTrue(serviceException.idempotent()); + assertEquals("insufficient data written", serviceException.getMessage()); assertEquals(exception, serviceException.getCause()); GoogleJsonError error = new GoogleJsonError(); From 7acf1815678931995f2a3f59d07b91e876810e9c Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 25 Aug 2016 16:41:54 +0200 Subject: [PATCH 213/663] Release 2.8.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4cfb7b84b0..e8ed3bd718 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.8-SNAPSHOT + 0.2.8 gcloud-java-core From 7bf2f2bbf57358772e80d935cd61f2e81cf0ed5d Mon Sep 17 00:00:00 2001 From: travis-ci Date: Thu, 25 Aug 2016 17:25:30 +0000 Subject: [PATCH 214/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 6f34f81917..4c06b0d2c4 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud gcloud-java-core - 0.2.7 + 0.2.8 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:gcloud-java-core:0.2.7' +compile 'com.google.cloud:gcloud-java-core:0.2.8' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.7" +libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.8" ``` Troubleshooting From 069d37deafd60357c179b9256a7c4c20866bfdd0 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 25 Aug 2016 20:34:08 +0200 Subject: [PATCH 215/663] Update version to 0.2.9-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e8ed3bd718..0a426d50a2 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.8 + 0.2.9-SNAPSHOT gcloud-java-core From 235eddab7c586f465de2e90dc7ee22110c495f12 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Mon, 29 Aug 2016 07:07:21 -0700 Subject: [PATCH 216/663] Initial auto-generated gcloud-java-vision (#1174) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 0a426d50a2..50155634bd 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -106,7 +106,7 @@ com.google.api gax - 0.0.14 + 0.0.16 com.google.api.grpc From 3374bd927ccf85805591115d72d6eed361fdb9d6 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 30 Aug 2016 13:06:40 +0200 Subject: [PATCH 217/663] Update pom.xml files and rename directories --- google-cloud-core/pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 50155634bd..6d1b948f8f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -1,20 +1,20 @@ 4.0.0 - gcloud-java-core + google-cloud-core jar - GCloud Java core - https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-core + Google Cloud Core + https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core - Core module for the gcloud-java. + Core module for the google-cloud. com.google.cloud - gcloud-java-pom + google-cloud-pom 0.2.9-SNAPSHOT - gcloud-java-core + google-cloud-core From a33e5cf85bbdb5568852f5ea538898c2596cc53d Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 30 Aug 2016 13:19:21 +0200 Subject: [PATCH 218/663] Rename gcloud-java to google-cloud in READMEs --- google-cloud-core/README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 4c06b0d2c4..6a6fcbc2b6 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -3,14 +3,14 @@ Google Cloud Java Client -- Core This module provides common functionality required by service-specific modules of this library. -[![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java) -[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master) -[![Maven](https://img.shields.io/maven-central/v/com.google.cloud/gcloud-java-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/gcloud-java-core.svg) -[![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/gcloud-java) +[![Build Status](https://travis-ci.org/GoogleCloudPlatform/google-cloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/google-cloud-java) +[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/google-cloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/google-cloud-java?branch=master) +[![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg) +[![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) [![Dependency Status](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969) -- [Homepage] (https://googlecloudplatform.github.io/gcloud-java/) -- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/cloud/package-summary.html) +- [Homepage] (https://googlecloudplatform.github.io/google-cloud-java/) +- [API Documentation] (https://googlecloudplatform.github.io/google-cloud-java/apidocs/index.html?com/google/cloud/package-summary.html) Quickstart ---------- @@ -18,23 +18,23 @@ If you are using Maven, add this to your pom.xml file ```xml com.google.cloud - gcloud-java-core + google-cloud-core 0.2.8 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:gcloud-java-core:0.2.8' +compile 'com.google.cloud:google-cloud-core:0.2.8' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "gcloud-java-core" % "0.2.8" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.2.8" ``` Troubleshooting --------------- -To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting). +To get help, follow the instructions in the [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting). Java Versions ------------- @@ -46,7 +46,7 @@ Contributing Contributions to this library are always welcome and highly encouraged. -See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started. +See `google-cloud`'s [CONTRIBUTING] documentation and the [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information. @@ -65,7 +65,7 @@ License Apache 2.0 - See [LICENSE] for more information. -[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md -[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct -[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE +[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/CONTRIBUTING.md +[code-of-conduct]:https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct +[LICENSE]: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/LICENSE [cloud-platform]: https://cloud.google.com/ From 3f0898f473abf7112792c189909d1c25af6c9d0d Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 30 Aug 2016 13:51:59 +0200 Subject: [PATCH 219/663] Rename gcloud-java to google-cloud in javadoc comments --- .../src/main/java/com/google/cloud/package-info.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/package-info.java b/google-cloud-core/src/main/java/com/google/cloud/package-info.java index 8b548e3d26..50a9efa045 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/package-info.java +++ b/google-cloud-core/src/main/java/com/google/cloud/package-info.java @@ -15,6 +15,6 @@ */ /** - * Core classes for the {@code gcloud-java} library. + * Core classes for the {@code google-cloud} library. */ package com.google.cloud; From c2c69f5b21adcbd4608a6e81bb0faea9f6b476ba Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 30 Aug 2016 14:34:05 +0200 Subject: [PATCH 220/663] Add new env variable for project, change namespace for datastore example --- .../src/main/java/com/google/cloud/ServiceOptions.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index db24555a18..acd1611797 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -64,10 +64,11 @@ public abstract class ServiceOptions, Service OptionsT extends ServiceOptions> implements Serializable { private static final String DEFAULT_HOST = "https://www.googleapis.com"; - private static final String PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; private static final String MANIFEST_ARTIFACT_ID_KEY = "artifactId"; private static final String MANIFEST_VERSION_KEY = "Implementation-Version"; - private static final String ARTIFACT_ID = "gcloud-java-core"; + private static final String ARTIFACT_ID = "google-cloud-core"; private static final String LIBRARY_NAME = "gcloud-java"; private static final String LIBRARY_VERSION = getLibraryVersion(); private static final String APPLICATION_NAME = @@ -261,6 +262,10 @@ protected String defaultHost() { protected String defaultProject() { String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } if (projectId == null) { projectId = appEngineProjectId(); } From 628106f7a86282625563788c67d9f5a2e4da4348 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 30 Aug 2016 14:41:58 +0200 Subject: [PATCH 221/663] Bump google-cloud to version 0.3.0-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6d1b948f8f..900b7f5739 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.2.9-SNAPSHOT + 0.3.0-SNAPSHOT google-cloud-core From c0b887377bdddcce975be742ca48536fb4dfad7c Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 31 Aug 2016 08:59:16 +0200 Subject: [PATCH 222/663] Release 0.3.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 900b7f5739..7dc25356c6 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.3.0-SNAPSHOT + 0.3.0 google-cloud-core From a8edfae898b0d7e1b529411002e0398489bf3e73 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Wed, 31 Aug 2016 09:55:52 +0000 Subject: [PATCH 223/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 6a6fcbc2b6..8e66bea2a3 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.2.8 + 0.3.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.2.8' +compile 'com.google.cloud:google-cloud-core:0.3.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.2.8" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.3.0" ``` Troubleshooting From 7613fcedb0e6881c14e5a2d6ef83a30cdea71b8f Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 31 Aug 2016 15:28:11 +0200 Subject: [PATCH 224/663] Update version to 0.3.1-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7dc25356c6..4784a40b09 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.3.0 + 0.3.1-SNAPSHOT google-cloud-core From 0360fe315e204c678553baee630770734606a40a Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 6 Sep 2016 22:36:17 +0200 Subject: [PATCH 225/663] Refactor IAM-related classes to be ready to support more services (#1224) Refactor IAM-related classes to be ready to support more services - Remove resourcemanager's Policy class - Rename core's IamPolicy to Policy - Add Role class to hold string values for roles - Add Policy.Marshaller and Policy.DefaultMarshaller classes to convert Policy to/from gRPC protos - Add PolicyMarshaller to resourcemanager to convert Policy to/from resourcemanager's protos - Update READMEs, javadoc and examples - Add factory methods for primitive roles, other minor fixes --- google-cloud-core/pom.xml | 7 +- .../main/java/com/google/cloud/Identity.java | 8 +- .../cloud/{IamPolicy.java => Policy.java} | 194 +++++++++++++----- .../src/main/java/com/google/cloud/Role.java | 109 ++++++++++ .../{IamPolicyTest.java => PolicyTest.java} | 165 ++++++--------- .../test/java/com/google/cloud/RoleTest.java | 65 ++++++ .../com/google/cloud/SerializationTest.java | 29 +-- 7 files changed, 397 insertions(+), 180 deletions(-) rename google-cloud-core/src/main/java/com/google/cloud/{IamPolicy.java => Policy.java} (50%) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/Role.java rename google-cloud-core/src/test/java/com/google/cloud/{IamPolicyTest.java => PolicyTest.java} (52%) create mode 100644 google-cloud-core/src/test/java/com/google/cloud/RoleTest.java diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4784a40b09..248eaa925f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -111,7 +111,12 @@ com.google.api.grpc grpc-google-common-protos - 0.0.7 + 0.0.9 + + + com.google.api.grpc + grpc-google-iam-v1 + 0.0.9 diff --git a/google-cloud-core/src/main/java/com/google/cloud/Identity.java b/google-cloud-core/src/main/java/com/google/cloud/Identity.java index fab70dfe6d..783e99f796 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Identity.java @@ -24,8 +24,7 @@ import java.util.Objects; /** - * An identity in an {@link IamPolicy}. The following types of identities are permitted in IAM - * policies: + * An identity in a {@link Policy}. The following types of identities are permitted in IAM policies: *

      *
    • Google account *
    • Service account @@ -161,6 +160,11 @@ public static Identity domain(String domain) { return new Identity(Type.DOMAIN, checkNotNull(domain)); } + @Override + public String toString() { + return strValue(); + } + @Override public int hashCode() { return Objects.hash(value, type); diff --git a/google-cloud-core/src/main/java/com/google/cloud/IamPolicy.java b/google-cloud-core/src/main/java/com/google/cloud/Policy.java similarity index 50% rename from google-cloud-core/src/main/java/com/google/cloud/IamPolicy.java rename to google-cloud-core/src/main/java/com/google/cloud/Policy.java index 2d15d99076..2a8009d403 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/IamPolicy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Policy.java @@ -19,79 +19,146 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Function; +import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.common.io.BaseEncoding; +import com.google.protobuf.ByteString; import java.io.Serializable; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; /** - * Base class for Identity and Access Management (IAM) policies. IAM policies are used to specify - * access settings for Cloud Platform resources. A policy is a map of bindings. A binding assigns - * a set of identities to a role, where the identities can be user accounts, Google groups, Google - * domains, and service accounts. A role is a named list of permissions defined by IAM. + * Class for Identity and Access Management (IAM) policies. IAM policies are used to specify access + * settings for Cloud Platform resources. A policy is a map of bindings. A binding assigns a set of + * identities to a role, where the identities can be user accounts, Google groups, Google domains, + * and service accounts. A role is a named list of permissions defined by IAM. * - * @param the data type of roles (should be serializable) * @see Policy */ -public abstract class IamPolicy implements Serializable { +public final class Policy implements Serializable { - private static final long serialVersionUID = 1114489978726897720L; + private static final long serialVersionUID = -3348914530232544290L; - private final Map> bindings; + private final Map> bindings; private final String etag; - private final Integer version; + private final int version; + + public abstract static class Marshaller { + + protected static final Function IDENTITY_VALUE_OF_FUNCTION = + new Function() { + @Override + public Identity apply(String identityPb) { + return Identity.valueOf(identityPb); + } + }; + protected static final Function IDENTITY_STR_VALUE_FUNCTION = + new Function() { + @Override + public String apply(Identity identity) { + return identity.strValue(); + } + }; + + protected abstract Policy fromPb(T policyPb); + + protected abstract T toPb(Policy policy); + } + + public static class DefaultMarshaller extends Marshaller { + + @Override + protected Policy fromPb(com.google.iam.v1.Policy policyPb) { + Map> bindings = new HashMap<>(); + for (com.google.iam.v1.Binding bindingPb : policyPb.getBindingsList()) { + bindings.put(Role.of(bindingPb.getRole()), + ImmutableSet.copyOf( + Lists.transform(bindingPb.getMembersList(), IDENTITY_VALUE_OF_FUNCTION))); + } + return builder() + .bindings(bindings) + .etag(policyPb.getEtag().isEmpty() ? null + : BaseEncoding.base64().encode(policyPb.getEtag().toByteArray())) + .version(policyPb.getVersion()) + .build(); + } + + @Override + protected com.google.iam.v1.Policy toPb(Policy policy) { + com.google.iam.v1.Policy.Builder policyBuilder = com.google.iam.v1.Policy.newBuilder(); + List bindingPbList = new LinkedList<>(); + for (Map.Entry> binding : policy.bindings().entrySet()) { + com.google.iam.v1.Binding.Builder bindingBuilder = com.google.iam.v1.Binding.newBuilder(); + bindingBuilder.setRole(binding.getKey().value()); + bindingBuilder.addAllMembers( + Lists.transform(new ArrayList<>(binding.getValue()), IDENTITY_STR_VALUE_FUNCTION)); + bindingPbList.add(bindingBuilder.build()); + } + policyBuilder.addAllBindings(bindingPbList); + if (policy.etag != null) { + policyBuilder.setEtag(ByteString.copyFrom(BaseEncoding.base64().decode(policy.etag))); + } + policyBuilder.setVersion(policy.version); + return policyBuilder.build(); + } + } /** - * Builder for an IAM Policy. - * - * @param the data type of roles - * @param the subclass extending this abstract builder + * A builder for {@code Policy} objects. */ - public abstract static class Builder> { + public static class Builder { - private final Map> bindings = new HashMap<>(); + private final Map> bindings = new HashMap<>(); private String etag; - private Integer version; + private int version; - /** - * Constructor for IAM Policy builder. - */ protected Builder() {} + protected Builder(Policy policy) { + bindings(policy.bindings); + etag(policy.etag); + version(policy.version); + } + /** * Replaces the builder's map of bindings with the given map of bindings. * * @throws NullPointerException if the given map is null or contains any null keys or values * @throws IllegalArgumentException if any identities in the given map are null */ - public final B bindings(Map> bindings) { + public final Builder bindings(Map> bindings) { checkNotNull(bindings, "The provided map of bindings cannot be null."); - for (Map.Entry> binding : bindings.entrySet()) { + for (Map.Entry> binding : bindings.entrySet()) { checkNotNull(binding.getKey(), "The role cannot be null."); Set identities = binding.getValue(); checkNotNull(identities, "A role cannot be assigned to a null set of identities."); checkArgument(!identities.contains(null), "Null identities are not permitted."); } this.bindings.clear(); - for (Map.Entry> binding : bindings.entrySet()) { - this.bindings.put(binding.getKey(), new HashSet(binding.getValue())); + for (Map.Entry> binding : bindings.entrySet()) { + this.bindings.put(binding.getKey(), new HashSet<>(binding.getValue())); } - return self(); + return this; } /** * Removes the role (and all identities associated with that role) from the policy. */ - public final B removeRole(R role) { + public final Builder removeRole(Role role) { bindings.remove(role); - return self(); + return this; } /** @@ -99,7 +166,7 @@ public final B removeRole(R role) { * * @throws NullPointerException if the role or any of the identities is null. */ - public final B addIdentity(R role, Identity first, Identity... others) { + public final Builder addIdentity(Role role, Identity first, Identity... others) { String nullIdentityMessage = "Null identities are not permitted."; checkNotNull(first, nullIdentityMessage); checkNotNull(others, nullIdentityMessage); @@ -111,18 +178,18 @@ public final B addIdentity(R role, Identity first, Identity... others) { toAdd.addAll(Arrays.asList(others)); Set identities = bindings.get(checkNotNull(role, "The role cannot be null.")); if (identities == null) { - identities = new HashSet(); + identities = new HashSet<>(); bindings.put(role, identities); } identities.addAll(toAdd); - return self(); + return this; } /** * Removes one or more identities from an existing binding. Does nothing if the binding * associated with the provided role doesn't exist. */ - public final B removeIdentity(R role, Identity first, Identity... others) { + public final Builder removeIdentity(Role role, Identity first, Identity... others) { Set identities = bindings.get(role); if (identities != null) { identities.remove(first); @@ -131,7 +198,7 @@ public final B removeIdentity(R role, Identity first, Identity... others) { if (identities != null && identities.isEmpty()) { bindings.remove(role); } - return self(); + return this; } /** @@ -145,31 +212,31 @@ public final B removeIdentity(R role, Identity first, Identity... others) { * applied to the same version of the policy. If no etag is provided in the call to * setIamPolicy, then the existing policy is overwritten blindly. */ - protected final B etag(String etag) { + protected final Builder etag(String etag) { this.etag = etag; - return self(); + return this; } /** * Sets the version of the policy. The default version is 0, meaning only the "owner", "editor", * and "viewer" roles are permitted. If the version is 1, you may also use other roles. */ - protected final B version(Integer version) { + protected final Builder version(int version) { this.version = version; - return self(); + return this; } - @SuppressWarnings("unchecked") - private B self() { - return (B) this; + /** + * Creates a {@code Policy} object. + */ + public final Policy build() { + return new Policy(this); } - - public abstract IamPolicy build(); } - protected IamPolicy(Builder> builder) { - ImmutableMap.Builder> bindingsBuilder = ImmutableMap.builder(); - for (Map.Entry> binding : builder.bindings.entrySet()) { + private Policy(Builder builder) { + ImmutableMap.Builder> bindingsBuilder = ImmutableMap.builder(); + for (Map.Entry> binding : builder.bindings.entrySet()) { bindingsBuilder.put(binding.getKey(), ImmutableSet.copyOf(binding.getValue())); } this.bindings = bindingsBuilder.build(); @@ -180,17 +247,19 @@ protected IamPolicy(Builder> builder) { /** * Returns a builder containing the properties of this IAM Policy. */ - public abstract Builder> toBuilder(); + public Builder toBuilder() { + return new Builder(this); + } /** - * The map of bindings that comprises the policy. + * Returns the map of bindings that comprises the policy. */ - public Map> bindings() { + public Map> bindings() { return bindings; } /** - * The policy's etag. + * Returns the policy's etag. * *

      Etags are used for optimistic concurrency control as a way to help prevent simultaneous * updates of a policy from overwriting each other. It is strongly suggested that systems make @@ -205,30 +274,45 @@ public String etag() { } /** - * Sets the version of the policy. The default version is 0, meaning only the "owner", "editor", - * and "viewer" roles are permitted. If the version is 1, you may also use other roles. + * Returns the version of the policy. The default version is 0, meaning only the "owner", + * "editor", and "viewer" roles are permitted. If the version is 1, you may also use other roles. */ - public Integer version() { + public int version() { return version; } @Override - public final int hashCode() { + public String toString() { + return MoreObjects.toStringHelper(this) + .add("bindings", bindings) + .add("etag", etag) + .add("version", version) + .toString(); + } + + @Override + public int hashCode() { return Objects.hash(getClass(), bindings, etag, version); } @Override - public final boolean equals(Object obj) { + public boolean equals(Object obj) { if (obj == this) { return true; } - if (obj == null || !obj.getClass().equals(getClass())) { + if (!(obj instanceof Policy)) { return false; } - @SuppressWarnings("rawtypes") - IamPolicy other = (IamPolicy) obj; + Policy other = (Policy) obj; return Objects.equals(bindings, other.bindings()) && Objects.equals(etag, other.etag()) && Objects.equals(version, other.version()); } + + /** + * Returns a builder for {@code Policy} objects. + */ + public static Builder builder() { + return new Builder(); + } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/Role.java b/google-cloud-core/src/main/java/com/google/cloud/Role.java new file mode 100644 index 0000000000..60f826d3a9 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/Role.java @@ -0,0 +1,109 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.Serializable; +import java.util.Objects; + +/** + * A role in a IAM {@link Policy}. Project owners can grant access to team members to access + * project's resources and APIs by granting IAM roles to team members. + * + * @see Viewing the Grantable + * Roles on Resources + * @see Understanding Roles + */ +public final class Role implements Serializable { + + private static final long serialVersionUID = -7779252712160972508L; + private static final String ROLE_PREFIX = "roles/"; + + private final String value; + + private Role(String value) { + this.value = value; + } + + /** + * Returns the string identifier for this role. For example, {@code "roles/viewer"}, + * {@code "roles/editor"}, or {@code "roles/owner"}. + */ + public String value() { + return value; + } + + /** + * Returns the viewer role. Encapsulates the permission for read-only actions that preserve state + * of a resource. + * + * @see Understanding Roles + */ + public static Role viewer() { + return of("viewer"); + } + + /** + * Returns the editor role. Encapsulates all viewer's permissions and permissions for actions that + * modify the state of a resource. + * + * @see Understanding Roles + */ + public static Role editor() { + return of("editor"); + } + + /** + * Returns the owner role. Encapsulates all editor's permissions and permissions to manage access + * control for a resource or manage the billing options for a project. + * + * @see Understanding Roles + */ + public static Role owner() { + return of("owner"); + } + + /** + * Returns a new role given its string value. + * + * @param value the string value for the role, for example, {@code "roles/viewer"}, + * {@code "roles/editor"}, or {@code "roles/owner"}. If this value does not start with the + * role prefix {@code roles/}, the prefix is prepended. + * @see Viewing the Grantable + * Roles on Resources + */ + public static Role of(String value) { + checkNotNull(value); + return new Role(value.startsWith(ROLE_PREFIX) ? value : ROLE_PREFIX + value); + } + + @Override + public int hashCode() { + return Objects.hash(value); + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof Role && Objects.equals(value, ((Role) obj).value()); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/IamPolicyTest.java b/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java similarity index 52% rename from google-cloud-core/src/test/java/com/google/cloud/IamPolicyTest.java rename to google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java index e79cfd9655..946c5584d5 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/IamPolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.google.cloud.Policy.DefaultMarshaller; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -33,7 +34,7 @@ import java.util.Map; import java.util.Set; -public class IamPolicyTest { +public class PolicyTest { private static final Identity ALL_USERS = Identity.allUsers(); private static final Identity ALL_AUTH_USERS = Identity.allAuthenticatedUsers(); @@ -42,123 +43,101 @@ public class IamPolicyTest { Identity.serviceAccount("service-account@gmail.com"); private static final Identity GROUP = Identity.group("group@gmail.com"); private static final Identity DOMAIN = Identity.domain("google.com"); - private static final Map> BINDINGS = ImmutableMap.of( - "viewer", + private static final Role VIEWER = Role.viewer(); + private static final Role EDITOR = Role.editor(); + private static final Role OWNER = Role.owner(); + private static final Map> BINDINGS = ImmutableMap.of( + VIEWER, ImmutableSet.of(USER, SERVICE_ACCOUNT, ALL_USERS), - "editor", + EDITOR, ImmutableSet.of(ALL_AUTH_USERS, GROUP, DOMAIN)); - private static final PolicyImpl SIMPLE_POLICY = PolicyImpl.builder() - .addIdentity("viewer", USER, SERVICE_ACCOUNT, ALL_USERS) - .addIdentity("editor", ALL_AUTH_USERS, GROUP, DOMAIN) + private static final Policy SIMPLE_POLICY = Policy.builder() + .addIdentity(VIEWER, USER, SERVICE_ACCOUNT, ALL_USERS) + .addIdentity(EDITOR, ALL_AUTH_USERS, GROUP, DOMAIN) + .build(); + private static final Policy FULL_POLICY = Policy.builder() + .bindings(SIMPLE_POLICY.bindings()) + .etag("etag") + .version(1) .build(); - private static final PolicyImpl FULL_POLICY = - new PolicyImpl.Builder(SIMPLE_POLICY.bindings(), "etag", 1).build(); - - static class PolicyImpl extends IamPolicy { - - static class Builder extends IamPolicy.Builder { - - private Builder() {} - - private Builder(Map> bindings, String etag, Integer version) { - bindings(bindings).etag(etag).version(version); - } - - @Override - public PolicyImpl build() { - return new PolicyImpl(this); - } - } - - PolicyImpl(Builder builder) { - super(builder); - } - - @Override - public Builder toBuilder() { - return new Builder(bindings(), etag(), version()); - } - - static Builder builder() { - return new Builder(); - } - } @Test public void testBuilder() { + assertEquals(BINDINGS, SIMPLE_POLICY.bindings()); + assertEquals(null, SIMPLE_POLICY.etag()); + assertEquals(0, SIMPLE_POLICY.version()); assertEquals(BINDINGS, FULL_POLICY.bindings()); assertEquals("etag", FULL_POLICY.etag()); - assertEquals(1, FULL_POLICY.version().intValue()); - Map> editorBinding = - ImmutableMap.>builder().put("editor", BINDINGS.get("editor")).build(); - PolicyImpl policy = FULL_POLICY.toBuilder().bindings(editorBinding).build(); + assertEquals(1, FULL_POLICY.version()); + Map> editorBinding = + ImmutableMap.>builder().put(EDITOR, BINDINGS.get(EDITOR)).build(); + Policy policy = FULL_POLICY.toBuilder().bindings(editorBinding).build(); assertEquals(editorBinding, policy.bindings()); assertEquals("etag", policy.etag()); - assertEquals(1, policy.version().intValue()); - policy = SIMPLE_POLICY.toBuilder().removeRole("editor").build(); - assertEquals(ImmutableMap.of("viewer", BINDINGS.get("viewer")), policy.bindings()); + assertEquals(1, policy.version()); + policy = SIMPLE_POLICY.toBuilder().removeRole(EDITOR).build(); + assertEquals(ImmutableMap.of(VIEWER, BINDINGS.get(VIEWER)), policy.bindings()); assertNull(policy.etag()); - assertNull(policy.version()); + assertEquals(0, policy.version()); policy = policy.toBuilder() - .removeIdentity("viewer", USER, ALL_USERS) - .addIdentity("viewer", DOMAIN, GROUP) + .removeIdentity(VIEWER, USER, ALL_USERS) + .addIdentity(VIEWER, DOMAIN, GROUP) .build(); - assertEquals(ImmutableMap.of("viewer", ImmutableSet.of(SERVICE_ACCOUNT, DOMAIN, GROUP)), + assertEquals(ImmutableMap.of(VIEWER, ImmutableSet.of(SERVICE_ACCOUNT, DOMAIN, GROUP)), policy.bindings()); assertNull(policy.etag()); - assertNull(policy.version()); - policy = PolicyImpl.builder() - .removeIdentity("viewer", USER) - .addIdentity("owner", USER, SERVICE_ACCOUNT) - .addIdentity("editor", GROUP) - .removeIdentity("editor", GROUP) + assertEquals(0, policy.version()); + policy = Policy.builder() + .removeIdentity(VIEWER, USER) + .addIdentity(OWNER, USER, SERVICE_ACCOUNT) + .addIdentity(EDITOR, GROUP) + .removeIdentity(EDITOR, GROUP) .build(); - assertEquals( - ImmutableMap.of("owner", ImmutableSet.of(USER, SERVICE_ACCOUNT)), policy.bindings()); + assertEquals(ImmutableMap.of(OWNER, ImmutableSet.of(USER, SERVICE_ACCOUNT)), policy.bindings()); assertNull(policy.etag()); - assertNull(policy.version()); + assertEquals(0, policy.version()); } @Test public void testIllegalPolicies() { try { - PolicyImpl.builder().addIdentity(null, USER); + Policy.builder().addIdentity(null, USER); fail("Null role should cause exception."); } catch (NullPointerException ex) { assertEquals("The role cannot be null.", ex.getMessage()); } try { - PolicyImpl.builder().addIdentity("viewer", null, USER); + Policy.builder().addIdentity(VIEWER, null, USER); fail("Null identity should cause exception."); } catch (NullPointerException ex) { assertEquals("Null identities are not permitted.", ex.getMessage()); } try { - PolicyImpl.builder().addIdentity("viewer", USER, (Identity[]) null); + Policy.builder().addIdentity(VIEWER, USER, (Identity[]) null); fail("Null identity should cause exception."); } catch (NullPointerException ex) { assertEquals("Null identities are not permitted.", ex.getMessage()); } try { - PolicyImpl.builder().bindings(null); + Policy.builder().bindings(null); fail("Null bindings map should cause exception."); } catch (NullPointerException ex) { assertEquals("The provided map of bindings cannot be null.", ex.getMessage()); } try { - Map> bindings = new HashMap<>(); - bindings.put("viewer", null); - PolicyImpl.builder().bindings(bindings); + Map> bindings = new HashMap<>(); + bindings.put(VIEWER, null); + Policy.builder().bindings(bindings); fail("Null set of identities should cause exception."); } catch (NullPointerException ex) { assertEquals("A role cannot be assigned to a null set of identities.", ex.getMessage()); } try { - Map> bindings = new HashMap<>(); + Map> bindings = new HashMap<>(); Set identities = new HashSet<>(); identities.add(null); - bindings.put("viewer", identities); - PolicyImpl.builder().bindings(bindings); + bindings.put(VIEWER, identities); + Policy.builder().bindings(bindings); fail("Null identity should cause exception."); } catch (IllegalArgumentException ex) { assertEquals("Null identities are not permitted.", ex.getMessage()); @@ -168,20 +147,20 @@ public void testIllegalPolicies() { @Test public void testEqualsHashCode() { assertNotNull(FULL_POLICY); - PolicyImpl emptyPolicy = PolicyImpl.builder().build(); - AnotherPolicyImpl anotherPolicy = new AnotherPolicyImpl.Builder().build(); - assertNotEquals(emptyPolicy, anotherPolicy); - assertNotEquals(emptyPolicy.hashCode(), anotherPolicy.hashCode()); + Policy emptyPolicy = Policy.builder().build(); + Policy anotherPolicy = Policy.builder().build(); + assertEquals(emptyPolicy, anotherPolicy); + assertEquals(emptyPolicy.hashCode(), anotherPolicy.hashCode()); assertNotEquals(FULL_POLICY, SIMPLE_POLICY); assertNotEquals(FULL_POLICY.hashCode(), SIMPLE_POLICY.hashCode()); - PolicyImpl copy = SIMPLE_POLICY.toBuilder().build(); + Policy copy = SIMPLE_POLICY.toBuilder().build(); assertEquals(SIMPLE_POLICY, copy); assertEquals(SIMPLE_POLICY.hashCode(), copy.hashCode()); } @Test public void testBindings() { - assertTrue(PolicyImpl.builder().build().bindings().isEmpty()); + assertTrue(Policy.builder().build().bindings().isEmpty()); assertEquals(BINDINGS, SIMPLE_POLICY.bindings()); } @@ -193,29 +172,21 @@ public void testEtag() { @Test public void testVersion() { - assertNull(SIMPLE_POLICY.version()); - assertEquals(1, FULL_POLICY.version().intValue()); + assertEquals(0, SIMPLE_POLICY.version()); + assertEquals(1, FULL_POLICY.version()); } - static class AnotherPolicyImpl extends IamPolicy { - - static class Builder extends IamPolicy.Builder { - - private Builder() {} - - @Override - public AnotherPolicyImpl build() { - return new AnotherPolicyImpl(this); - } - } - - AnotherPolicyImpl(Builder builder) { - super(builder); - } - - @Override - public Builder toBuilder() { - return new Builder(); - } + @Test + public void testDefaultMarshaller() { + DefaultMarshaller marshaller = new DefaultMarshaller(); + Policy emptyPolicy = Policy.builder().build(); + assertEquals(emptyPolicy, marshaller.fromPb(marshaller.toPb(emptyPolicy))); + assertEquals(SIMPLE_POLICY, marshaller.fromPb(marshaller.toPb(SIMPLE_POLICY))); + assertEquals(FULL_POLICY, marshaller.fromPb(marshaller.toPb(FULL_POLICY))); + com.google.iam.v1.Policy policyPb = com.google.iam.v1.Policy.getDefaultInstance(); + Policy policy = marshaller.fromPb(policyPb); + assertTrue(policy.bindings().isEmpty()); + assertNull(policy.etag()); + assertEquals(0, policy.version()); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java new file mode 100644 index 0000000000..c66c28a952 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class RoleTest { + + private static final Role VIEWER = Role.of("viewer"); + private static final Role EDITOR = Role.of("editor"); + private static final Role OWNER = Role.of("owner"); + + @Test + public void testOf() { + assertEquals("roles/viewer", VIEWER.value()); + assertEquals("roles/editor", EDITOR.value()); + assertEquals("roles/owner", OWNER.value()); + compareRoles(VIEWER, Role.of("roles/viewer")); + compareRoles(EDITOR, Role.of("roles/editor")); + compareRoles(OWNER, Role.of("roles/owner")); + } + + @Test + public void testViewer() { + assertEquals("roles/viewer", Role.viewer().value()); + } + + @Test + public void testEditor() { + assertEquals("roles/editor", Role.editor().value()); + } + + @Test + public void testOwner() { + assertEquals("roles/owner", Role.owner().value()); + } + + @Test(expected = NullPointerException.class) + public void testOfNullValue() { + Role.of(null); + } + + private void compareRoles(Role expected, Role actual) { + assertEquals(expected, actual); + assertEquals(expected.value(), actual.value()); + assertEquals(expected.hashCode(), actual.hashCode()); + assertEquals(expected.toString(), actual.toString()); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 77f56ed3dd..13baed858b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -39,7 +39,8 @@ public class SerializationTest extends BaseSerializationTest { private static final SigningException SIGNING_EXCEPTION = new SigningException("message", BASE_SERVICE_EXCEPTION); private static final RetryParams RETRY_PARAMS = RetryParams.defaultInstance(); - private static final SomeIamPolicy SOME_IAM_POLICY = new SomeIamPolicy.Builder().build(); + private static final Role SOME_ROLE = Role.viewer(); + private static final Policy SOME_IAM_POLICY = Policy.builder().build(); private static final WaitForOption CHECKING_PERIOD = WaitForOption.checkEvery(42, TimeUnit.SECONDS); private static final LabelDescriptor LABEL_DESCRIPTOR = @@ -78,33 +79,11 @@ public class SerializationTest extends BaseSerializationTest { + " \"type\": \"service_account\"\n" + "}"; - private static class SomeIamPolicy extends IamPolicy { - - private static final long serialVersionUID = 271243551016958285L; - - private static class Builder extends IamPolicy.Builder { - - @Override - public SomeIamPolicy build() { - return new SomeIamPolicy(this); - } - } - - protected SomeIamPolicy(Builder builder) { - super(builder); - } - - @Override - public Builder toBuilder() { - return new Builder(); - } - } - @Override protected Serializable[] serializableObjects() { return new Serializable[]{BASE_SERVICE_EXCEPTION, EXCEPTION_HANDLER, IDENTITY, PAGE, - RETRY_PARAMS, SOME_IAM_POLICY, SIGNING_EXCEPTION, CHECKING_PERIOD, LABEL_DESCRIPTOR, - MONITORED_RESOURCE_DESCRIPTOR, MONITORED_RESOURCE}; + RETRY_PARAMS, SOME_ROLE, SOME_IAM_POLICY, SIGNING_EXCEPTION, CHECKING_PERIOD, + LABEL_DESCRIPTOR, MONITORED_RESOURCE_DESCRIPTOR, MONITORED_RESOURCE}; } @Override From ce74202247ee2554bb1f8dcb77d86e0ad173e2c4 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Wed, 28 Sep 2016 09:53:35 -0700 Subject: [PATCH 226/663] Update grpc, protobuf, datastore and gax dependencies, regenerate SPI classes (#1273) * Regenerating SPI classes * Updating grpc to 1.0.1 and protobuf to 3.0.0 * Converting PageAccessor to PagedListResponse * Adding auto-generated tests for logging * Removing some unused imports * Updating datastore proto dependency * Removing unnecessary auto-value dependency * Using correct version of netty-tcnative-boringssl-static --- google-cloud-core/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 248eaa925f..b1781b3238 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -101,22 +101,22 @@ com.google.protobuf protobuf-java - 3.0.0-beta-3 + 3.0.0 com.google.api gax - 0.0.16 + 0.0.18 com.google.api.grpc grpc-google-common-protos - 0.0.9 + 0.1.0 com.google.api.grpc grpc-google-iam-v1 - 0.0.9 + 0.1.0 From ea7ed2093b915b1f53ac45f2bdb9b474c48b864a Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 29 Sep 2016 13:16:37 +0200 Subject: [PATCH 227/663] Release 0.4.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b1781b3238..f6161fee3c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.3.1-SNAPSHOT + 0.4.0 google-cloud-core From a251db2c539b6714cde3c2f48f316223b96a2e08 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Thu, 29 Sep 2016 13:15:40 +0000 Subject: [PATCH 228/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 8e66bea2a3..aabe170ffe 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.3.0 + 0.4.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.3.0' +compile 'com.google.cloud:google-cloud-core:0.4.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.3.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.4.0" ``` Troubleshooting From 1e7591678426fa38595f5518ffdd6e1f8659c404 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 29 Sep 2016 19:30:26 +0200 Subject: [PATCH 229/663] Update version to 0.4.1-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f6161fee3c..e3fb52ed2e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.4.0 + 0.4.1-SNAPSHOT google-cloud-core From 76226bd68e2212b8321cc299c066e7220c9e78bc Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 21 Oct 2016 12:51:16 +0200 Subject: [PATCH 230/663] Rename setters/getters/builders for Logging classes to meet proto conventions (#1313) * Rename setters/getters/builders for Logging classes to meet proto conventions * Update Logging examples, snippets and READMEs to use renamed getters/setters/builders * Make deprecated methods call renamed ones --- .../com/google/cloud/MonitoredResource.java | 52 ++++++++++- .../cloud/MonitoredResourceDescriptor.java | 93 +++++++++++++++++-- .../MonitoredResourceDescriptorTest.java | 63 +++++++++---- .../google/cloud/MonitoredResourceTest.java | 53 ++++++++--- .../com/google/cloud/SerializationTest.java | 8 +- 5 files changed, 223 insertions(+), 46 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java index 584bc80ced..66cd15ce1e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java @@ -66,7 +66,17 @@ public static class Builder { * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. */ + @Deprecated public Builder type(String type) { + return setType(type); + } + + /** + * Sets the monitored resource type. This value must match the one of + * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. + * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. + */ + public Builder setType(String type) { this.type = type; return this; } @@ -76,7 +86,17 @@ public Builder type(String type) { * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute * Engine VM instances use the labels {@code instance_id} and {@code zone}. */ + @Deprecated public Builder labels(Map labels) { + return setLabels(labels); + } + + /** + * Sets the values for all the labels required by the corresponding monitored resource + * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute + * Engine VM instances use the labels {@code instance_id} and {@code zone}. + */ + public Builder setLabels(Map labels) { this.labels = new HashMap<>(checkNotNull(labels)); return this; } @@ -112,7 +132,17 @@ public MonitoredResource build() { * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. */ + @Deprecated public String type() { + return getType(); + } + + /** + * Returns the monitored resource type. This value must match the one of + * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. + * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. + */ + public String getType() { return type; } @@ -121,7 +151,17 @@ public String type() { * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute * Engine VM instances use the labels {@code instance_id} and {@code zone}. */ + @Deprecated public Map labels() { + return getLabels(); + } + + /** + * Returns the values for all the labels required by the corresponding monitored resource + * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute + * Engine VM instances use the labels {@code instance_id} and {@code zone}. + */ + public Map getLabels() { return labels; } @@ -167,7 +207,15 @@ public Builder toBuilder() { /** * Returns a builder for {@code MonitoredResource} objects given the resource's type. */ + @Deprecated public static Builder builder(String type) { + return newBuilder(type); + } + + /** + * Returns a builder for {@code MonitoredResource} objects given the resource's type. + */ + public static Builder newBuilder(String type) { return new Builder(type); } @@ -175,10 +223,10 @@ public static Builder builder(String type) { * Creates a {@code MonitoredResource} object given the resource's type and labels. */ public static MonitoredResource of(String type, Map labels) { - return builder(type).labels(labels).build(); + return newBuilder(type).setLabels(labels).build(); } public static MonitoredResource fromPb(com.google.api.MonitoredResource descriptorPb) { - return new Builder(descriptorPb.getType()).labels(descriptorPb.getLabels()).build(); + return new Builder(descriptorPb.getType()).setLabels(descriptorPb.getLabelsMap()).build(); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java index cb121094ef..ebee6544df 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java @@ -120,14 +120,30 @@ static ValueType fromPb(com.google.api.LabelDescriptor.ValueType typePb) { /** * Returns the key associated to this label. */ + @Deprecated public String key() { + return getKey(); + } + + /** + * Returns the key associated to this label. + */ + public String getKey() { return key; } /** * Returns the type of data that can be assigned to this label. */ + @Deprecated public ValueType valueType() { + return getValueType(); + } + + /** + * Returns the type of data that can be assigned to this label. + */ + public ValueType getValueType() { return valueType; } @@ -135,7 +151,16 @@ public ValueType valueType() { * Returns the optional human-readable description for this label. If not set, this method * returns {@code null}. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns the optional human-readable description for this label. If not set, this method + * returns {@code null}. + */ + public String getDescription() { return description; } @@ -199,22 +224,22 @@ static class Builder { this.type = type; } - Builder name(String name) { + Builder setName(String name) { this.name = name; return this; } - Builder displayName(String displayName) { + Builder setDisplayName(String displayName) { this.displayName = displayName; return this; } - Builder description(String description) { + Builder setDescription(String description) { this.description = description; return this; } - Builder labels(List labels) { + Builder setLabels(List labels) { this.labels = labels; return this; } @@ -236,7 +261,16 @@ MonitoredResourceDescriptor build() { * Returns the monitored resource type. For example, the type {@code cloudsql_database} represents * databases in Google Cloud SQL. */ + @Deprecated public String type() { + return getType(); + } + + /** + * Returns the monitored resource type. For example, the type {@code cloudsql_database} represents + * databases in Google Cloud SQL. + */ + public String getType() { return type; } @@ -244,7 +278,16 @@ public String type() { * Returns an optional name for the monitored resource descriptor. If not set, this method returns * {@code null}. */ + @Deprecated public String name() { + return getName(); + } + + /** + * Returns an optional name for the monitored resource descriptor. If not set, this method returns + * {@code null}. + */ + public String getName() { return name; } @@ -253,7 +296,17 @@ public String name() { * in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method * returns {@code null}. */ + @Deprecated public String displayName() { + return getDisplayName(); + } + + /** + * Returns an optional concise name for the monitored resource type. This value might be displayed + * in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method + * returns {@code null}. + */ + public String getDisplayName() { return displayName; } @@ -261,7 +314,16 @@ public String displayName() { * Returns an optional detailed description of the monitored resource type. This value might be * used in documentation. If not set, this method returns {@code null}. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns an optional detailed description of the monitored resource type. This value might be + * used in documentation. If not set, this method returns {@code null}. + */ + public String getDescription() { return description; } @@ -270,7 +332,17 @@ public String description() { * example, an individual Google Cloud SQL database is identified by values for the labels * {@code database_id} and {@code region}. */ + @Deprecated public List labels() { + return getLabels(); + } + + /** + * Returns a list of labels used to describe instances of this monitored resource type. For + * example, an individual Google Cloud SQL database is identified by values for the labels + * {@code database_id} and {@code region}. + */ + public List getLabels() { return labels; } @@ -323,23 +395,24 @@ public com.google.api.MonitoredResourceDescriptor toPb() { return builder.build(); } - static Builder builder(String type) { + static Builder newBuilder(String type) { return new Builder(type); } public static MonitoredResourceDescriptor fromPb( com.google.api.MonitoredResourceDescriptor descriptorPb) { - Builder builder = builder(descriptorPb.getType()); + Builder builder = newBuilder(descriptorPb.getType()); if (descriptorPb.getName() != null && !descriptorPb.getName().equals("")) { - builder.name(descriptorPb.getName()); + builder.setName(descriptorPb.getName()); } if (descriptorPb.getDisplayName() != null && !descriptorPb.getDisplayName().equals("")) { - builder.displayName(descriptorPb.getDisplayName()); + builder.setDisplayName(descriptorPb.getDisplayName()); } if (descriptorPb.getDescription() != null && !descriptorPb.getDescription().equals("")) { - builder.description(descriptorPb.getDescription()); + builder.setDescription(descriptorPb.getDescription()); } - builder.labels(Lists.transform(descriptorPb.getLabelsList(), LabelDescriptor.FROM_PB_FUNCTION)); + builder.setLabels(Lists.transform(descriptorPb.getLabelsList(), + LabelDescriptor.FROM_PB_FUNCTION)); return builder.build(); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java index cab0438e05..24a8be62e7 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java @@ -44,15 +44,31 @@ public class MonitoredResourceDescriptorTest { private static final List LABELS = ImmutableList.of(BOOLEAN_LABEL, STRING_LABEL, INT_LABEL); private static final MonitoredResourceDescriptor RESOURCE_DESCRIPTOR = - MonitoredResourceDescriptor.builder(TYPE) - .name(NAME) - .displayName(DISPLAY_NAME) - .description(DESCRIPTION) - .labels(LABELS) + MonitoredResourceDescriptor.newBuilder(TYPE) + .setName(NAME) + .setDisplayName(DISPLAY_NAME) + .setDescription(DESCRIPTION) + .setLabels(LABELS) .build(); @Test public void testLabelDescriptor() { + assertEquals("booleanKey", BOOLEAN_LABEL.getKey()); + assertEquals(ValueType.BOOL, BOOLEAN_LABEL.getValueType()); + assertEquals("Boolean label", BOOLEAN_LABEL.getDescription()); + assertEquals("stringKey", STRING_LABEL.getKey()); + assertEquals(ValueType.STRING, STRING_LABEL.getValueType()); + assertEquals("String label", STRING_LABEL.getDescription()); + assertEquals("intKey", INT_LABEL.getKey()); + assertEquals(ValueType.INT64, INT_LABEL.getValueType()); + assertEquals("Int label", INT_LABEL.getDescription()); + assertEquals("intKey", INT_LABEL_NO_DESCRIPTION.getKey()); + assertEquals(ValueType.INT64, INT_LABEL_NO_DESCRIPTION.getValueType()); + assertNull(INT_LABEL_NO_DESCRIPTION.getDescription()); + } + + @Test + public void testLabelDescriptorDeprecated() { assertEquals("booleanKey", BOOLEAN_LABEL.key()); assertEquals(ValueType.BOOL, BOOLEAN_LABEL.valueType()); assertEquals("Boolean label", BOOLEAN_LABEL.description()); @@ -69,13 +85,29 @@ public void testLabelDescriptor() { @Test public void testBuilder() { + assertEquals(TYPE, RESOURCE_DESCRIPTOR.getType()); + assertEquals(NAME, RESOURCE_DESCRIPTOR.getName()); + assertEquals(DISPLAY_NAME, RESOURCE_DESCRIPTOR.getDisplayName()); + assertEquals(DESCRIPTION, RESOURCE_DESCRIPTOR.getDescription()); + assertEquals(LABELS, RESOURCE_DESCRIPTOR.getLabels()); + MonitoredResourceDescriptor resourceDescriptor = + MonitoredResourceDescriptor.newBuilder(TYPE).build(); + assertEquals(TYPE, resourceDescriptor.getType()); + assertNull(resourceDescriptor.getName()); + assertNull(resourceDescriptor.getDisplayName()); + assertNull(resourceDescriptor.getDescription()); + assertEquals(ImmutableList.of(), resourceDescriptor.getLabels()); + } + + @Test + public void testBuilderDeprecated() { assertEquals(TYPE, RESOURCE_DESCRIPTOR.type()); assertEquals(NAME, RESOURCE_DESCRIPTOR.name()); assertEquals(DISPLAY_NAME, RESOURCE_DESCRIPTOR.displayName()); assertEquals(DESCRIPTION, RESOURCE_DESCRIPTOR.description()); assertEquals(LABELS, RESOURCE_DESCRIPTOR.labels()); MonitoredResourceDescriptor resourceDescriptor = - MonitoredResourceDescriptor.builder(TYPE).build(); + MonitoredResourceDescriptor.newBuilder(TYPE).build(); assertEquals(TYPE, resourceDescriptor.type()); assertNull(resourceDescriptor.name()); assertNull(resourceDescriptor.displayName()); @@ -83,7 +115,6 @@ public void testBuilder() { assertEquals(ImmutableList.of(), resourceDescriptor.labels()); } - @Test public void testToAndFromPbLabelDescriptor() { compareLabelDescriptor(BOOLEAN_LABEL, LabelDescriptor.fromPb(BOOLEAN_LABEL.toPb())); @@ -98,16 +129,16 @@ public void testToAndFromPb() { compareResourceDescriptor(RESOURCE_DESCRIPTOR, MonitoredResourceDescriptor.fromPb(RESOURCE_DESCRIPTOR.toPb())); MonitoredResourceDescriptor resourceDescriptor = - MonitoredResourceDescriptor.builder(TYPE).build(); + MonitoredResourceDescriptor.newBuilder(TYPE).build(); compareResourceDescriptor(resourceDescriptor, MonitoredResourceDescriptor.fromPb(resourceDescriptor.toPb())); } private void compareLabelDescriptor(LabelDescriptor expected, LabelDescriptor value) { assertEquals(expected, value); - assertEquals(expected.key(), value.key()); - assertEquals(expected.valueType(), value.valueType()); - assertEquals(expected.description(), value.description()); + assertEquals(expected.getKey(), value.getKey()); + assertEquals(expected.getValueType(), value.getValueType()); + assertEquals(expected.getDescription(), value.getDescription()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } @@ -115,11 +146,11 @@ private void compareLabelDescriptor(LabelDescriptor expected, LabelDescriptor va private void compareResourceDescriptor(MonitoredResourceDescriptor expected, MonitoredResourceDescriptor value) { assertEquals(expected, value); - assertEquals(expected.type(), value.type()); - assertEquals(expected.name(), value.name()); - assertEquals(expected.displayName(), value.displayName()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.labels(), value.labels()); + assertEquals(expected.getType(), value.getType()); + assertEquals(expected.getName(), value.getName()); + assertEquals(expected.getDisplayName(), value.getDisplayName()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getLabels(), value.getLabels()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java index b42dc0c0f6..845ff035c6 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java @@ -29,21 +29,46 @@ public class MonitoredResourceTest { private static final String TYPE = "cloudsql_database"; private static final Map LABELS = ImmutableMap.of("dataset-id", "myDataset", "zone", "myZone"); - private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.builder(TYPE) - .labels(LABELS) + private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.newBuilder(TYPE) + .setLabels(LABELS) .build(); + private static final MonitoredResource DEPRECATED_MONITORED_RESOURCE = + MonitoredResource.builder(TYPE) + .labels(LABELS) + .build(); @Test public void testBuilder() { - assertEquals(TYPE, MONITORED_RESOURCE.type()); - assertEquals(LABELS, MONITORED_RESOURCE.labels()); + assertEquals(TYPE, MONITORED_RESOURCE.getType()); + assertEquals(LABELS, MONITORED_RESOURCE.getLabels()); + MonitoredResource monitoredResource = MonitoredResource.newBuilder(TYPE) + .addLabel("dataset-id", "myDataset") + .addLabel("zone", "myZone") + .build(); + assertEquals(TYPE, monitoredResource.getType()); + assertEquals(LABELS, monitoredResource.getLabels()); + compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); + monitoredResource = MonitoredResource.newBuilder(TYPE) + .setType("global") + .addLabel("dataset-id", "myDataset") + .addLabel("zone", "myZone") + .clearLabels() + .build(); + assertEquals("global", monitoredResource.getType()); + assertEquals(ImmutableMap.of(), monitoredResource.getLabels()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(TYPE, DEPRECATED_MONITORED_RESOURCE.type()); + assertEquals(LABELS, DEPRECATED_MONITORED_RESOURCE.labels()); MonitoredResource monitoredResource = MonitoredResource.builder(TYPE) .addLabel("dataset-id", "myDataset") .addLabel("zone", "myZone") .build(); assertEquals(TYPE, monitoredResource.type()); assertEquals(LABELS, monitoredResource.labels()); - compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); + compareMonitoredResource(DEPRECATED_MONITORED_RESOURCE, monitoredResource); monitoredResource = MonitoredResource.builder(TYPE) .type("global") .addLabel("dataset-id", "myDataset") @@ -58,14 +83,14 @@ public void testBuilder() { public void testToBuilder() { compareMonitoredResource(MONITORED_RESOURCE, MONITORED_RESOURCE.toBuilder().build()); MonitoredResource monitoredResource = MONITORED_RESOURCE.toBuilder() - .type("global") + .setType("global") .clearLabels() .build(); - assertEquals("global", monitoredResource.type()); - assertEquals(ImmutableMap.of(), monitoredResource.labels()); + assertEquals("global", monitoredResource.getType()); + assertEquals(ImmutableMap.of(), monitoredResource.getLabels()); monitoredResource = monitoredResource.toBuilder() - .type(TYPE) - .labels(ImmutableMap.of("dataset-id", "myDataset")) + .setType(TYPE) + .setLabels(ImmutableMap.of("dataset-id", "myDataset")) .addLabel("zone", "myZone") .build(); compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); @@ -74,8 +99,8 @@ public void testToBuilder() { @Test public void testOf() { MonitoredResource monitoredResource = MonitoredResource.of(TYPE, LABELS); - assertEquals(TYPE, monitoredResource.type()); - assertEquals(LABELS, monitoredResource.labels()); + assertEquals(TYPE, monitoredResource.getType()); + assertEquals(LABELS, monitoredResource.getLabels()); compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); } @@ -90,8 +115,8 @@ public void testToAndFromPb() { private void compareMonitoredResource(MonitoredResource expected, MonitoredResource value) { assertEquals(expected, value); - assertEquals(expected.type(), value.type()); - assertEquals(expected.labels(), value.labels()); + assertEquals(expected.getType(), value.getType()); + assertEquals(expected.getLabels(), value.getLabels()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 13baed858b..ba3194c203 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -46,11 +46,11 @@ public class SerializationTest extends BaseSerializationTest { private static final LabelDescriptor LABEL_DESCRIPTOR = new LabelDescriptor("project_id", ValueType.STRING, "The project id"); private static final MonitoredResourceDescriptor MONITORED_RESOURCE_DESCRIPTOR = - MonitoredResourceDescriptor.builder("global") - .labels(ImmutableList.of(LABEL_DESCRIPTOR)) + MonitoredResourceDescriptor.newBuilder("global") + .setLabels(ImmutableList.of(LABEL_DESCRIPTOR)) .build(); - private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.builder("global") - .labels(ImmutableMap.of("project_id", "project")) + private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.newBuilder("global") + .setLabels(ImmutableMap.of("project_id", "project")) .build(); private static final String JSON_KEY = "{\n" + " \"private_key_id\": \"somekeyid\",\n" From dbfadca48adb48c94392d2c8354a3f52e4dc1d4e Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Fri, 28 Oct 2016 06:48:24 -0700 Subject: [PATCH 231/663] Update spi classes with GAX 0.0.21 (#1326) --- google-cloud-core/pom.xml | 2 +- .../src/main/java/com/google/cloud/GrpcServiceOptions.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e3fb52ed2e..1ea4eb6cce 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -106,7 +106,7 @@ com.google.api gax - 0.0.18 + 0.0.21 com.google.api.grpc diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java index 330a3dff2b..a4991ae312 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java @@ -20,7 +20,7 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.annotations.VisibleForTesting; @@ -226,7 +226,7 @@ protected ExecutorFactory executorFactory() { /** * Returns a builder for API call settings. */ - protected ApiCallSettings.Builder apiCallSettings() { + protected UnaryCallSettings.Builder apiCallSettings() { // todo(mziccard): specify timeout these settings: // retryParams().retryMaxAttempts(), retryParams().retryMinAttempts() final RetrySettings.Builder builder = RetrySettings.newBuilder() @@ -237,7 +237,7 @@ protected ApiCallSettings.Builder apiCallSettings() { .setInitialRetryDelay(Duration.millis(retryParams().initialRetryDelayMillis())) .setRetryDelayMultiplier(retryParams().retryDelayBackoffFactor()) .setMaxRetryDelay(Duration.millis(retryParams().maxRetryDelayMillis())); - return ApiCallSettings.newBuilder().setRetrySettingsBuilder(builder); + return UnaryCallSettings.newBuilder().setRetrySettingsBuilder(builder); } /** From c63063a0d98ccdd348763e43e820265691109b5e Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 28 Oct 2016 22:15:39 +0200 Subject: [PATCH 232/663] Rename setters/getters/builders for core classes to meet proto conventions (#1341) * Rename setters/getters/builders for core classes to meet proto conventions * Update examples, snippets and READMEs to use renamed core getters/setters/builders --- .../main/java/com/google/cloud/AsyncPage.java | 11 +- .../java/com/google/cloud/AsyncPageImpl.java | 20 +- .../com/google/cloud/AuthCredentials.java | 64 +++++- .../java/com/google/cloud/BaseService.java | 12 +- .../google/cloud/BaseServiceException.java | 86 +++++++- .../com/google/cloud/BaseWriteChannel.java | 92 +++++++- .../main/java/com/google/cloud/ByteArray.java | 7 +- .../com/google/cloud/ExceptionHandler.java | 36 +++- .../java/com/google/cloud/FieldSelector.java | 9 +- .../com/google/cloud/GrpcServiceOptions.java | 125 +++++++++-- .../com/google/cloud/HttpServiceOptions.java | 74 ++++++- .../main/java/com/google/cloud/Identity.java | 22 +- .../src/main/java/com/google/cloud/Page.java | 21 +- .../main/java/com/google/cloud/PageImpl.java | 29 ++- .../main/java/com/google/cloud/Policy.java | 101 +++++++-- .../java/com/google/cloud/ReadChannel.java | 7 + .../java/com/google/cloud/RetryHelper.java | 16 +- .../java/com/google/cloud/RetryParams.java | 150 ++++++++++++- .../src/main/java/com/google/cloud/Role.java | 11 +- .../main/java/com/google/cloud/Service.java | 3 + .../google/cloud/ServiceAccountSigner.java | 6 + .../java/com/google/cloud/ServiceOptions.java | 201 ++++++++++++++++-- .../java/com/google/cloud/WaitForOption.java | 28 ++- .../java/com/google/cloud/WriteChannel.java | 7 + .../com/google/cloud/AsyncPageImplTest.java | 102 +++++---- .../com/google/cloud/AuthCredentialsTest.java | 40 ++++ .../cloud/BaseServiceExceptionTest.java | 96 ++++++++- .../google/cloud/BaseWriteChannelTest.java | 38 ++-- .../google/cloud/ExceptionHandlerTest.java | 14 +- .../google/cloud/FieldSelectorHelperTest.java | 15 ++ .../google/cloud/GrpcServiceOptionsTest.java | 86 +++++--- .../google/cloud/HttpServiceOptionsTest.java | 52 +++-- .../java/com/google/cloud/IdentityTest.java | 40 +++- .../java/com/google/cloud/PageImplTest.java | 46 ++-- .../java/com/google/cloud/PolicyTest.java | 105 ++++++--- .../com/google/cloud/RetryHelperTest.java | 123 +++++++++-- .../com/google/cloud/RetryParamsTest.java | 56 ++++- .../test/java/com/google/cloud/RoleTest.java | 18 +- .../com/google/cloud/SerializationTest.java | 6 +- .../com/google/cloud/ServiceOptionsTest.java | 58 +++-- .../com/google/cloud/WaitForOptionTest.java | 19 +- 41 files changed, 1731 insertions(+), 321 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java index 8d7ff026e7..ab836e6e4b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java @@ -34,10 +34,10 @@ *

       {@code
        * AsyncPage page = ...; // get a AsyncPage instance
        * while (page != null) {
      - *   for (T value : page.values()) {
      + *   for (T value : page.getValues()) {
        *     // do something with value
        *   }
      - *   page = page.nextPageAsync().get();
      + *   page = page.getNextPageAsync().get();
        * }}
      * * @param the value type that the page holds @@ -48,5 +48,12 @@ public interface AsyncPage extends Page { * Returns a {@link Future} object for the next page. {@link Future#get()} returns {@code null} if * the last page has been reached. */ + @Deprecated Future> nextPageAsync(); + + /** + * Returns a {@link Future} object for the next page. {@link Future#get()} returns {@code null} if + * the last page has been reached. + */ + Future> getNextPageAsync(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index 706316e362..c5734408d4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -41,7 +41,10 @@ public class AsyncPageImpl extends PageImpl implements AsyncPage { * @param the value type that the page holds */ public interface NextPageFetcher extends Serializable { + @Deprecated Future> nextPage(); + + Future> getNextPage(); } private static class SyncNextPageFetcher implements PageImpl.NextPageFetcher { @@ -56,9 +59,14 @@ private SyncNextPageFetcher(NextPageFetcher asyncPageFetcher) { @Override public Page nextPage() { + return getNextPage(); + } + + @Override + public Page getNextPage() { try { return asyncPageFetcher != null - ? Uninterruptibles.getUninterruptibly(asyncPageFetcher.nextPage()) : null; + ? Uninterruptibles.getUninterruptibly(asyncPageFetcher.getNextPage()) : null; } catch (ExecutionException ex) { throw Throwables.propagate(ex.getCause()); } @@ -74,10 +82,16 @@ public AsyncPageImpl(NextPageFetcher asyncPageFetcher, String cursor, Iterabl } @Override + @Deprecated public Future> nextPageAsync() { - if (nextPageCursor() == null || asyncPageFetcher == null) { + return getNextPageAsync(); + } + + @Override + public Future> getNextPageAsync() { + if (getNextPageCursor() == null || asyncPageFetcher == null) { return Futures.immediateCheckedFuture(null); } - return asyncPageFetcher.nextPage(); + return asyncPageFetcher.getNextPage(); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java index 792831bb9e..257e801c6f 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java @@ -130,6 +130,11 @@ public GoogleCredentials createScoped(Collection scopes) { @Override public String account() { + return getAccount(); + } + + @Override + public String getAccount() { return account; } @@ -166,7 +171,13 @@ public boolean equals(Object obj) { } @Override + @Deprecated public AppEngineCredentials credentials() { + return getCredentials(); + } + + @Override + public AppEngineCredentials getCredentials() { if (credentials == null) { credentials = new AppEngineCredentials(); } @@ -179,13 +190,19 @@ public RestorableState capture() { } @Override + @Deprecated public String account() { - return credentials().account(); + return getAccount(); + } + + @Override + public String getAccount() { + return getCredentials().getAccount(); } @Override public byte[] sign(byte[] toSign) { - return credentials().sign(toSign); + return getCredentials().sign(toSign); } } @@ -247,19 +264,39 @@ public boolean equals(Object obj) { } @Override + @Deprecated public ServiceAccountCredentials credentials() { + return getCredentials(); + } + + @Override + public ServiceAccountCredentials getCredentials() { return credentials; } @Override + @Deprecated public String account() { return account; } + @Override + public String getAccount() { + return account; + } + /** * Returns the private key associated with the service account credentials. */ + @Deprecated public PrivateKey privateKey() { + return getPrivateKey(); + } + + /** + * Returns the private key associated with the service account credentials. + */ + public PrivateKey getPrivateKey() { return privateKey; } @@ -267,7 +304,7 @@ public PrivateKey privateKey() { public byte[] sign(byte[] toSign) { try { Signature signer = Signature.getInstance("SHA256withRSA"); - signer.initSign(privateKey()); + signer.initSign(getPrivateKey()); signer.update(toSign); return signer.sign(); } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException ex) { @@ -331,7 +368,13 @@ public boolean equals(Object obj) { } @Override + @Deprecated public GoogleCredentials credentials() { + return getCredentials(); + } + + @Override + public GoogleCredentials getCredentials() { return googleCredentials; } @@ -392,7 +435,13 @@ public boolean equals(Object obj) { } @Override + @Deprecated public GoogleCredentials credentials() { + return getCredentials(); + } + + @Override + public GoogleCredentials getCredentials() { return credentials; } @@ -436,7 +485,13 @@ public boolean equals(Object obj) { private NoAuthCredentials() {} @Override + @Deprecated public GoogleCredentials credentials() { + return getCredentials(); + } + + @Override + public GoogleCredentials getCredentials() { return null; } @@ -446,8 +501,11 @@ public RestorableState capture() { } } + @Deprecated public abstract GoogleCredentials credentials(); + public abstract GoogleCredentials getCredentials(); + public static AuthCredentials createForAppEngine() { return AppEngineAuthCredentials.INSTANCE; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java index d0476b66c2..f221ade324 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java @@ -38,15 +38,15 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { @Override public RetryResult beforeEval(Exception exception) { if (exception instanceof BaseServiceException) { - boolean retriable = ((BaseServiceException) exception).retryable(); + boolean retriable = ((BaseServiceException) exception).isRetryable(); return retriable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.NO_RETRY; } return Interceptor.RetryResult.CONTINUE_EVALUATION; } }; - public static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.builder() + public static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.newBuilder() .abortOn(RuntimeException.class) - .interceptor(EXCEPTION_HANDLER_INTERCEPTOR) + .addInterceptors(EXCEPTION_HANDLER_INTERCEPTOR) .build(); private final OptionsT options; @@ -56,7 +56,13 @@ protected BaseService(OptionsT options) { } @Override + @Deprecated public OptionsT options() { return options; } + + @Override + public OptionsT getOptions() { + return options; + } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index c22fcfd44a..d892d85b6b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -65,7 +65,15 @@ public Error(Integer code, String reason, boolean rejected) { /** * Returns the code associated with this exception. */ + @Deprecated public Integer code() { + return getCode(); + } + + /** + * Returns the code associated with this exception. + */ + public Integer getCode() { return code; } @@ -74,22 +82,41 @@ public Integer code() { * server. For instance, if the server returns a rate limit exceeded error, it certainly did not * process the request and this method will return {@code true}. */ + @Deprecated public boolean rejected() { + return isRejected(); + } + + /** + * Returns true if the error indicates that the API call was certainly not accepted by the + * server. For instance, if the server returns a rate limit exceeded error, it certainly did not + * process the request and this method will return {@code true}. + */ + public boolean isRejected() { return rejected; } /** * Returns the reason that caused the exception. */ + @Deprecated public String reason() { + return getReason(); + } + + /** + * Returns the reason that caused the exception. + */ + public String getReason() { return reason; } boolean isRetryable(boolean idempotent, Set retryableErrors) { for (Error retryableError : retryableErrors) { - if ((retryableError.code() == null || retryableError.code().equals(this.code())) - && (retryableError.reason() == null || retryableError.reason().equals(this.reason()))) { - return idempotent || retryableError.rejected(); + if ((retryableError.getCode() == null || retryableError.getCode().equals(this.getCode())) + && (retryableError.getReason() == null + || retryableError.getReason().equals(this.getReason()))) { + return idempotent || retryableError.isRejected(); } } return false; @@ -179,12 +206,17 @@ public BaseServiceException(ApiException apiException, boolean idempotent) { this.debugInfo = null; } + @Deprecated protected Set retryableErrors() { + return getRetryableErrors(); + } + + protected Set getRetryableErrors() { return Collections.emptySet(); } protected boolean isRetryable(boolean idempotent, Error error) { - return error.isRetryable(idempotent, retryableErrors()); + return error.isRetryable(idempotent, getRetryableErrors()); } protected boolean isRetryable(boolean idempotent, IOException exception) { @@ -197,28 +229,60 @@ protected boolean isRetryable(boolean idempotent, IOException exception) { /** * Returns the code associated with this exception. */ + @Deprecated public int code() { + return getCode(); + } + + /** + * Returns the code associated with this exception. + */ + public int getCode() { return code; } /** * Returns the reason that caused the exception. */ + @Deprecated public String reason() { + return getReason(); + } + + /** + * Returns the reason that caused the exception. + */ + public String getReason() { return reason; } /** * Returns {@code true} when it is safe to retry the operation that caused this exception. */ + @Deprecated public boolean retryable() { + return isRetryable(); + } + + /** + * Returns {@code true} when it is safe to retry the operation that caused this exception. + */ + public boolean isRetryable() { return retryable; } /** * Returns {@code true} when the operation that caused this exception had no side effects. */ + @Deprecated public boolean idempotent() { + return isIdempotent(); + } + + /** + * Returns {@code true} when the operation that caused this exception had no side effects. + */ + public boolean isIdempotent() { return idempotent; } @@ -226,11 +290,25 @@ public boolean idempotent() { * Returns the service location where the error causing the exception occurred. Returns {@code * null} if not available. */ + @Deprecated public String location() { + return getLocation(); + } + + /** + * Returns the service location where the error causing the exception occurred. Returns {@code + * null} if not available. + */ + public String getLocation() { return location; } + @Deprecated protected String debugInfo() { + return getDebugInfo(); + } + + protected String getDebugInfo() { return debugInfo; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index 038ef8c362..aaef34149f 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -16,7 +16,6 @@ package com.google.cloud; -import com.google.cloud.BaseWriteChannel.BaseState; import com.google.common.base.MoreObjects; import java.io.IOException; @@ -46,56 +45,107 @@ public abstract class BaseWriteChannel< private byte[] buffer = new byte[0]; private int limit; private boolean isOpen = true; - private int chunkSize = defaultChunkSize(); + private int chunkSize = getDefaultChunkSize(); + @Deprecated protected int minChunkSize() { + return getMinChunkSize(); + } + + protected int getMinChunkSize() { return MIN_CHUNK_SIZE; } + @Deprecated protected int defaultChunkSize() { + return getDefaultChunkSize(); + } + + protected int getDefaultChunkSize() { return DEFAULT_CHUNK_SIZE; } /** - * Writes {@code length} bytes of {@link #buffer()} to the {@link #uploadId()} URL. + * Writes {@code length} bytes of {@link #getBuffer()} to the {@link #getUploadId()} URL. * - * @param length the number of bytes to write from {@link #buffer()} + * @param length the number of bytes to write from {@link #getBuffer()} * @param last if {@code true} the resumable session is closed */ protected abstract void flushBuffer(int length, boolean last); + @Deprecated protected ServiceOptionsT options() { return options; } + protected ServiceOptionsT getOptions() { + return options; + } + + @Deprecated protected EntityT entity() { + return getEntity(); + } + + protected EntityT getEntity() { return entity; } + @Deprecated protected String uploadId() { + return getUploadId(); + } + + protected String getUploadId() { return uploadId; } + @Deprecated protected int position() { + return getPosition(); + } + + protected int getPosition() { return position; } + @Deprecated protected byte[] buffer() { + return getBuffer(); + } + + protected byte[] getBuffer() { return buffer; } + @Deprecated protected int limit() { + return getLimit(); + } + + protected int getLimit() { return limit; } + @Deprecated protected int chunkSize() { + return getChunkSize(); + } + + protected int getChunkSize() { return chunkSize; } @Override + @Deprecated public final void chunkSize(int chunkSize) { - chunkSize = (chunkSize / minChunkSize()) * minChunkSize(); - this.chunkSize = Math.max(minChunkSize(), chunkSize); + setChunkSize(chunkSize); + } + + @Override + public final void setChunkSize(int chunkSize) { + chunkSize = (chunkSize / getMinChunkSize()) * getMinChunkSize(); + this.chunkSize = Math.max(getMinChunkSize(), chunkSize); } protected BaseWriteChannel(ServiceOptionsT options, EntityT entity, String uploadId) { @@ -106,7 +156,7 @@ protected BaseWriteChannel(ServiceOptionsT options, EntityT entity, String uploa private void flush() { if (limit >= chunkSize) { - final int length = limit - limit % minChunkSize(); + final int length = limit - limit % getMinChunkSize(); flushBuffer(length, false); position += length; limit -= length; @@ -166,10 +216,10 @@ public RestorableState capture() { bufferToSave = Arrays.copyOf(buffer, limit); } return stateBuilder() - .position(position) - .buffer(bufferToSave) - .isOpen(isOpen) - .chunkSize(chunkSize) + .setPosition(position) + .setBuffer(bufferToSave) + .setIsOpen(isOpen) + .setChunkSize(chunkSize) .build(); } @@ -235,22 +285,42 @@ protected Builder(ServiceOptionsT options, EntityT entity, String uploadId) { this.uploadId = uploadId; } + @Deprecated public Builder position(int position) { + return setPosition(position); + } + + public Builder setPosition(int position) { this.position = position; return this; } + @Deprecated public Builder buffer(byte[] buffer) { + return setBuffer(buffer); + } + + public Builder setBuffer(byte[] buffer) { this.buffer = buffer; return this; } + @Deprecated public Builder isOpen(boolean isOpen) { + return setIsOpen(isOpen); + } + + public Builder setIsOpen(boolean isOpen) { this.isOpen = isOpen; return this; } + @Deprecated public Builder chunkSize(int chunkSize) { + return setChunkSize(chunkSize); + } + + public Builder setChunkSize(int chunkSize) { this.chunkSize = chunkSize; return this; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java index 3a23a17ba4..0c719fb18d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -41,7 +41,7 @@ protected ByteArray(ByteString byteString) { } protected ByteArray(ByteArray byteArray) { - this.byteString = byteArray.byteString(); + this.byteString = byteArray.getByteString(); } @Override @@ -108,7 +108,12 @@ public final InputStream asInputStream() { return byteString.newInput(); } + @Deprecated protected ByteString byteString() { + return getByteString(); + } + + protected ByteString getByteString() { return byteString; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java index e72eb1edcf..91534885a1 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java @@ -38,7 +38,7 @@ public final class ExceptionHandler implements Serializable { private static final long serialVersionUID = -2460707015779532919L; private static final ExceptionHandler DEFAULT_INSTANCE = - builder().retryOn(Exception.class).abortOn(RuntimeException.class).build(); + newBuilder().retryOn(Exception.class).abortOn(RuntimeException.class).build(); private final ImmutableList interceptors; private final ImmutableSet> retriableExceptions; @@ -93,7 +93,18 @@ private Builder() {} * @param interceptors the interceptors for this exception handler * @return the Builder for chaining */ + @Deprecated public Builder interceptor(Interceptor... interceptors) { + return addInterceptors(interceptors); + } + + /** + * Adds the exception handler interceptors. Call order will be maintained. + * + * @param interceptors the interceptors for this exception handler + * @return the Builder for chaining + */ + public Builder addInterceptors(Interceptor... interceptors) { for (Interceptor interceptor : interceptors) { this.interceptors.add(interceptor); } @@ -232,14 +243,24 @@ void verifyCaller(Callable callable) { } } + @Deprecated public Set> retriableExceptions() { + return getRetriableExceptions(); + } + + public Set> getRetriableExceptions() { return retriableExceptions; } + @Deprecated public Set> nonRetriableExceptions() { return nonRetriableExceptions; } + public Set> getNonRetriableExceptions() { + return nonRetriableExceptions; + } + boolean shouldRetry(Exception ex) { for (Interceptor interceptor : interceptors) { Interceptor.RetryResult retryResult = checkNotNull(interceptor.beforeEval(ex)); @@ -283,11 +304,24 @@ public boolean equals(Object obj) { /** * Returns an instance which retry any checked exception and abort on any runtime exception. */ + @Deprecated public static ExceptionHandler defaultInstance() { + return getDefaultInstance(); + } + + /** + * Returns an instance which retry any checked exception and abort on any runtime exception. + */ + public static ExceptionHandler getDefaultInstance() { return DEFAULT_INSTANCE; } + @Deprecated public static Builder builder() { + return newBuilder(); + } + + public static Builder newBuilder() { return new Builder(); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java index 5a46d05864..37190a3c2e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java +++ b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java @@ -35,8 +35,15 @@ public interface FieldSelector { * Returns a string selector. This selector is passed to a Google Cloud service (possibly with * other field selectors) to specify which resource fields should be returned by an API call. */ + @Deprecated String selector(); + /** + * Returns a string selector. This selector is passed to a Google Cloud service (possibly with + * other field selectors) to specify which resource fields should be returned by an API call. + */ + String getSelector(); + /** * A helper class used to build composite selectors given a number of fields. This class is not * supposed to be used directly by users. @@ -51,7 +58,7 @@ private Helper() {} new Function() { @Override public String apply(FieldSelector fieldSelector) { - return fieldSelector.selector(); + return fieldSelector.getSelector(); } }; diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java index a4991ae312..e0017e0919 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java @@ -158,19 +158,42 @@ protected Builder(GrpcServiceOptions options) { * * @return the builder */ + @Deprecated public B executorFactory(ExecutorFactory executorFactory) { + return setExecutorFactory(executorFactory); + } + + /** + * Sets the scheduled executor factory. This method can be used to provide an user-defined + * scheduled executor to execute requests. + * + * @return the builder + */ + public B setExecutorFactory(ExecutorFactory executorFactory) { this.executorFactory = executorFactory; return self(); } /** * Sets the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value - * adjusted according to {@link #timeoutMultiplier(double)}. Default value is 20000. + * adjusted according to {@link #setTimeoutMultiplier(double)}. Default value is 20000. * * @return the builder * @throws IllegalArgumentException if the provided timeout is < 0 */ + @Deprecated public B initialTimeout(int initialTimeout) { + return setInitialTimeout(initialTimeout); + } + + /** + * Sets the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value + * adjusted according to {@link #setTimeoutMultiplier(double)}. Default value is 20000. + * + * @return the builder + * @throws IllegalArgumentException if the provided timeout is < 0 + */ + public B setInitialTimeout(int initialTimeout) { Preconditions.checkArgument(initialTimeout > 0, "Initial timeout must be > 0"); this.initialTimeout = initialTimeout; return self(); @@ -183,7 +206,19 @@ public B initialTimeout(int initialTimeout) { * @return the builder * @throws IllegalArgumentException if the provided timeout multiplier is < 0 */ + @Deprecated public B timeoutMultiplier(double timeoutMultiplier) { + return setTimeoutMultiplier(timeoutMultiplier); + } + + /** + * Sets the timeout multiplier. This value is used to compute the timeout for a retried RPC. + * Timeout is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. + * + * @return the builder + * @throws IllegalArgumentException if the provided timeout multiplier is < 0 + */ + public B setTimeoutMultiplier(double timeoutMultiplier) { Preconditions.checkArgument(timeoutMultiplier >= 1.0, "Timeout multiplier must be >= 1"); this.timeoutMultiplier = timeoutMultiplier; return self(); @@ -191,12 +226,24 @@ public B timeoutMultiplier(double timeoutMultiplier) { /** * Sets the maximum timeout for a RPC call, in milliseconds. Default value is 100000. If - * {@code maxTimeout} is lower than the initial timeout the {@link #initialTimeout(int)} value - * is used instead. + * {@code maxTimeout} is lower than the initial timeout the {@link #setInitialTimeout(int)} + * value is used instead. * * @return the builder */ + @Deprecated public B maxTimeout(int maxTimeout) { + return setMaxTimeout(maxTimeout); + } + + /** + * Sets the maximum timeout for a RPC call, in milliseconds. Default value is 100000. If + * {@code maxTimeout} is lower than the initial timeout the {@link #setInitialTimeout(int)} + * value is used instead. + * + * @return the builder + */ + public B setMaxTimeout(int maxTimeout) { this.maxTimeout = maxTimeout; return self(); } @@ -219,47 +266,80 @@ protected GrpcServiceOptions( /** * Returns a scheduled executor service provider. */ + @Deprecated protected ExecutorFactory executorFactory() { + return getExecutorFactory(); + } + + /** + * Returns a scheduled executor service provider. + */ + protected ExecutorFactory getExecutorFactory() { return executorFactory; } /** * Returns a builder for API call settings. */ + @Deprecated protected UnaryCallSettings.Builder apiCallSettings() { + return getApiCallSettings(); + } + + /** + * Returns a builder for API call settings. + */ + protected UnaryCallSettings.Builder getApiCallSettings() { // todo(mziccard): specify timeout these settings: // retryParams().retryMaxAttempts(), retryParams().retryMinAttempts() final RetrySettings.Builder builder = RetrySettings.newBuilder() - .setTotalTimeout(Duration.millis(retryParams().totalRetryPeriodMillis())) - .setInitialRpcTimeout(Duration.millis(initialTimeout())) - .setRpcTimeoutMultiplier(timeoutMultiplier()) - .setMaxRpcTimeout(Duration.millis(maxTimeout())) - .setInitialRetryDelay(Duration.millis(retryParams().initialRetryDelayMillis())) - .setRetryDelayMultiplier(retryParams().retryDelayBackoffFactor()) - .setMaxRetryDelay(Duration.millis(retryParams().maxRetryDelayMillis())); + .setTotalTimeout(Duration.millis(getRetryParams().getTotalRetryPeriodMillis())) + .setInitialRpcTimeout(Duration.millis(getInitialTimeout())) + .setRpcTimeoutMultiplier(getTimeoutMultiplier()) + .setMaxRpcTimeout(Duration.millis(getMaxTimeout())) + .setInitialRetryDelay(Duration.millis(getRetryParams().getInitialRetryDelayMillis())) + .setRetryDelayMultiplier(getRetryParams().getRetryDelayBackoffFactor()) + .setMaxRetryDelay(Duration.millis(getRetryParams().getMaxRetryDelayMillis())); return UnaryCallSettings.newBuilder().setRetrySettingsBuilder(builder); } /** * Returns a builder for connection-related settings. */ + @Deprecated protected ConnectionSettings.Builder connectionSettings() { - HostAndPort hostAndPort = HostAndPort.fromString(host()); + return getConnectionSettings(); + } + + /** + * Returns a builder for connection-related settings. + */ + protected ConnectionSettings.Builder getConnectionSettings() { + HostAndPort hostAndPort = HostAndPort.fromString(getHost()); ConnectionSettings.Builder builder = ConnectionSettings.newBuilder() .setServiceAddress(hostAndPort.getHostText()) .setPort(hostAndPort.getPort()); - GoogleCredentials credentials = authCredentials().credentials(); + GoogleCredentials credentials = getAuthCredentials().getCredentials(); if (credentials != null) { - builder.provideCredentialsWith(credentials.createScoped(scopes())); + builder.provideCredentialsWith(credentials.createScoped(getScopes())); } return builder; } /** * Returns the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value - * adjusted according to {@link #timeoutMultiplier()}. Default value is 20000. + * adjusted according to {@link #getTimeoutMultiplier()}. Default value is 20000. */ + @Deprecated public int initialTimeout() { + return getInitialTimeout(); + } + + /** + * Returns the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value + * adjusted according to {@link #getTimeoutMultiplier()}. Default value is 20000. + */ + public int getInitialTimeout() { return initialTimeout; } @@ -267,14 +347,31 @@ public int initialTimeout() { * Returns the timeout multiplier. This values is used to compute the timeout for a RPC. Timeout * is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. */ + @Deprecated public double timeoutMultiplier() { + return getTimeoutMultiplier(); + } + + /** + * Returns the timeout multiplier. This values is used to compute the timeout for a RPC. Timeout + * is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. + */ + public double getTimeoutMultiplier() { return timeoutMultiplier; } /** * Returns the maximum timeout for a RPC call, in milliseconds. Default value is 100000. */ + @Deprecated public int maxTimeout() { + return getMaxTimeout(); + } + + /** + * Returns the maximum timeout for a RPC call, in milliseconds. Default value is 100000. + */ + public int getMaxTimeout() { return maxTimeout; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java index eca411849e..9e49d537f3 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java @@ -116,7 +116,17 @@ protected B self() { * * @return the builder */ + @Deprecated public B httpTransportFactory(HttpTransportFactory httpTransportFactory) { + return setHttpTransportFactory(httpTransportFactory); + } + + /** + * Sets the HTTP transport factory. + * + * @return the builder + */ + public B setHttpTransportFactory(HttpTransportFactory httpTransportFactory) { this.httpTransportFactory = httpTransportFactory; return self(); } @@ -128,7 +138,19 @@ public B httpTransportFactory(HttpTransportFactory httpTransportFactory) { * negative number for the default value (20000). * @return the builder */ + @Deprecated public B connectTimeout(int connectTimeout) { + return setConnectTimeout(connectTimeout); + } + + /** + * Sets the timeout in milliseconds to establish a connection. + * + * @param connectTimeout connection timeout in milliseconds. 0 for an infinite timeout, a + * negative number for the default value (20000). + * @return the builder + */ + public B setConnectTimeout(int connectTimeout) { this.connectTimeout = connectTimeout; return self(); } @@ -140,7 +162,19 @@ public B connectTimeout(int connectTimeout) { * for the default value (20000). * @return the builder */ + @Deprecated public B readTimeout(int readTimeout) { + return setReadTimeout(readTimeout); + } + + /** + * Sets the timeout in milliseconds to read data from an established connection. + * + * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a negative number + * for the default value (20000). + * @return the builder + */ + public B setReadTimeout(int readTimeout) { this.readTimeout = readTimeout; return self(); } @@ -161,19 +195,36 @@ protected HttpServiceOptions( /** * Returns the HTTP transport factory. */ + @Deprecated public HttpTransportFactory httpTransportFactory() { - return httpTransportFactory; + return getHttpTransportFactory(); } + /** + * Returns the HTTP transport factory. + */ + public HttpTransportFactory getHttpTransportFactory() { + return httpTransportFactory; + } /** * Returns a request initializer responsible for initializing requests according to service * options. */ + @Deprecated public HttpRequestInitializer httpRequestInitializer() { + return getHttpRequestInitializer(); + } + + /** + * Returns a request initializer responsible for initializing requests according to service + * options. + */ + public HttpRequestInitializer getHttpRequestInitializer() { final HttpRequestInitializer delegate = - authCredentials() != null && authCredentials().credentials() != null - ? new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes())) + getAuthCredentials() != null && getAuthCredentials().getCredentials() != null + ? new HttpCredentialsAdapter( + getAuthCredentials().getCredentials().createScoped(getScopes())) : null; return new HttpRequestInitializer() { @Override @@ -196,6 +247,14 @@ public void initialize(HttpRequest httpRequest) throws IOException { * negative number is the default value (20000). */ public int connectTimeout() { + return getConnectTimeout(); + } + + /** + * Returns the timeout in milliseconds to establish a connection. 0 is an infinite timeout, a + * negative number is the default value (20000). + */ + public int getConnectTimeout() { return connectTimeout; } @@ -203,7 +262,16 @@ public int connectTimeout() { * Returns the timeout in milliseconds to read from an established connection. 0 is an infinite * timeout, a negative number is the default value (20000). */ + @Deprecated public int readTimeout() { + return getReadTimeout(); + } + + /** + * Returns the timeout in milliseconds to read from an established connection. 0 is an infinite + * timeout, a negative number is the default value (20000). + */ + public int getReadTimeout() { return readTimeout; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/Identity.java b/google-cloud-core/src/main/java/com/google/cloud/Identity.java index 783e99f796..c82005a38d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Identity.java @@ -86,7 +86,12 @@ private Identity(Type type, String value) { this.value = value; } + @Deprecated public Type type() { + return getType(); + } + + public Type getType() { return type; } @@ -100,7 +105,22 @@ public Type type() { * {@code ALL_AUTHENTICATED_USERS}) *
    */ + @Deprecated public String value() { + return getValue(); + } + + /** + * Returns the string identifier for this identity. The value corresponds to: + *
      + *
    • email address (for identities of type {@code USER}, {@code SERVICE_ACCOUNT}, and + * {@code GROUP}) + *
    • domain (for identities of type {@code DOMAIN}) + *
    • {@code null} (for identities of type {@code ALL_USERS} and + * {@code ALL_AUTHENTICATED_USERS}) + *
    + */ + public String getValue() { return value; } @@ -176,7 +196,7 @@ public boolean equals(Object obj) { return false; } Identity other = (Identity) obj; - return Objects.equals(value, other.value()) && Objects.equals(type, other.type()); + return Objects.equals(value, other.getValue()) && Objects.equals(type, other.getType()); } /** diff --git a/google-cloud-core/src/main/java/com/google/cloud/Page.java b/google-cloud-core/src/main/java/com/google/cloud/Page.java index 8881a98b46..dde285e3aa 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Page.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Page.java @@ -34,10 +34,10 @@ *
     {@code
      * Page page = ...; // get a Page instance
      * while (page != null) {
    - *   for (T value : page.values()) {
    + *   for (T value : page.getValues()) {
      *     // do something with value
      *   }
    - *   page = page.nextPage();
    + *   page = page.getNextPage();
      * }}
    * * @param the value type that the page holds @@ -47,8 +47,14 @@ public interface Page { /** * Returns the values contained in this page. */ + @Deprecated Iterable values(); + /** + * Returns the values contained in this page. + */ + Iterable getValues(); + /** * Returns an iterator for all values, possibly also in the next pages. Once current page's values * are traversed the iterator fetches next page, if any. @@ -58,11 +64,22 @@ public interface Page { /** * Returns the cursor for the nextPage or {@code null} if no more results. */ + @Deprecated String nextPageCursor(); + /** + * Returns the cursor for the nextPage or {@code null} if no more results. + */ + String getNextPageCursor(); + /** * Returns the next page of results or {@code null} if no more result. */ + @Deprecated Page nextPage(); + /** + * Returns the next page of results or {@code null} if no more result. + */ + Page getNextPage(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java index de1a3506b7..99c675dea3 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java @@ -44,7 +44,10 @@ public class PageImpl implements Page, Serializable { * @param the value type that the page holds */ public interface NextPageFetcher extends Serializable { + @Deprecated Page nextPage(); + + Page getNextPage(); } static class PageIterator extends AbstractIterator { @@ -53,18 +56,18 @@ static class PageIterator extends AbstractIterator { private Page currentPage; PageIterator(Page currentPage) { - this.currentPageIterator = currentPage.values().iterator(); + this.currentPageIterator = currentPage.getValues().iterator(); this.currentPage = currentPage; } @Override protected T computeNext() { while (!currentPageIterator.hasNext()) { - currentPage = currentPage.nextPage(); + currentPage = currentPage.getNextPage(); if (currentPage == null) { return endOfData(); } - currentPageIterator = currentPage.values().iterator(); + currentPageIterator = currentPage.getValues().iterator(); } return currentPageIterator.next(); } @@ -81,7 +84,13 @@ public PageImpl(NextPageFetcher pageFetcher, String cursor, Iterable resul } @Override + @Deprecated public Iterable values() { + return getValues(); + } + + @Override + public Iterable getValues() { return results == null ? Collections.emptyList() : results; } @@ -91,16 +100,28 @@ public Iterator iterateAll() { } @Override + @Deprecated public String nextPageCursor() { + return getNextPageCursor(); + } + + @Override + public String getNextPageCursor() { return cursor; } @Override + @Deprecated public Page nextPage() { + return getNextPage(); + } + + @Override + public Page getNextPage() { if (cursor == null || pageFetcher == null) { return null; } - return pageFetcher.nextPage(); + return pageFetcher.getNextPage(); } @Override diff --git a/google-cloud-core/src/main/java/com/google/cloud/Policy.java b/google-cloud-core/src/main/java/com/google/cloud/Policy.java index 2a8009d403..4307f1dffd 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Policy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Policy.java @@ -87,11 +87,11 @@ protected Policy fromPb(com.google.iam.v1.Policy policyPb) { ImmutableSet.copyOf( Lists.transform(bindingPb.getMembersList(), IDENTITY_VALUE_OF_FUNCTION))); } - return builder() - .bindings(bindings) - .etag(policyPb.getEtag().isEmpty() ? null + return newBuilder() + .setBindings(bindings) + .setEtag(policyPb.getEtag().isEmpty() ? null : BaseEncoding.base64().encode(policyPb.getEtag().toByteArray())) - .version(policyPb.getVersion()) + .setVersion(policyPb.getVersion()) .build(); } @@ -99,9 +99,9 @@ protected Policy fromPb(com.google.iam.v1.Policy policyPb) { protected com.google.iam.v1.Policy toPb(Policy policy) { com.google.iam.v1.Policy.Builder policyBuilder = com.google.iam.v1.Policy.newBuilder(); List bindingPbList = new LinkedList<>(); - for (Map.Entry> binding : policy.bindings().entrySet()) { + for (Map.Entry> binding : policy.getBindings().entrySet()) { com.google.iam.v1.Binding.Builder bindingBuilder = com.google.iam.v1.Binding.newBuilder(); - bindingBuilder.setRole(binding.getKey().value()); + bindingBuilder.setRole(binding.getKey().getValue()); bindingBuilder.addAllMembers( Lists.transform(new ArrayList<>(binding.getValue()), IDENTITY_STR_VALUE_FUNCTION)); bindingPbList.add(bindingBuilder.build()); @@ -127,9 +127,9 @@ public static class Builder { protected Builder() {} protected Builder(Policy policy) { - bindings(policy.bindings); - etag(policy.etag); - version(policy.version); + setBindings(policy.bindings); + setEtag(policy.etag); + setVersion(policy.version); } /** @@ -138,7 +138,18 @@ protected Builder(Policy policy) { * @throws NullPointerException if the given map is null or contains any null keys or values * @throws IllegalArgumentException if any identities in the given map are null */ + @Deprecated public final Builder bindings(Map> bindings) { + return setBindings(bindings); + } + + /** + * Replaces the builder's map of bindings with the given map of bindings. + * + * @throws NullPointerException if the given map is null or contains any null keys or values + * @throws IllegalArgumentException if any identities in the given map are null + */ + public final Builder setBindings(Map> bindings) { checkNotNull(bindings, "The provided map of bindings cannot be null."); for (Map.Entry> binding : bindings.entrySet()) { checkNotNull(binding.getKey(), "The role cannot be null."); @@ -212,7 +223,23 @@ public final Builder removeIdentity(Role role, Identity first, Identity... other * applied to the same version of the policy. If no etag is provided in the call to * setIamPolicy, then the existing policy is overwritten blindly. */ + @Deprecated protected final Builder etag(String etag) { + return setEtag(etag); + } + + /** + * Sets the policy's etag. + * + *

    Etags are used for optimistic concurrency control as a way to help prevent simultaneous + * updates of a policy from overwriting each other. It is strongly suggested that systems make + * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid + * race conditions. An etag is returned in the response to getIamPolicy, and systems are + * expected to put that etag in the request to setIamPolicy to ensure that their change will be + * applied to the same version of the policy. If no etag is provided in the call to + * setIamPolicy, then the existing policy is overwritten blindly. + */ + protected final Builder setEtag(String etag) { this.etag = etag; return this; } @@ -221,7 +248,16 @@ protected final Builder etag(String etag) { * Sets the version of the policy. The default version is 0, meaning only the "owner", "editor", * and "viewer" roles are permitted. If the version is 1, you may also use other roles. */ + @Deprecated protected final Builder version(int version) { + return setVersion(version); + } + + /** + * Sets the version of the policy. The default version is 0, meaning only the "owner", "editor", + * and "viewer" roles are permitted. If the version is 1, you may also use other roles. + */ + protected final Builder setVersion(int version) { this.version = version; return this; } @@ -254,7 +290,15 @@ public Builder toBuilder() { /** * Returns the map of bindings that comprises the policy. */ + @Deprecated public Map> bindings() { + return getBindings(); + } + + /** + * Returns the map of bindings that comprises the policy. + */ + public Map> getBindings() { return bindings; } @@ -269,7 +313,23 @@ public Map> bindings() { * applied to the same version of the policy. If no etag is provided in the call to * setIamPolicy, then the existing policy is overwritten blindly. */ + @Deprecated public String etag() { + return getEtag(); + } + + /** + * Returns the policy's etag. + * + *

    Etags are used for optimistic concurrency control as a way to help prevent simultaneous + * updates of a policy from overwriting each other. It is strongly suggested that systems make + * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid + * race conditions. An etag is returned in the response to getIamPolicy, and systems are + * expected to put that etag in the request to setIamPolicy to ensure that their change will be + * applied to the same version of the policy. If no etag is provided in the call to + * setIamPolicy, then the existing policy is overwritten blindly. + */ + public String getEtag() { return etag; } @@ -277,7 +337,16 @@ public String etag() { * Returns the version of the policy. The default version is 0, meaning only the "owner", * "editor", and "viewer" roles are permitted. If the version is 1, you may also use other roles. */ + @Deprecated public int version() { + return getVersion(); + } + + /** + * Returns the version of the policy. The default version is 0, meaning only the "owner", + * "editor", and "viewer" roles are permitted. If the version is 1, you may also use other roles. + */ + public int getVersion() { return version; } @@ -304,15 +373,23 @@ public boolean equals(Object obj) { return false; } Policy other = (Policy) obj; - return Objects.equals(bindings, other.bindings()) - && Objects.equals(etag, other.etag()) - && Objects.equals(version, other.version()); + return Objects.equals(bindings, other.getBindings()) + && Objects.equals(etag, other.getEtag()) + && Objects.equals(version, other.getVersion()); } /** * Returns a builder for {@code Policy} objects. */ + @Deprecated public static Builder builder() { + return newBuilder(); + } + + /** + * Returns a builder for {@code Policy} objects. + */ + public static Builder newBuilder() { return new Builder(); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java index 1ac45902b2..a097526928 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java @@ -44,8 +44,15 @@ public interface ReadChannel extends ReadableByteChannel, Closeable, Restorable< * Sets the minimum size that will be read by a single RPC. * Read data will be locally buffered until consumed. */ + @Deprecated void chunkSize(int chunkSize); + /** + * Sets the minimum size that will be read by a single RPC. + * Read data will be locally buffered until consumed. + */ + void setChunkSize(int chunkSize); + /** * Captures the read channel state so that it can be saved and restored afterwards. * diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index bd59070d47..b23a516cca 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -192,9 +192,9 @@ private V doRetry() throws RetryHelperException { } exception = e; } - if (attemptNumber >= params.retryMaxAttempts() - || attemptNumber >= params.retryMinAttempts() - && clock.millis() - start >= params.totalRetryPeriodMillis()) { + if (attemptNumber >= params.getRetryMaxAttempts() + || attemptNumber >= params.getRetryMinAttempts() + && clock.millis() - start >= params.getTotalRetryPeriodMillis()) { throw new RetriesExhaustedException(this + ": Too many failures, giving up", exception); } long sleepDurationMillis = getSleepDuration(params, attemptNumber); @@ -213,9 +213,9 @@ private V doRetry() throws RetryHelperException { @VisibleForTesting static long getSleepDuration(RetryParams retryParams, int attemptsSoFar) { - long initialDelay = retryParams.initialRetryDelayMillis(); - double backoffFactor = retryParams.retryDelayBackoffFactor(); - long maxDelay = retryParams.maxRetryDelayMillis(); + long initialDelay = retryParams.getInitialRetryDelayMillis(); + double backoffFactor = retryParams.getRetryDelayBackoffFactor(); + long maxDelay = retryParams.getMaxRetryDelayMillis(); long retryDelay = getExponentialValue(initialDelay, backoffFactor, maxDelay, attemptsSoFar); return (long) ((random() / 2.0 + .75) * retryDelay); } @@ -226,8 +226,8 @@ private static long getExponentialValue(long initialDelay, double backoffFactor, } public static V runWithRetries(Callable callable) throws RetryHelperException { - return runWithRetries(callable, RetryParams.defaultInstance(), - ExceptionHandler.defaultInstance()); + return runWithRetries(callable, RetryParams.getDefaultInstance(), + ExceptionHandler.getDefaultInstance()); } public static V runWithRetries(Callable callable, RetryParams params, diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java b/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java index 02ffda1813..e835ad5d3c 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java @@ -38,8 +38,8 @@ * {@code RetryParams}, first create a {@link RetryParams.Builder}. The builder is mutable and each * of the parameters can be set (any unset parameters will fallback to the defaults). The * {@code Builder} can be then used to create an immutable {@code RetryParams} object. For default - * {@code RetryParams} use {@link #defaultInstance}. Default settings are subject to change release - * to release. If you require specific settings, explicitly create an instance of + * {@code RetryParams} use {@link #getDefaultInstance}. Default settings are subject to change + * release to release. If you require specific settings, explicitly create an instance of * {@code RetryParams} with all the required settings. * * @see RetryHelper @@ -71,7 +71,7 @@ public final class RetryParams implements Serializable { // requirement differs from the default parameters used here. private static final RetryParams DEFAULT_INSTANCE = new RetryParams(new Builder()); private static final RetryParams NO_RETRIES = - builder().retryMaxAttempts(1).retryMinAttempts(1).build(); + newBuilder().setRetryMaxAttempts(1).setRetryMinAttempts(1).build(); /** * RetryParams builder. @@ -98,12 +98,12 @@ private Builder() { retryDelayBackoffFactor = DEFAULT_RETRY_DELAY_BACKOFF_FACTOR; totalRetryPeriodMillis = DEFAULT_TOTAL_RETRY_PERIOD_MILLIS; } else { - retryMinAttempts = retryParams.retryMinAttempts(); - retryMaxAttempts = retryParams.retryMaxAttempts(); - initialRetryDelayMillis = retryParams.initialRetryDelayMillis(); - maxRetryDelayMillis = retryParams.maxRetryDelayMillis(); - retryDelayBackoffFactor = retryParams.retryDelayBackoffFactor(); - totalRetryPeriodMillis = retryParams.totalRetryPeriodMillis(); + retryMinAttempts = retryParams.getRetryMinAttempts(); + retryMaxAttempts = retryParams.getRetryMaxAttempts(); + initialRetryDelayMillis = retryParams.getInitialRetryDelayMillis(); + maxRetryDelayMillis = retryParams.getMaxRetryDelayMillis(); + retryDelayBackoffFactor = retryParams.getRetryDelayBackoffFactor(); + totalRetryPeriodMillis = retryParams.getTotalRetryPeriodMillis(); } } @@ -113,7 +113,18 @@ private Builder() { * @param retryMinAttempts the retryMinAttempts to set * @return the Builder for chaining */ + @Deprecated public Builder retryMinAttempts(int retryMinAttempts) { + return setRetryMinAttempts(retryMinAttempts); + } + + /** + * Sets retryMinAttempts. + * + * @param retryMinAttempts the retryMinAttempts to set + * @return the Builder for chaining + */ + public Builder setRetryMinAttempts(int retryMinAttempts) { this.retryMinAttempts = retryMinAttempts; return this; } @@ -124,7 +135,18 @@ public Builder retryMinAttempts(int retryMinAttempts) { * @param retryMaxAttempts the retryMaxAttempts to set * @return the Builder for chaining */ + @Deprecated public Builder retryMaxAttempts(int retryMaxAttempts) { + return setRetryMaxAttempts(retryMaxAttempts); + } + + /** + * Sets retryMaxAttempts. + * + * @param retryMaxAttempts the retryMaxAttempts to set + * @return the Builder for chaining + */ + public Builder setRetryMaxAttempts(int retryMaxAttempts) { this.retryMaxAttempts = retryMaxAttempts; return this; } @@ -135,7 +157,18 @@ public Builder retryMaxAttempts(int retryMaxAttempts) { * @param initialRetryDelayMillis the initialRetryDelayMillis to set * @return the Builder for chaining */ + @Deprecated public Builder initialRetryDelayMillis(long initialRetryDelayMillis) { + return setInitialRetryDelayMillis(initialRetryDelayMillis); + } + + /** + * Sets initialRetryDelayMillis. + * + * @param initialRetryDelayMillis the initialRetryDelayMillis to set + * @return the Builder for chaining + */ + public Builder setInitialRetryDelayMillis(long initialRetryDelayMillis) { this.initialRetryDelayMillis = initialRetryDelayMillis; return this; } @@ -146,7 +179,18 @@ public Builder initialRetryDelayMillis(long initialRetryDelayMillis) { * @param maxRetryDelayMillis the maxRetryDelayMillis to set * @return the Builder for chaining */ + @Deprecated public Builder maxRetryDelayMillis(long maxRetryDelayMillis) { + return setMaxRetryDelayMillis(maxRetryDelayMillis); + } + + /** + * Sets maxRetryDelayMillis. + * + * @param maxRetryDelayMillis the maxRetryDelayMillis to set + * @return the Builder for chaining + */ + public Builder setMaxRetryDelayMillis(long maxRetryDelayMillis) { this.maxRetryDelayMillis = maxRetryDelayMillis; return this; } @@ -157,7 +201,18 @@ public Builder maxRetryDelayMillis(long maxRetryDelayMillis) { * @param retryDelayBackoffFactor the retryDelayBackoffFactor to set * @return the Builder for chaining */ + @Deprecated public Builder retryDelayBackoffFactor(double retryDelayBackoffFactor) { + return setRetryDelayBackoffFactor(retryDelayBackoffFactor); + } + + /** + * Sets retryDelayBackoffFactor. + * + * @param retryDelayBackoffFactor the retryDelayBackoffFactor to set + * @return the Builder for chaining + */ + public Builder setRetryDelayBackoffFactor(double retryDelayBackoffFactor) { this.retryDelayBackoffFactor = retryDelayBackoffFactor; return this; } @@ -170,7 +225,20 @@ public Builder retryDelayBackoffFactor(double retryDelayBackoffFactor) { * @param totalRetryPeriodMillis the totalRetryPeriodMillis to set * @return the Builder for chaining */ + @Deprecated public Builder totalRetryPeriodMillis(long totalRetryPeriodMillis) { + return setTotalRetryPeriodMillis(totalRetryPeriodMillis); + } + + /** + * Sets totalRetryPeriodMillis. Note that App Engine Standard Environment front-end modules have + * a 60 second deadline for HTTP requests. For that reason, you should set the total retry + * period to under 60 seconds if you are using it on an App Engine front-end module. + * + * @param totalRetryPeriodMillis the totalRetryPeriodMillis to set + * @return the Builder for chaining + */ + public Builder setTotalRetryPeriodMillis(long totalRetryPeriodMillis) { this.totalRetryPeriodMillis = totalRetryPeriodMillis; return this; } @@ -210,7 +278,15 @@ private RetryParams(Builder builder) { /** * Returns an instance with the default parameters. */ + @Deprecated public static RetryParams defaultInstance() { + return getDefaultInstance(); + } + + /** + * Returns an instance with the default parameters. + */ + public static RetryParams getDefaultInstance() { return DEFAULT_INSTANCE; } @@ -225,14 +301,30 @@ public static RetryParams noRetries() { /** * Returns the retryMinAttempts. Default value is {@value #DEFAULT_RETRY_MIN_ATTEMPTS}. */ + @Deprecated public int retryMinAttempts() { + return getRetryMinAttempts(); + } + + /** + * Returns the retryMinAttempts. Default value is {@value #DEFAULT_RETRY_MIN_ATTEMPTS}. + */ + public int getRetryMinAttempts() { return retryMinAttempts; } /** * Returns the retryMaxAttempts. Default value is {@value #DEFAULT_RETRY_MAX_ATTEMPTS}. */ + @Deprecated public int retryMaxAttempts() { + return getRetryMaxAttempts(); + } + + /** + * Returns the retryMaxAttempts. Default value is {@value #DEFAULT_RETRY_MAX_ATTEMPTS}. + */ + public int getRetryMaxAttempts() { return retryMaxAttempts; } @@ -240,14 +332,31 @@ public int retryMaxAttempts() { * Returns the initialRetryDelayMillis. Default value is * {@value #DEFAULT_INITIAL_RETRY_DELAY_MILLIS}. */ + @Deprecated public long initialRetryDelayMillis() { + return getInitialRetryDelayMillis(); + } + + /** + * Returns the initialRetryDelayMillis. Default value is + * {@value #DEFAULT_INITIAL_RETRY_DELAY_MILLIS}. + */ + public long getInitialRetryDelayMillis() { return initialRetryDelayMillis; } /** * Returns the maxRetryDelayMillis. Default values is {@value #DEFAULT_MAX_RETRY_DELAY_MILLIS}. */ + @Deprecated public long maxRetryDelayMillis() { + return getMaxRetryDelayMillis(); + } + + /** + * Returns the maxRetryDelayMillis. Default values is {@value #DEFAULT_MAX_RETRY_DELAY_MILLIS}. + */ + public long getMaxRetryDelayMillis() { return maxRetryDelayMillis; } @@ -255,7 +364,16 @@ public long maxRetryDelayMillis() { * Returns the maxRetryDelayBackoffFactor. Default values is * {@value #DEFAULT_RETRY_DELAY_BACKOFF_FACTOR}. */ + @Deprecated public double retryDelayBackoffFactor() { + return getRetryDelayBackoffFactor(); + } + + /** + * Returns the maxRetryDelayBackoffFactor. Default values is + * {@value #DEFAULT_RETRY_DELAY_BACKOFF_FACTOR}. + */ + public double getRetryDelayBackoffFactor() { return retryDelayBackoffFactor; } @@ -263,7 +381,16 @@ public double retryDelayBackoffFactor() { * Returns the totalRetryPeriodMillis. Default value is * {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}. */ + @Deprecated public long totalRetryPeriodMillis() { + return getTotalRetryPeriodMillis(); + } + + /** + * Returns the totalRetryPeriodMillis. Default value is + * {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}. + */ + public long getTotalRetryPeriodMillis() { return totalRetryPeriodMillis; } @@ -301,7 +428,12 @@ public String toString() { return toStringHelper.toString(); } + @Deprecated public static Builder builder() { + return newBuilder(); + } + + public static Builder newBuilder() { return new Builder(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/Role.java b/google-cloud-core/src/main/java/com/google/cloud/Role.java index 60f826d3a9..9444421e6b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Role.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Role.java @@ -44,7 +44,16 @@ private Role(String value) { * Returns the string identifier for this role. For example, {@code "roles/viewer"}, * {@code "roles/editor"}, or {@code "roles/owner"}. */ + @Deprecated public String value() { + return getValue(); + } + + /** + * Returns the string identifier for this role. For example, {@code "roles/viewer"}, + * {@code "roles/editor"}, or {@code "roles/owner"}. + */ + public String getValue() { return value; } @@ -104,6 +113,6 @@ public String toString() { @Override public boolean equals(Object obj) { - return obj instanceof Role && Objects.equals(value, ((Role) obj).value()); + return obj instanceof Role && Objects.equals(value, ((Role) obj).getValue()); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/Service.java b/google-cloud-core/src/main/java/com/google/cloud/Service.java index a3797eca30..4c64e6fab2 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Service.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Service.java @@ -22,5 +22,8 @@ * @param the {@code ServiceOptions} subclass corresponding to the service */ public interface Service> { + @Deprecated OptionsT options(); + + OptionsT getOptions(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java index c68d14116a..29202c69d0 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java @@ -54,8 +54,14 @@ public int hashCode() { /** * Returns the service account associated with the signer. */ + @Deprecated String account(); + /** + * Returns the service account associated with the signer. + */ + String getAccount(); + /** * Signs the provided bytes using the private key associated with the service account. * diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index acd1611797..f918cd2188 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -70,7 +70,7 @@ public abstract class ServiceOptions, Service private static final String MANIFEST_VERSION_KEY = "Implementation-Version"; private static final String ARTIFACT_ID = "google-cloud-core"; private static final String LIBRARY_NAME = "gcloud-java"; - private static final String LIBRARY_VERSION = getLibraryVersion(); + private static final String LIBRARY_VERSION = defaultLibraryVersion(); private static final String APPLICATION_NAME = LIBRARY_VERSION == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + LIBRARY_VERSION; private static final long serialVersionUID = 3049375916337507361L; @@ -131,7 +131,15 @@ protected B self() { /** * Sets the service factory. */ + @Deprecated public B serviceFactory(ServiceFactory serviceFactory) { + return setServiceFactory(serviceFactory); + } + + /** + * Sets the service factory. + */ + public B setServiceFactory(ServiceFactory serviceFactory) { this.serviceFactory = serviceFactory; return self(); } @@ -143,7 +151,19 @@ public B serviceFactory(ServiceFactory serviceFactory) { * @param clock the clock to set * @return the builder */ + @Deprecated public B clock(Clock clock) { + return setClock(clock); + } + + /** + * Sets the service's clock. The clock is mainly used for testing purpose. {@link Clock} will be + * replaced by Java8's {@code java.time.Clock}. + * + * @param clock the clock to set + * @return the builder + */ + public B setClock(Clock clock) { this.clock = clock; return self(); } @@ -153,7 +173,17 @@ public B clock(Clock clock) { * * @return the builder */ + @Deprecated public B projectId(String projectId) { + return setProjectId(projectId); + } + + /** + * Sets project id. + * + * @return the builder + */ + public B setProjectId(String projectId) { this.projectId = projectId; return self(); } @@ -163,7 +193,17 @@ public B projectId(String projectId) { * * @return the builder */ + @Deprecated public B host(String host) { + return setHost(host); + } + + /** + * Sets service host. + * + * @return the builder + */ + public B setHost(String host) { this.host = host; return self(); } @@ -173,19 +213,41 @@ public B host(String host) { * * @return the builder */ + @Deprecated public B authCredentials(AuthCredentials authCredentials) { + return setAuthCredentials(authCredentials); + } + + /** + * Sets the service authentication credentials. + * + * @return the builder + */ + public B setAuthCredentials(AuthCredentials authCredentials) { this.authCredentials = authCredentials; return self(); } /** * Sets configuration parameters for request retries. If no configuration is set - * {@link RetryParams#defaultInstance()} is used. To disable retries, supply + * {@link RetryParams#getDefaultInstance()} is used. To disable retries, supply * {@link RetryParams#noRetries()} here. * * @return the builder */ + @Deprecated public B retryParams(RetryParams retryParams) { + return setRetryParams(retryParams); + } + + /** + * Sets configuration parameters for request retries. If no configuration is set + * {@link RetryParams#getDefaultInstance()} is used. To disable retries, supply + * {@link RetryParams#noRetries()} here. + * + * @return the builder + */ + public B setRetryParams(RetryParams retryParams) { this.retryParams = retryParams; return self(); } @@ -195,7 +257,17 @@ public B retryParams(RetryParams retryParams) { * * @return the builder */ + @Deprecated public B serviceRpcFactory(ServiceRpcFactory serviceRpcFactory) { + return setServiceRpcFactory(serviceRpcFactory); + } + + /** + * Sets the factory for rpc services. + * + * @return the builder + */ + public B setServiceRpcFactory(ServiceRpcFactory serviceRpcFactory) { this.serviceRpcFactory = serviceRpcFactory; return self(); } @@ -204,23 +276,23 @@ public B serviceRpcFactory(ServiceRpcFactory serviceRpcFa protected ServiceOptions(Class> serviceFactoryClass, Class> rpcFactoryClass, Builder builder) { - projectId = builder.projectId != null ? builder.projectId : defaultProject(); + projectId = builder.projectId != null ? builder.projectId : getDefaultProject(); if (projectIdRequired()) { checkArgument( projectId != null, "A project ID is required for this service but could not be determined from the builder " + "or the environment. Please set a project ID using the builder."); } - host = firstNonNull(builder.host, defaultHost()); + host = firstNonNull(builder.host, getDefaultHost()); authCredentials = builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials(); authCredentialsState = authCredentials != null ? authCredentials.capture() : null; retryParams = firstNonNull(builder.retryParams, defaultRetryParams()); serviceFactory = firstNonNull(builder.serviceFactory, - getFromServiceLoader(serviceFactoryClass, defaultServiceFactory())); + getFromServiceLoader(serviceFactoryClass, getDefaultServiceFactory())); serviceFactoryClassName = serviceFactory.getClass().getName(); serviceRpcFactory = firstNonNull(builder.serviceRpcFactory, - getFromServiceLoader(rpcFactoryClass, defaultRpcFactory())); + getFromServiceLoader(rpcFactoryClass, getDefaultRpcFactory())); serviceRpcFactoryClassName = serviceRpcFactory.getClass().getName(); clock = firstNonNull(builder.clock, Clock.defaultClock()); } @@ -256,11 +328,21 @@ protected static String appEngineAppId() { return System.getProperty("com.google.appengine.application.id"); } + @Deprecated protected String defaultHost() { + return getDefaultHost(); + } + + protected String getDefaultHost() { return DEFAULT_HOST; } + @Deprecated protected String defaultProject() { + return getDefaultProject(); + } + + protected String getDefaultProject() { String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); if (projectId == null) { projectId = @@ -385,16 +467,26 @@ protected static String serviceAccountProjectId() { return project; } - @SuppressWarnings("unchecked") + @Deprecated public ServiceT service() { + return getService(); + } + + @SuppressWarnings("unchecked") + public ServiceT getService() { if (service == null) { service = serviceFactory.create((OptionsT) this); } return service; } - @SuppressWarnings("unchecked") + @Deprecated public ServiceRpcT rpc() { + return getRpc(); + } + + @SuppressWarnings("unchecked") + public ServiceRpcT getRpc() { if (rpc == null) { rpc = serviceRpcFactory.create((OptionsT) this); } @@ -405,29 +497,63 @@ public ServiceRpcT rpc() { * Returns the project id. Return value can be null (for services that don't require a project * id). */ + @Deprecated public String projectId() { + return getProjectId(); + } + + /** + * Returns the project id. Return value can be null (for services that don't require a project + * id). + */ + public String getProjectId() { return projectId; } /** * Returns the service host. */ + @Deprecated public String host() { + return getHost(); + } + + /** + * Returns the service host. + */ + public String getHost() { return host; } /** * Returns the authentication credentials. */ + @Deprecated public AuthCredentials authCredentials() { + return getAuthCredentials(); + } + + /** + * Returns the authentication credentials. + */ + public AuthCredentials getAuthCredentials() { return authCredentials; } /** * Returns configuration parameters for request retries. By default requests are retried: - * {@link RetryParams#defaultInstance()} is used. + * {@link RetryParams#getDefaultInstance()} is used. */ + @Deprecated public RetryParams retryParams() { + return getRetryParams(); + } + + /** + * Returns configuration parameters for request retries. By default requests are retried: + * {@link RetryParams#getDefaultInstance()} is used. + */ + public RetryParams getRetryParams() { return retryParams; } @@ -435,21 +561,46 @@ public RetryParams retryParams() { * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to get * current time. */ + @Deprecated public Clock clock() { + return getClock(); + } + + /** + * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to get + * current time. + */ + public Clock getClock() { return clock; } /** * Returns the application's name as a string in the format {@code gcloud-java/[version]}. */ + @Deprecated public String applicationName() { + return getApplicationName(); + } + + /** + * Returns the application's name as a string in the format {@code gcloud-java/[version]}. + */ + public String getApplicationName() { return APPLICATION_NAME; } /** * Returns the library's name, {@code gcloud-java}, as a string. */ + @Deprecated public String libraryName() { + return getLibraryName(); + } + + /** + * Returns the library's name, {@code gcloud-java}, as a string. + */ + public String getLibraryName() { return LIBRARY_NAME; } @@ -457,6 +608,13 @@ public String libraryName() { * Returns the library's version as a string. */ public String libraryVersion() { + return getLibraryVersion(); + } + + /** + * Returns the library's version as a string. + */ + public String getLibraryVersion() { return LIBRARY_VERSION; } @@ -491,11 +649,26 @@ static T newInstance(String className) throws IOException, ClassNotFoundExce } } - protected abstract ServiceFactory defaultServiceFactory(); + @Deprecated + protected ServiceFactory defaultServiceFactory() { + return getDefaultServiceFactory(); + } + + protected abstract ServiceFactory getDefaultServiceFactory(); + + @Deprecated + protected ServiceRpcFactory defaultRpcFactory() { + return getDefaultRpcFactory(); + } + + protected abstract ServiceRpcFactory getDefaultRpcFactory(); - protected abstract ServiceRpcFactory defaultRpcFactory(); + @Deprecated + protected Set scopes() { + return getScopes(); + } - protected abstract Set scopes(); + protected abstract Set getScopes(); public abstract > B toBuilder(); @@ -505,14 +678,14 @@ static T newInstance(String className) throws IOException, ClassNotFoundExce * default parameters listed in {@link RetryParams}. */ protected RetryParams defaultRetryParams() { - return RetryParams.defaultInstance(); + return RetryParams.getDefaultInstance(); } static T getFromServiceLoader(Class clazz, T defaultInstance) { return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance); } - private static String getLibraryVersion() { + private static String defaultLibraryVersion() { String version = null; try { Enumeration resources = diff --git a/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java b/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java index 8af7a074ab..1938f81994 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java +++ b/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java @@ -63,14 +63,30 @@ private CheckingPeriod(long period, TimeUnit unit) { /** * Returns the checking period. */ + @Deprecated public long period() { + return getPeriod(); + } + + /** + * Returns the checking period. + */ + public long getPeriod() { return period; } /** - * Returns the time unit for {@link #period()}. + * Returns the time unit for {@link #getPeriod()}. */ + @Deprecated public TimeUnit unit() { + return getUnit(); + } + + /** + * Returns the time unit for {@link #getPeriod()}. + */ + public TimeUnit getUnit() { return unit; } @@ -139,7 +155,15 @@ private Timeout(long timeoutMillis) { /** * Returns the timeout in milliseconds. */ + @Deprecated public long timeoutMillis() { + return getTimeoutMillis(); + } + + /** + * Returns the timeout in milliseconds. + */ + public long getTimeoutMillis() { return timeoutMillis; } @@ -176,7 +200,7 @@ public static Timeout getOrDefault(WaitForOption... options) { } } - OptionType optionType() { + OptionType getOptionType() { return optionType; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java index 636bc60d02..f061f55ac5 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java @@ -33,8 +33,15 @@ public interface WriteChannel extends WritableByteChannel, Closeable, Restorable * Sets the minimum size that will be written by a single RPC. * Written data will be buffered and only flushed upon reaching this size or closing the channel. */ + @Deprecated void chunkSize(int chunkSize); + /** + * Sets the minimum size that will be written by a single RPC. + * Written data will be buffered and only flushed upon reaching this size or closing the channel. + */ + void setChunkSize(int chunkSize); + /** * Captures the write channel state so that it can be saved and restored afterwards. The original * {@code WriteChannel} and the restored one should not both be used. Closing one channel diff --git a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java index 60189a0554..0767d205ec 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java @@ -41,17 +41,40 @@ public class AsyncPageImplTest { .addAll(VALUES3) .build(); + private static class TestPageFetcher implements AsyncPageImpl.NextPageFetcher { + private static final long serialVersionUID = 4703765400378593176L; + + private final AsyncPageImpl nextResult; + + TestPageFetcher(AsyncPageImpl nextResult) { + this.nextResult = nextResult; + } + + @Override + public Future> nextPage() { + return getNextPage(); + } + + @Override + public Future> getNextPage() { + return Futures.>immediateFuture(nextResult); + } + } + @Test public void testPage() { final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2); - AsyncPageImpl.NextPageFetcher fetcher = new AsyncPageImpl.NextPageFetcher() { - private static final long serialVersionUID = 4703765400378593176L; - - @Override - public Future> nextPage() { - return Futures.>immediateFuture(nextResult); - } - }; + AsyncPageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); + AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1); + assertEquals(nextResult, result.getNextPage()); + assertEquals("c", result.getNextPageCursor()); + assertEquals(VALUES1, result.getValues()); + } + + @Test + public void testPageDeprecated() { + final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2); + AsyncPageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1); assertEquals(nextResult, result.nextPage()); assertEquals("c", result.nextPageCursor()); @@ -61,14 +84,17 @@ public Future> nextPage() { @Test public void testPageAsync() throws ExecutionException, InterruptedException { final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2); - AsyncPageImpl.NextPageFetcher fetcher = new AsyncPageImpl.NextPageFetcher() { - private static final long serialVersionUID = 4703765400378593176L; - - @Override - public Future> nextPage() { - return Futures.>immediateFuture(nextResult); - } - }; + AsyncPageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); + AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1); + assertEquals(nextResult, result.getNextPageAsync().get()); + assertEquals("c", result.getNextPageCursor()); + assertEquals(VALUES1, result.getValues()); + } + + @Test + public void testPageAsyncDeprecated() throws ExecutionException, InterruptedException { + final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2); + AsyncPageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1); assertEquals(nextResult, result.nextPageAsync().get()); assertEquals("c", result.nextPageCursor()); @@ -78,23 +104,9 @@ public Future> nextPage() { @Test public void testIterateAll() { final AsyncPageImpl nextResult2 = new AsyncPageImpl<>(null, "c3", VALUES3); - AsyncPageImpl.NextPageFetcher fetcher2 = new AsyncPageImpl.NextPageFetcher() { - private static final long serialVersionUID = -9203621430631884026L; - - @Override - public Future> nextPage() { - return Futures.>immediateFuture(nextResult2); - } - }; + AsyncPageImpl.NextPageFetcher fetcher2 = new TestPageFetcher(nextResult2); final AsyncPageImpl nextResult1 = new AsyncPageImpl<>(fetcher2, "c2", VALUES2); - AsyncPageImpl.NextPageFetcher fetcher1 = new AsyncPageImpl.NextPageFetcher() { - private static final long serialVersionUID = -9203621430631884026L; - - @Override - public Future> nextPage() { - return Futures.>immediateFuture(nextResult1); - } - }; + AsyncPageImpl.NextPageFetcher fetcher1 = new TestPageFetcher(nextResult1); AsyncPageImpl result = new AsyncPageImpl<>(fetcher1, "c1", VALUES1); assertEquals(ALL_VALUES, ImmutableList.copyOf(result.iterateAll())); } @@ -102,27 +114,13 @@ public Future> nextPage() { @Test public void testAsyncPageAndIterateAll() throws ExecutionException, InterruptedException { final AsyncPageImpl nextResult2 = new AsyncPageImpl<>(null, "c3", VALUES3); - AsyncPageImpl.NextPageFetcher fetcher2 = new AsyncPageImpl.NextPageFetcher() { - private static final long serialVersionUID = -9203621430631884026L; - - @Override - public Future> nextPage() { - return Futures.>immediateFuture(nextResult2); - } - }; + AsyncPageImpl.NextPageFetcher fetcher2 = new TestPageFetcher(nextResult2); final AsyncPageImpl nextResult1 = new AsyncPageImpl<>(fetcher2, "c2", VALUES2); - AsyncPageImpl.NextPageFetcher fetcher1 = new AsyncPageImpl.NextPageFetcher() { - private static final long serialVersionUID = -9203621430631884026L; - - @Override - public Future> nextPage() { - return Futures.>immediateFuture(nextResult1); - } - }; + AsyncPageImpl.NextPageFetcher fetcher1 = new TestPageFetcher(nextResult1); AsyncPageImpl result = new AsyncPageImpl<>(fetcher1, "c1", VALUES1); - assertEquals(nextResult1, result.nextPageAsync().get()); - assertEquals("c1", result.nextPageCursor()); - assertEquals(VALUES1, result.values()); - assertEquals(SOME_VALUES, ImmutableList.copyOf(result.nextPageAsync().get().iterateAll())); + assertEquals(nextResult1, result.getNextPageAsync().get()); + assertEquals("c1", result.getNextPageCursor()); + assertEquals(VALUES1, result.getValues()); + assertEquals(SOME_VALUES, ImmutableList.copyOf(result.getNextPageAsync().get().iterateAll())); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java b/google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java index 9074c2d103..3ae34e6ca9 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java @@ -88,12 +88,30 @@ public static void beforeClass() throws NoSuchAlgorithmException, InvalidKeySpec @Test public void testNoAuthCredentials() { + assertSame(NO_AUTH_CREDENTIALS, AuthCredentials.noAuth()); + assertNull(NO_AUTH_CREDENTIALS.getCredentials()); + } + + @Test + public void testNoAuthCredentialsDeprecated() { assertSame(NO_AUTH_CREDENTIALS, AuthCredentials.noAuth()); assertNull(NO_AUTH_CREDENTIALS.credentials()); } @Test public void testOAuth2AuthCredentials() { + AccessToken accessToken = OAUTH2_AUTH_CREDENTIALS.getCredentials().getAccessToken(); + assertEquals(ACCESS_TOKEN, accessToken.getTokenValue()); + assertEquals(EXPIRATION_DATE, accessToken.getExpirationTime()); + OAuth2AuthCredentials oAuth2AuthCredentials = + AuthCredentials.createFor(ACCESS_TOKEN); + accessToken = oAuth2AuthCredentials.getCredentials().getAccessToken(); + assertEquals(ACCESS_TOKEN, accessToken.getTokenValue()); + assertNull(accessToken.getExpirationTime()); + } + + @Test + public void testOAuth2AuthCredentialsDeprecated() { AccessToken accessToken = OAUTH2_AUTH_CREDENTIALS.credentials().getAccessToken(); assertEquals(ACCESS_TOKEN, accessToken.getTokenValue()); assertEquals(EXPIRATION_DATE, accessToken.getExpirationTime()); @@ -106,6 +124,17 @@ public void testOAuth2AuthCredentials() { @Test public void testServiceAccountFromJson() throws IOException, SignatureException { + ServiceAccountAuthCredentials serviceAccountAuthCredentials = + AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes())); + ServiceAccountCredentials credentials = serviceAccountAuthCredentials.getCredentials(); + assertEquals(SERVICE_ACCOUNT, serviceAccountAuthCredentials.getAccount()); + assertEquals(SERVICE_ACCOUNT, credentials.getClientEmail()); + assertEquals(privateKey, credentials.getPrivateKey()); + assertArrayEquals(signedBytes, serviceAccountAuthCredentials.sign(BYTES_TO_SIGN)); + } + + @Test + public void testServiceAccountFromJsonDeprecated() throws IOException, SignatureException { ServiceAccountAuthCredentials serviceAccountAuthCredentials = AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes())); ServiceAccountCredentials credentials = serviceAccountAuthCredentials.credentials(); @@ -117,6 +146,17 @@ public void testServiceAccountFromJson() throws IOException, SignatureException @Test public void testServiceAccountFromKey() throws IOException, SignatureException { + ServiceAccountAuthCredentials serviceAccountAuthCredentials = + AuthCredentials.createFor(SERVICE_ACCOUNT, privateKey); + ServiceAccountCredentials credentials = serviceAccountAuthCredentials.getCredentials(); + assertEquals(SERVICE_ACCOUNT, serviceAccountAuthCredentials.getAccount()); + assertEquals(SERVICE_ACCOUNT, credentials.getClientEmail()); + assertEquals(privateKey, credentials.getPrivateKey()); + assertArrayEquals(signedBytes, serviceAccountAuthCredentials.sign(BYTES_TO_SIGN)); + } + + @Test + public void testServiceAccountFromKeyDeprecated() throws IOException, SignatureException { ServiceAccountAuthCredentials serviceAccountAuthCredentials = AuthCredentials.createFor(SERVICE_ACCOUNT, privateKey); ServiceAccountCredentials credentials = serviceAccountAuthCredentials.credentials(); diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index 4517afff44..8980643b32 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -56,7 +56,7 @@ public CustomServiceException(int code, String message, String reason, boolean i } @Override - protected Set retryableErrors() { + protected Set getRetryableErrors() { return ImmutableSet.of(new Error(CODE, REASON), new Error(null, REASON), new Error(CODE_NO_REASON, null)); } @@ -64,6 +64,94 @@ protected Set retryableErrors() { @Test public void testBaseServiceException() { + BaseServiceException serviceException = new BaseServiceException(CODE, MESSAGE, REASON, + IDEMPOTENT); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertFalse(serviceException.isRetryable()); + assertEquals(IDEMPOTENT, serviceException.isIdempotent()); + assertNull(serviceException.getCause()); + + serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertFalse(serviceException.isRetryable()); + assertEquals(IDEMPOTENT, serviceException.isIdempotent()); + assertNull(serviceException.getCause()); + + Exception cause = new RuntimeException(); + serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, cause); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertFalse(serviceException.isRetryable()); + assertEquals(IDEMPOTENT, serviceException.isIdempotent()); + assertEquals(cause, serviceException.getCause()); + + serviceException = new BaseServiceException(CODE, MESSAGE, REASON, false, cause); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertFalse(serviceException.isRetryable()); + assertFalse(serviceException.isIdempotent()); + assertEquals(cause, serviceException.getCause()); + + IOException exception = new SocketTimeoutException(); + serviceException = new BaseServiceException(exception, true); + assertTrue(serviceException.isRetryable()); + assertTrue(serviceException.isIdempotent()); + assertNull(serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + + exception = new SocketException(); + serviceException = new BaseServiceException(exception, true); + assertTrue(serviceException.isRetryable()); + assertTrue(serviceException.isIdempotent()); + assertNull(serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + + exception = new IOException("insufficient data written"); + serviceException = new BaseServiceException(exception, true); + assertTrue(serviceException.isRetryable()); + assertTrue(serviceException.isIdempotent()); + assertEquals("insufficient data written", serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + + GoogleJsonError error = new GoogleJsonError(); + error.setCode(CODE); + error.setMessage(MESSAGE); + serviceException = new BaseServiceException(error, true); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertFalse(serviceException.isRetryable()); + assertTrue(serviceException.isIdempotent()); + + serviceException = new CustomServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertEquals(RETRYABLE, serviceException.isRetryable()); + assertEquals(IDEMPOTENT, serviceException.isIdempotent()); + + serviceException = new CustomServiceException(CODE_NO_REASON, MESSAGE, null, IDEMPOTENT); + assertEquals(CODE_NO_REASON, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertNull(serviceException.getReason()); + assertEquals(RETRYABLE, serviceException.isRetryable()); + assertEquals(IDEMPOTENT, serviceException.isIdempotent()); + + serviceException = new CustomServiceException(UNKNOWN_CODE, MESSAGE, REASON, IDEMPOTENT); + assertEquals(UNKNOWN_CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertEquals(RETRYABLE, serviceException.isRetryable()); + assertEquals(IDEMPOTENT, serviceException.isIdempotent()); + } + + @Test + public void testBaseServiceExceptionDeprecated() { BaseServiceException serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); assertEquals(CODE, serviceException.code()); @@ -160,10 +248,10 @@ public void testTranslateAndThrow() throws Exception { try { BaseServiceException.translateAndPropagateIfPossible(exceptionMock); } catch (BaseServiceException ex) { - assertEquals(CODE, ex.code()); + assertEquals(CODE, ex.getCode()); assertEquals(MESSAGE, ex.getMessage()); - assertFalse(ex.retryable()); - assertEquals(IDEMPOTENT, ex.idempotent()); + assertFalse(ex.isRetryable()); + assertEquals(IDEMPOTENT, ex.isIdempotent()); } finally { verify(exceptionMock); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java index fc476b11ae..9fb58a1633 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java @@ -83,6 +83,18 @@ protected BaseState.Builder stateBuilder() { @Test public void testConstructor() { + assertEquals(null, channel.getOptions()); + assertEquals(ENTITY, channel.getEntity()); + assertEquals(0, channel.getPosition()); + assertEquals(UPLOAD_ID, channel.getUploadId()); + assertEquals(0, channel.getLimit()); + assertTrue(channel.isOpen()); + assertArrayEquals(new byte[0], channel.getBuffer()); + assertEquals(DEFAULT_CHUNK_SIZE, channel.getChunkSize()); + } + + @Test + public void testConstructorDeprecated() { assertEquals(null, channel.options()); assertEquals(ENTITY, channel.entity()); assertEquals(0, channel.position()); @@ -97,7 +109,7 @@ public void testConstructor() { public void testClose() throws IOException { channel.close(); assertFalse(channel.isOpen()); - assertNull(channel.buffer()); + assertNull(channel.getBuffer()); } @Test @@ -109,31 +121,31 @@ public void testValidateOpen() throws IOException { @Test public void testChunkSize() { - channel.chunkSize(42); - assertEquals(MIN_CHUNK_SIZE, channel.chunkSize()); - channel.chunkSize(2 * MIN_CHUNK_SIZE); - assertEquals(2 * MIN_CHUNK_SIZE, channel.chunkSize()); - channel.chunkSize(512 * 1025); - assertEquals(2 * MIN_CHUNK_SIZE, channel.chunkSize()); + channel.setChunkSize(42); + assertEquals(MIN_CHUNK_SIZE, channel.getChunkSize()); + channel.setChunkSize(2 * MIN_CHUNK_SIZE); + assertEquals(2 * MIN_CHUNK_SIZE, channel.getChunkSize()); + channel.setChunkSize(512 * 1025); + assertEquals(2 * MIN_CHUNK_SIZE, channel.getChunkSize()); } @Test public void testWrite() throws IOException { channel.write(ByteBuffer.wrap(CONTENT)); - assertEquals(CONTENT.length, channel.limit()); - assertEquals(DEFAULT_CHUNK_SIZE, channel.buffer().length); - assertArrayEquals(Arrays.copyOf(CONTENT, DEFAULT_CHUNK_SIZE), channel.buffer()); + assertEquals(CONTENT.length, channel.getLimit()); + assertEquals(DEFAULT_CHUNK_SIZE, channel.getBuffer().length); + assertArrayEquals(Arrays.copyOf(CONTENT, DEFAULT_CHUNK_SIZE), channel.getBuffer()); } @Test public void testWriteAndFlush() throws IOException { ByteBuffer content = randomBuffer(DEFAULT_CHUNK_SIZE + 1); channel.write(content); - assertEquals(DEFAULT_CHUNK_SIZE, channel.position()); - assertEquals(1, channel.limit()); + assertEquals(DEFAULT_CHUNK_SIZE, channel.getPosition()); + assertEquals(1, channel.getLimit()); byte[] newContent = new byte[DEFAULT_CHUNK_SIZE]; newContent[0] = content.get(DEFAULT_CHUNK_SIZE); - assertArrayEquals(newContent, channel.buffer()); + assertArrayEquals(newContent, channel.getBuffer()); } private static ByteBuffer randomBuffer(int size) { diff --git a/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java index ddbd2ced84..f489207019 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java @@ -82,7 +82,7 @@ public Object call() throws Error { } // using default exception handler (retry upon any non-runtime exceptions) - ExceptionHandler handler = ExceptionHandler.defaultInstance(); + ExceptionHandler handler = ExceptionHandler.getDefaultInstance(); assertValidCallable(new A(), handler); assertValidCallable(new B(), handler); assertValidCallable(new C(), handler); @@ -90,7 +90,7 @@ public Object call() throws Error { assertValidCallable(new E(), handler); assertInvalidCallable(new F(), handler); - handler = ExceptionHandler.builder() + handler = ExceptionHandler.newBuilder() .retryOn(FileNotFoundException.class, NullPointerException.class) .build(); assertInvalidCallable(new A(), handler); @@ -116,12 +116,12 @@ private static void assertInvalidCallable(Callable callable, ExceptionHan @Test public void testShouldTry() { - ExceptionHandler handler = ExceptionHandler.builder().retryOn(IOException.class).build(); + ExceptionHandler handler = ExceptionHandler.newBuilder().retryOn(IOException.class).build(); assertTrue(handler.shouldRetry(new IOException())); assertTrue(handler.shouldRetry(new ClosedByInterruptException())); assertFalse(handler.shouldRetry(new RuntimeException())); - ExceptionHandler.Builder builder = ExceptionHandler.builder() + ExceptionHandler.Builder builder = ExceptionHandler.newBuilder() .retryOn(IOException.class, NullPointerException.class) .abortOn(RuntimeException.class, ClosedByInterruptException.class, InterruptedException.class); @@ -148,7 +148,7 @@ public RetryResult beforeEval(Exception exception) { } }; - builder.interceptor(interceptor); + builder.addInterceptors(interceptor); handler = builder.build(); assertFalse(handler.shouldRetry(new IOException())); assertFalse(handler.shouldRetry(new ClosedByInterruptException())); @@ -188,7 +188,7 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { }; - ExceptionHandler handler = ExceptionHandler.builder().interceptor(interceptor).build(); + ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build(); thrown.expect(NullPointerException.class); handler.shouldRetry(new Exception()); } @@ -210,7 +210,7 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { }; - ExceptionHandler handler = ExceptionHandler.builder().interceptor(interceptor).build(); + ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build(); thrown.expect(NullPointerException.class); handler.shouldRetry(new Exception()); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java index 02d5847946..408dc73132 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java @@ -31,18 +31,33 @@ public class FieldSelectorHelperTest { private static final FieldSelector FIELD1 = new FieldSelector() { @Override public String selector() { + return getSelector(); + } + + @Override + public String getSelector() { return "field1"; } }; private static final FieldSelector FIELD2 = new FieldSelector() { @Override public String selector() { + return getSelector(); + } + + @Override + public String getSelector() { return "field2"; } }; private static final FieldSelector FIELD3 = new FieldSelector() { @Override public String selector() { + return getSelector(); + } + + @Override + public String getSelector() { return "field3"; } }; diff --git a/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java index 457f05cd0b..f0906fae03 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java @@ -36,15 +36,25 @@ public class GrpcServiceOptionsTest { private static final ExecutorFactory MOCK_EXECUTOR_FACTORY = EasyMock.createMock(ExecutorFactory.class); - private static final TestGrpcServiceOptions OPTIONS = TestGrpcServiceOptions.builder() - .projectId("project-id") - .initialTimeout(1234) - .timeoutMultiplier(1.6) - .maxTimeout(5678) - .executorFactory(MOCK_EXECUTOR_FACTORY) + private static final TestGrpcServiceOptions OPTIONS = TestGrpcServiceOptions.newBuilder() + .setProjectId("project-id") + .setInitialTimeout(1234) + .setTimeoutMultiplier(1.6) + .setMaxTimeout(5678) + .setExecutorFactory(MOCK_EXECUTOR_FACTORY) .build(); + private static final TestGrpcServiceOptions DEPRECATED_OPTIONS = + TestGrpcServiceOptions.newBuilder() + .projectId("project-id") + .initialTimeout(1234) + .timeoutMultiplier(1.6) + .maxTimeout(5678) + .executorFactory(MOCK_EXECUTOR_FACTORY) + .build(); private static final TestGrpcServiceOptions DEFAULT_OPTIONS = - TestGrpcServiceOptions.builder().projectId("project-id").build(); + TestGrpcServiceOptions.newBuilder().setProjectId("project-id").build(); + private static final TestGrpcServiceOptions DEPRECATED_DEFAULT_OPTIONS = + TestGrpcServiceOptions.newBuilder().projectId("project-id").build(); private static final TestGrpcServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); private interface TestService extends Service {} @@ -108,17 +118,17 @@ private TestGrpcServiceOptions(Builder builder) { } @Override - protected TestServiceFactory defaultServiceFactory() { + protected TestServiceFactory getDefaultServiceFactory() { return DefaultTestServiceFactory.INSTANCE; } @Override - protected TestServiceRpcFactory defaultRpcFactory() { + protected TestServiceRpcFactory getDefaultRpcFactory() { return DefaultTestServiceRpcFactory.INSTANCE; } @Override - protected Set scopes() { + protected Set getScopes() { return null; } @@ -127,7 +137,7 @@ public Builder toBuilder() { return new Builder(this); } - private static Builder builder() { + private static Builder newBuilder() { return new Builder(); } @@ -144,32 +154,44 @@ public int hashCode() { @Test public void testBuilder() { - assertEquals(1234, OPTIONS.initialTimeout()); - assertEquals(1.6, OPTIONS.timeoutMultiplier(), 0.0); - assertEquals(5678, OPTIONS.maxTimeout()); - assertSame(MOCK_EXECUTOR_FACTORY, OPTIONS.executorFactory()); - assertEquals(20000, DEFAULT_OPTIONS.initialTimeout()); - assertEquals(1.5, DEFAULT_OPTIONS.timeoutMultiplier(), 0.0); - assertEquals(100000, DEFAULT_OPTIONS.maxTimeout()); - assertTrue(DEFAULT_OPTIONS.executorFactory() instanceof DefaultExecutorFactory); + assertEquals(1234, OPTIONS.getInitialTimeout()); + assertEquals(1.6, OPTIONS.getTimeoutMultiplier(), 0.0); + assertEquals(5678, OPTIONS.getMaxTimeout()); + assertSame(MOCK_EXECUTOR_FACTORY, OPTIONS.getExecutorFactory()); + assertEquals(20000, DEFAULT_OPTIONS.getInitialTimeout()); + assertEquals(1.5, DEFAULT_OPTIONS.getTimeoutMultiplier(), 0.0); + assertEquals(100000, DEFAULT_OPTIONS.getMaxTimeout()); + assertTrue(DEFAULT_OPTIONS.getExecutorFactory() instanceof DefaultExecutorFactory); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(1234, DEPRECATED_OPTIONS.initialTimeout()); + assertEquals(1.6, DEPRECATED_OPTIONS.timeoutMultiplier(), 0.0); + assertEquals(5678, DEPRECATED_OPTIONS.maxTimeout()); + assertSame(MOCK_EXECUTOR_FACTORY, DEPRECATED_OPTIONS.executorFactory()); + assertEquals(20000, DEPRECATED_DEFAULT_OPTIONS.initialTimeout()); + assertEquals(1.5, DEPRECATED_DEFAULT_OPTIONS.timeoutMultiplier(), 0.0); + assertEquals(100000, DEPRECATED_DEFAULT_OPTIONS.maxTimeout()); + assertTrue(DEPRECATED_DEFAULT_OPTIONS.executorFactory() instanceof DefaultExecutorFactory); } @Test public void testBuilderError() { try { - TestGrpcServiceOptions.builder().initialTimeout(0); + TestGrpcServiceOptions.newBuilder().setInitialTimeout(0); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException ex) { assertEquals("Initial timeout must be > 0", ex.getMessage()); } try { - TestGrpcServiceOptions.builder().initialTimeout(-1); + TestGrpcServiceOptions.newBuilder().setInitialTimeout(-1); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException ex) { assertEquals("Initial timeout must be > 0", ex.getMessage()); } try { - TestGrpcServiceOptions.builder().timeoutMultiplier(0.9); + TestGrpcServiceOptions.newBuilder().setTimeoutMultiplier(0.9); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException ex) { assertEquals("Timeout multiplier must be >= 1", ex.getMessage()); @@ -178,15 +200,15 @@ public void testBuilderError() { @Test public void testBuilderInvalidMaxTimeout() { - TestGrpcServiceOptions options = TestGrpcServiceOptions.builder() - .projectId("project-id") - .initialTimeout(1234) - .timeoutMultiplier(1.6) - .maxTimeout(123) + TestGrpcServiceOptions options = TestGrpcServiceOptions.newBuilder() + .setProjectId("project-id") + .setInitialTimeout(1234) + .setTimeoutMultiplier(1.6) + .setMaxTimeout(123) .build(); - assertEquals(1234, options.initialTimeout()); - assertEquals(1.6, options.timeoutMultiplier(), 0.0); - assertEquals(1234, options.maxTimeout()); + assertEquals(1234, options.getInitialTimeout()); + assertEquals(1.6, options.getTimeoutMultiplier(), 0.0); + assertEquals(1234, options.getMaxTimeout()); } @Test @@ -194,7 +216,7 @@ public void testBaseEquals() { assertEquals(OPTIONS, OPTIONS_COPY); assertNotEquals(DEFAULT_OPTIONS, OPTIONS); TestGrpcServiceOptions options = OPTIONS.toBuilder() - .executorFactory(new DefaultExecutorFactory()) + .setExecutorFactory(new DefaultExecutorFactory()) .build(); assertNotEquals(OPTIONS, options); } @@ -204,7 +226,7 @@ public void testBaseHashCode() { assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); TestGrpcServiceOptions options = OPTIONS.toBuilder() - .executorFactory(new DefaultExecutorFactory()) + .setExecutorFactory(new DefaultExecutorFactory()) .build(); assertNotEquals(OPTIONS.hashCode(), options.hashCode()); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java index de8dc8592e..a372498c21 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java @@ -34,14 +34,23 @@ public class HttpServiceOptionsTest { private static final HttpTransportFactory MOCK_HTTP_TRANSPORT_FACTORY = EasyMock.createMock(HttpTransportFactory.class); - private static final TestHttpServiceOptions OPTIONS = TestHttpServiceOptions.builder() - .projectId("project-id") - .connectTimeout(1234) - .httpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) - .readTimeout(5678) + private static final TestHttpServiceOptions OPTIONS = TestHttpServiceOptions.newBuilder() + .setProjectId("project-id") + .setConnectTimeout(1234) + .setHttpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) + .setReadTimeout(5678) .build(); + private static final TestHttpServiceOptions DEPRECATED_OPTIONS = + TestHttpServiceOptions.newBuilder() + .projectId("project-id") + .connectTimeout(1234) + .httpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) + .readTimeout(5678) + .build(); private static final TestHttpServiceOptions DEFAULT_OPTIONS = - TestHttpServiceOptions.builder().projectId("project-id").build(); + TestHttpServiceOptions.newBuilder().setProjectId("project-id").build(); + private static final TestHttpServiceOptions DEPRECATED_DEFAULT_OPTIONS = + TestHttpServiceOptions.newBuilder().projectId("project-id").build(); private static final TestHttpServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); private interface TestService extends Service {} @@ -105,17 +114,17 @@ private TestHttpServiceOptions(Builder builder) { } @Override - protected TestServiceFactory defaultServiceFactory() { + protected TestServiceFactory getDefaultServiceFactory() { return DefaultTestServiceFactory.INSTANCE; } @Override - protected TestServiceRpcFactory defaultRpcFactory() { + protected TestServiceRpcFactory getDefaultRpcFactory() { return DefaultTestServiceRpcFactory.INSTANCE; } @Override - protected Set scopes() { + protected Set getScopes() { return null; } @@ -124,7 +133,7 @@ public Builder toBuilder() { return new Builder(this); } - private static Builder builder() { + private static Builder newBuilder() { return new Builder(); } @@ -141,12 +150,23 @@ public int hashCode() { @Test public void testBuilder() { - assertEquals(1234, OPTIONS.connectTimeout()); - assertSame(MOCK_HTTP_TRANSPORT_FACTORY, OPTIONS.httpTransportFactory()); - assertEquals(5678, OPTIONS.readTimeout()); - assertEquals(-1, DEFAULT_OPTIONS.connectTimeout()); - assertTrue(DEFAULT_OPTIONS.httpTransportFactory() instanceof DefaultHttpTransportFactory); - assertEquals(-1, DEFAULT_OPTIONS.readTimeout()); + assertEquals(1234, OPTIONS.getConnectTimeout()); + assertSame(MOCK_HTTP_TRANSPORT_FACTORY, OPTIONS.getHttpTransportFactory()); + assertEquals(5678, OPTIONS.getReadTimeout()); + assertEquals(-1, DEFAULT_OPTIONS.getConnectTimeout()); + assertTrue(DEFAULT_OPTIONS.getHttpTransportFactory() instanceof DefaultHttpTransportFactory); + assertEquals(-1, DEFAULT_OPTIONS.getReadTimeout()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(1234, DEPRECATED_OPTIONS.connectTimeout()); + assertSame(MOCK_HTTP_TRANSPORT_FACTORY, DEPRECATED_OPTIONS.httpTransportFactory()); + assertEquals(5678, DEPRECATED_OPTIONS.readTimeout()); + assertEquals(-1, DEPRECATED_DEFAULT_OPTIONS.connectTimeout()); + assertTrue( + DEPRECATED_DEFAULT_OPTIONS.httpTransportFactory() instanceof DefaultHttpTransportFactory); + assertEquals(-1, DEPRECATED_DEFAULT_OPTIONS.readTimeout()); } @Test diff --git a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java index e720503c54..5a80daa50d 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java @@ -33,18 +33,36 @@ public class IdentityTest { @Test public void testAllUsers() { + assertEquals(Identity.Type.ALL_USERS, ALL_USERS.getType()); + assertNull(ALL_USERS.getValue()); + } + + @Test + public void testAllUsersDeprecated() { assertEquals(Identity.Type.ALL_USERS, ALL_USERS.type()); assertNull(ALL_USERS.value()); } @Test public void testAllAuthenticatedUsers() { + assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTH_USERS.getType()); + assertNull(ALL_AUTH_USERS.getValue()); + } + + @Test + public void testAllAuthenticatedUsersDeprecated() { assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTH_USERS.type()); assertNull(ALL_AUTH_USERS.value()); } @Test public void testUser() { + assertEquals(Identity.Type.USER, USER.getType()); + assertEquals("abc@gmail.com", USER.getValue()); + } + + @Test + public void testUserDeprecated() { assertEquals(Identity.Type.USER, USER.type()); assertEquals("abc@gmail.com", USER.value()); } @@ -56,6 +74,12 @@ public void testUserNullEmail() { @Test public void testServiceAccount() { + assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.getType()); + assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.getValue()); + } + + @Test + public void testServiceAccountDeprecated() { assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type()); assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.value()); } @@ -67,6 +91,12 @@ public void testServiceAccountNullEmail() { @Test public void testGroup() { + assertEquals(Identity.Type.GROUP, GROUP.getType()); + assertEquals("group@gmail.com", GROUP.getValue()); + } + + @Test + public void testGroupDeprecated() { assertEquals(Identity.Type.GROUP, GROUP.type()); assertEquals("group@gmail.com", GROUP.value()); } @@ -78,6 +108,12 @@ public void testGroupNullEmail() { @Test public void testDomain() { + assertEquals(Identity.Type.DOMAIN, DOMAIN.getType()); + assertEquals("google.com", DOMAIN.getValue()); + } + + @Test + public void testDomainDeprecated() { assertEquals(Identity.Type.DOMAIN, DOMAIN.type()); assertEquals("google.com", DOMAIN.value()); } @@ -99,7 +135,7 @@ public void testIdentityToAndFromPb() { private void compareIdentities(Identity expected, Identity actual) { assertEquals(expected, actual); - assertEquals(expected.type(), actual.type()); - assertEquals(expected.value(), actual.value()); + assertEquals(expected.getType(), actual.getType()); + assertEquals(expected.getValue(), actual.getValue()); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java index 40db43b61d..2a70b07ac9 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java @@ -31,17 +31,40 @@ public class PageImplTest { .addAll(NEXT_VALUES) .build(); + private static class TestPageFetcher implements PageImpl.NextPageFetcher { + private static final long serialVersionUID = -8316752901403429976L; + + private final PageImpl nextResult; + + TestPageFetcher(PageImpl nextResult) { + this.nextResult = nextResult; + } + + @Override + public Page nextPage() { + return getNextPage(); + } + + @Override + public Page getNextPage() { + return nextResult; + } + } + @Test public void testPage() { final PageImpl nextResult = new PageImpl<>(null, "c", NEXT_VALUES); - PageImpl.NextPageFetcher fetcher = new PageImpl.NextPageFetcher() { - private static final long serialVersionUID = -1714571149183431798L; - - @Override - public PageImpl nextPage() { - return nextResult; - } - }; + PageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); + PageImpl result = new PageImpl<>(fetcher, "c", VALUES); + assertEquals(nextResult, result.getNextPage()); + assertEquals("c", result.getNextPageCursor()); + assertEquals(VALUES, result.getValues()); + } + + @Test + public void testPageDeprecated() { + final PageImpl nextResult = new PageImpl<>(null, "c", NEXT_VALUES); + PageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); PageImpl result = new PageImpl<>(fetcher, "c", VALUES); assertEquals(nextResult, result.nextPage()); assertEquals("c", result.nextPageCursor()); @@ -51,12 +74,7 @@ public PageImpl nextPage() { @Test public void testIterateAll() { final PageImpl nextResult = new PageImpl<>(null, "c", NEXT_VALUES); - PageImpl.NextPageFetcher fetcher = new PageImpl.NextPageFetcher() { - @Override - public PageImpl nextPage() { - return nextResult; - } - }; + PageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); PageImpl result = new PageImpl<>(fetcher, "c", VALUES); assertEquals(ALL_VALUES, ImmutableList.copyOf(result.iterateAll())); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java b/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java index 946c5584d5..29583e6482 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java @@ -51,31 +51,78 @@ public class PolicyTest { ImmutableSet.of(USER, SERVICE_ACCOUNT, ALL_USERS), EDITOR, ImmutableSet.of(ALL_AUTH_USERS, GROUP, DOMAIN)); - private static final Policy SIMPLE_POLICY = Policy.builder() + private static final Policy SIMPLE_POLICY = Policy.newBuilder() .addIdentity(VIEWER, USER, SERVICE_ACCOUNT, ALL_USERS) .addIdentity(EDITOR, ALL_AUTH_USERS, GROUP, DOMAIN) .build(); - private static final Policy FULL_POLICY = Policy.builder() - .bindings(SIMPLE_POLICY.bindings()) + private static final Policy DEPRECATED_SIMPLE_POLICY = Policy.builder() + .addIdentity(VIEWER, USER, SERVICE_ACCOUNT, ALL_USERS) + .addIdentity(EDITOR, ALL_AUTH_USERS, GROUP, DOMAIN) + .build(); + private static final Policy FULL_POLICY = Policy.newBuilder() + .setBindings(SIMPLE_POLICY.getBindings()) + .setEtag("etag") + .setVersion(1) + .build(); + private static final Policy DEPRECATED_FULL_POLICY = Policy.builder() + .bindings(SIMPLE_POLICY.getBindings()) .etag("etag") .version(1) .build(); @Test public void testBuilder() { - assertEquals(BINDINGS, SIMPLE_POLICY.bindings()); - assertEquals(null, SIMPLE_POLICY.etag()); - assertEquals(0, SIMPLE_POLICY.version()); - assertEquals(BINDINGS, FULL_POLICY.bindings()); - assertEquals("etag", FULL_POLICY.etag()); - assertEquals(1, FULL_POLICY.version()); + assertEquals(BINDINGS, SIMPLE_POLICY.getBindings()); + assertEquals(null, SIMPLE_POLICY.getEtag()); + assertEquals(0, SIMPLE_POLICY.getVersion()); + assertEquals(BINDINGS, FULL_POLICY.getBindings()); + assertEquals("etag", FULL_POLICY.getEtag()); + assertEquals(1, FULL_POLICY.getVersion()); Map> editorBinding = ImmutableMap.>builder().put(EDITOR, BINDINGS.get(EDITOR)).build(); - Policy policy = FULL_POLICY.toBuilder().bindings(editorBinding).build(); + Policy policy = FULL_POLICY.toBuilder().setBindings(editorBinding).build(); + assertEquals(editorBinding, policy.getBindings()); + assertEquals("etag", policy.getEtag()); + assertEquals(1, policy.getVersion()); + policy = SIMPLE_POLICY.toBuilder().removeRole(EDITOR).build(); + assertEquals(ImmutableMap.of(VIEWER, BINDINGS.get(VIEWER)), policy.getBindings()); + assertNull(policy.getEtag()); + assertEquals(0, policy.getVersion()); + policy = policy.toBuilder() + .removeIdentity(VIEWER, USER, ALL_USERS) + .addIdentity(VIEWER, DOMAIN, GROUP) + .build(); + assertEquals(ImmutableMap.of(VIEWER, ImmutableSet.of(SERVICE_ACCOUNT, DOMAIN, GROUP)), + policy.getBindings()); + assertNull(policy.getEtag()); + assertEquals(0, policy.getVersion()); + policy = Policy.newBuilder() + .removeIdentity(VIEWER, USER) + .addIdentity(OWNER, USER, SERVICE_ACCOUNT) + .addIdentity(EDITOR, GROUP) + .removeIdentity(EDITOR, GROUP) + .build(); + assertEquals(ImmutableMap.of(OWNER, ImmutableSet.of(USER, SERVICE_ACCOUNT)), + policy.getBindings()); + assertNull(policy.getEtag()); + assertEquals(0, policy.getVersion()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(BINDINGS, DEPRECATED_SIMPLE_POLICY.bindings()); + assertEquals(null, DEPRECATED_SIMPLE_POLICY.etag()); + assertEquals(0, DEPRECATED_SIMPLE_POLICY.version()); + assertEquals(BINDINGS, DEPRECATED_FULL_POLICY.bindings()); + assertEquals("etag", DEPRECATED_FULL_POLICY.etag()); + assertEquals(1, DEPRECATED_FULL_POLICY.version()); + Map> editorBinding = + ImmutableMap.>builder().put(EDITOR, BINDINGS.get(EDITOR)).build(); + Policy policy = DEPRECATED_FULL_POLICY.toBuilder().bindings(editorBinding).build(); assertEquals(editorBinding, policy.bindings()); assertEquals("etag", policy.etag()); assertEquals(1, policy.version()); - policy = SIMPLE_POLICY.toBuilder().removeRole(EDITOR).build(); + policy = DEPRECATED_SIMPLE_POLICY.toBuilder().removeRole(EDITOR).build(); assertEquals(ImmutableMap.of(VIEWER, BINDINGS.get(VIEWER)), policy.bindings()); assertNull(policy.etag()); assertEquals(0, policy.version()); @@ -101,25 +148,25 @@ public void testBuilder() { @Test public void testIllegalPolicies() { try { - Policy.builder().addIdentity(null, USER); + Policy.newBuilder().addIdentity(null, USER); fail("Null role should cause exception."); } catch (NullPointerException ex) { assertEquals("The role cannot be null.", ex.getMessage()); } try { - Policy.builder().addIdentity(VIEWER, null, USER); + Policy.newBuilder().addIdentity(VIEWER, null, USER); fail("Null identity should cause exception."); } catch (NullPointerException ex) { assertEquals("Null identities are not permitted.", ex.getMessage()); } try { - Policy.builder().addIdentity(VIEWER, USER, (Identity[]) null); + Policy.newBuilder().addIdentity(VIEWER, USER, (Identity[]) null); fail("Null identity should cause exception."); } catch (NullPointerException ex) { assertEquals("Null identities are not permitted.", ex.getMessage()); } try { - Policy.builder().bindings(null); + Policy.newBuilder().setBindings(null); fail("Null bindings map should cause exception."); } catch (NullPointerException ex) { assertEquals("The provided map of bindings cannot be null.", ex.getMessage()); @@ -127,7 +174,7 @@ public void testIllegalPolicies() { try { Map> bindings = new HashMap<>(); bindings.put(VIEWER, null); - Policy.builder().bindings(bindings); + Policy.newBuilder().setBindings(bindings); fail("Null set of identities should cause exception."); } catch (NullPointerException ex) { assertEquals("A role cannot be assigned to a null set of identities.", ex.getMessage()); @@ -137,7 +184,7 @@ public void testIllegalPolicies() { Set identities = new HashSet<>(); identities.add(null); bindings.put(VIEWER, identities); - Policy.builder().bindings(bindings); + Policy.newBuilder().setBindings(bindings); fail("Null identity should cause exception."); } catch (IllegalArgumentException ex) { assertEquals("Null identities are not permitted.", ex.getMessage()); @@ -147,8 +194,8 @@ public void testIllegalPolicies() { @Test public void testEqualsHashCode() { assertNotNull(FULL_POLICY); - Policy emptyPolicy = Policy.builder().build(); - Policy anotherPolicy = Policy.builder().build(); + Policy emptyPolicy = Policy.newBuilder().build(); + Policy anotherPolicy = Policy.newBuilder().build(); assertEquals(emptyPolicy, anotherPolicy); assertEquals(emptyPolicy.hashCode(), anotherPolicy.hashCode()); assertNotEquals(FULL_POLICY, SIMPLE_POLICY); @@ -160,33 +207,33 @@ public void testEqualsHashCode() { @Test public void testBindings() { - assertTrue(Policy.builder().build().bindings().isEmpty()); - assertEquals(BINDINGS, SIMPLE_POLICY.bindings()); + assertTrue(Policy.newBuilder().build().getBindings().isEmpty()); + assertEquals(BINDINGS, SIMPLE_POLICY.getBindings()); } @Test public void testEtag() { - assertNull(SIMPLE_POLICY.etag()); - assertEquals("etag", FULL_POLICY.etag()); + assertNull(SIMPLE_POLICY.getEtag()); + assertEquals("etag", FULL_POLICY.getEtag()); } @Test public void testVersion() { - assertEquals(0, SIMPLE_POLICY.version()); - assertEquals(1, FULL_POLICY.version()); + assertEquals(0, SIMPLE_POLICY.getVersion()); + assertEquals(1, FULL_POLICY.getVersion()); } @Test public void testDefaultMarshaller() { DefaultMarshaller marshaller = new DefaultMarshaller(); - Policy emptyPolicy = Policy.builder().build(); + Policy emptyPolicy = Policy.newBuilder().build(); assertEquals(emptyPolicy, marshaller.fromPb(marshaller.toPb(emptyPolicy))); assertEquals(SIMPLE_POLICY, marshaller.fromPb(marshaller.toPb(SIMPLE_POLICY))); assertEquals(FULL_POLICY, marshaller.fromPb(marshaller.toPb(FULL_POLICY))); com.google.iam.v1.Policy policyPb = com.google.iam.v1.Policy.getDefaultInstance(); Policy policy = marshaller.fromPb(policyPb); - assertTrue(policy.bindings().isEmpty()); - assertNull(policy.etag()); - assertEquals(0, policy.version()); + assertTrue(policy.getBindings().isEmpty()); + assertNull(policy.getEtag()); + assertEquals(0, policy.getVersion()); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java index fcb404a462..987cf1daa1 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java @@ -58,6 +58,51 @@ static class E4Exception extends E2Exception { @Test public void testTriesWithExceptionHandling() { + assertNull(RetryHelper.getContext()); + RetryParams params = + RetryParams.newBuilder().setInitialRetryDelayMillis(0).setRetryMaxAttempts(3).build(); + ExceptionHandler handler = ExceptionHandler.newBuilder() + .retryOn(IOException.class).abortOn(RuntimeException.class).build(); + final AtomicInteger count = new AtomicInteger(3); + try { + RetryHelper.runWithRetries(new Callable() { + @Override public Void call() throws IOException, NullPointerException { + if (count.decrementAndGet() == 2) { + assertEquals(1, RetryHelper.getContext().getAttemptNumber()); + throw new IOException("should be retried"); + } + assertEquals(2, RetryHelper.getContext().getAttemptNumber()); + throw new NullPointerException("Boo!"); + } + }, params, handler); + fail("Exception should have been thrown"); + } catch (NonRetriableException ex) { + assertEquals("Boo!", ex.getCause().getMessage()); + assertEquals(1, count.intValue()); + } + assertNull(RetryHelper.getContext()); + + params = RetryParams.newBuilder().setInitialRetryDelayMillis(0).setRetryMaxAttempts(5).build(); + handler = ExceptionHandler.newBuilder() + .retryOn(E1Exception.class, E4Exception.class) + .abortOn(E3Exception.class).build(); + final Iterator exceptions = Arrays.asList( + new E1Exception(), new E2Exception(), new E4Exception(), new E3Exception()).iterator(); + try { + RetryHelper.runWithRetries(new Callable() { + @Override public Void call() throws E1Exception { + throw exceptions.next(); + } + }, params, handler); + fail("Exception should have been thrown"); + } catch (NonRetriableException ex) { + assertTrue(ex.getCause() instanceof E3Exception); + } + assertNull(RetryHelper.getContext()); + } + + @Test + public void testTriesWithExceptionHandlingDeprecated() { assertNull(RetryHelper.getContext()); RetryParams params = RetryParams.builder().initialRetryDelayMillis(0).retryMaxAttempts(3).build(); @@ -103,6 +148,32 @@ public void testTriesWithExceptionHandling() { @Test public void testTriesAtLeastMinTimes() { + // Total retry period set to 60 seconds so as to not factor into test + RetryParams params = RetryParams.newBuilder().setInitialRetryDelayMillis(0) + .setTotalRetryPeriodMillis(60000) + .setRetryMinAttempts(5) + .setRetryMaxAttempts(10) + .build(); + final int timesToFail = 7; + assertNull(RetryHelper.getContext()); + int attempted = RetryHelper.runWithRetries(new Callable() { + int timesCalled; + @Override public Integer call() throws IOException { + timesCalled++; + assertEquals(timesCalled, RetryHelper.getContext().getAttemptNumber()); + assertEquals(10, RetryHelper.getContext().getRetryParams().getRetryMaxAttempts()); + if (timesCalled <= timesToFail) { + throw new IOException(); + } + return timesCalled; + } + }, params, ExceptionHandler.getDefaultInstance()); + assertEquals(timesToFail + 1, attempted); + assertNull(RetryHelper.getContext()); + } + + @Test + public void testTriesAtLeastMinTimesDeprecated() { // Total retry period set to 60 seconds so as to not factor into test RetryParams params = RetryParams.builder().initialRetryDelayMillis(0) .totalRetryPeriodMillis(60000) @@ -129,6 +200,34 @@ public void testTriesAtLeastMinTimes() { @Test public void testTriesNoMoreThanMaxTimes() { + // Total retry period set to 60 seconds so as to not factor into test + final int maxAttempts = 10; + RetryParams params = RetryParams.newBuilder().setInitialRetryDelayMillis(0) + .setTotalRetryPeriodMillis(60000) + .setRetryMinAttempts(0) + .setRetryMaxAttempts(maxAttempts) + .build(); + final AtomicInteger timesCalled = new AtomicInteger(0); + try { + RetryHelper.runWithRetries(callable(new Runnable() { + @Override public void run() { + // Throw an exception up to maxAttempts times, should never be called beyond that + if (timesCalled.incrementAndGet() <= maxAttempts) { + throw new RuntimeException(); + } + fail("Body was executed too many times: " + timesCalled.get()); + } + }), params, ExceptionHandler.newBuilder().retryOn(RuntimeException.class).build()); + // Unnecessary as this line should not be possible reach even if RetryHandler is broken + fail("Should not have succeeded, expected all attempts to fail and give up."); + } catch (RetriesExhaustedException expected) { + // Expect the body to run exactly maxAttempts times + assertEquals(maxAttempts, timesCalled.get()); + } + } + + @Test + public void testTriesNoMoreThanMaxTimesDeprecated() { // Total retry period set to 60 seconds so as to not factor into test final int maxAttempts = 10; RetryParams params = RetryParams.builder().initialRetryDelayMillis(0) @@ -175,12 +274,12 @@ public void testTriesNoMoreLongerThanTotalRetryPeriod() { final FakeClock fakeClock = new FakeClock(); // The 8th attempt (after min and before max) will trigger a 1 second (virtual) delay exceeding // total retry period which is set just under 1 second. Test occurs faster than realtime. - RetryParams params = RetryParams.builder().initialRetryDelayMillis(0) - .totalRetryPeriodMillis(999) - .retryMinAttempts(5) - .retryMaxAttempts(10) + RetryParams params = RetryParams.newBuilder().setInitialRetryDelayMillis(0) + .setTotalRetryPeriodMillis(999) + .setRetryMinAttempts(5) + .setRetryMaxAttempts(10) .build(); - ExceptionHandler handler = ExceptionHandler.builder().retryOn(RuntimeException.class).build(); + ExceptionHandler handler = ExceptionHandler.newBuilder().retryOn(RuntimeException.class).build(); final int sleepOnAttempt = 8; final AtomicInteger timesCalled = new AtomicInteger(0); try { @@ -203,13 +302,13 @@ public void testTriesNoMoreLongerThanTotalRetryPeriod() { @Test public void testBackoffIsExponential() { // Total retry period set to 60 seconds so as to not factor into test - RetryParams params = RetryParams.builder() - .initialRetryDelayMillis(10) - .maxRetryDelayMillis(10_000_000) - .retryDelayBackoffFactor(2) - .totalRetryPeriodMillis(60_000) - .retryMinAttempts(0) - .retryMaxAttempts(100) + RetryParams params = RetryParams.newBuilder() + .setInitialRetryDelayMillis(10) + .setMaxRetryDelayMillis(10_000_000) + .setRetryDelayBackoffFactor(2) + .setTotalRetryPeriodMillis(60_000) + .setRetryMinAttempts(0) + .setRetryMaxAttempts(100) .build(); long sleepDuration = RetryHelper.getSleepDuration(params, 1); assertTrue(String.valueOf(sleepDuration), sleepDuration < 13 && sleepDuration >= 7); diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java index c304105311..c963580429 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java @@ -41,6 +41,20 @@ public class RetryParamsTest { @Test public void testDefaults() { + RetryParams params1 = RetryParams.getDefaultInstance(); + RetryParams params2 = RetryParams.newBuilder().build(); + for (RetryParams params : Arrays.asList(params1, params2)) { + assertEquals(DEFAULT_INITIAL_RETRY_DELAY_MILLIS, params.getInitialRetryDelayMillis()); + assertEquals(DEFAULT_MAX_RETRY_DELAY_MILLIS, params.getMaxRetryDelayMillis()); + assertEquals(DEFAULT_RETRY_DELAY_BACKOFF_FACTOR, params.getRetryDelayBackoffFactor(), 0); + assertEquals(DEFAULT_RETRY_MAX_ATTEMPTS, params.getRetryMaxAttempts()); + assertEquals(DEFAULT_RETRY_MIN_ATTEMPTS, params.getRetryMinAttempts()); + assertEquals(DEFAULT_TOTAL_RETRY_PERIOD_MILLIS, params.getTotalRetryPeriodMillis()); + } + } + + @Test + public void testDefaultsDeprecated() { RetryParams params1 = RetryParams.defaultInstance(); RetryParams params2 = RetryParams.builder().build(); for (RetryParams params : Arrays.asList(params1, params2)) { @@ -55,6 +69,27 @@ public void testDefaults() { @Test public void testSetAndCopy() { + RetryParams.Builder builder = RetryParams.newBuilder(); + builder.setInitialRetryDelayMillis(101); + builder.setMaxRetryDelayMillis(102); + builder.setRetryDelayBackoffFactor(103); + builder.setRetryMinAttempts(107); + builder.setRetryMaxAttempts(108); + builder.setTotalRetryPeriodMillis(109); + RetryParams params1 = builder.build(); + RetryParams params2 = new RetryParams.Builder(params1).build(); + for (RetryParams params : Arrays.asList(params1, params2)) { + assertEquals(101, params.getInitialRetryDelayMillis()); + assertEquals(102, params.getMaxRetryDelayMillis()); + assertEquals(103, params.getRetryDelayBackoffFactor(), 0); + assertEquals(107, params.getRetryMinAttempts()); + assertEquals(108, params.getRetryMaxAttempts()); + assertEquals(109, params.getTotalRetryPeriodMillis()); + } + } + + @Test + public void testSetAndCopyDeprecated() { RetryParams.Builder builder = RetryParams.builder(); builder.initialRetryDelayMillis(101); builder.maxRetryDelayMillis(102); @@ -76,22 +111,23 @@ public void testSetAndCopy() { @Test public void testBadSettings() { - RetryParams.Builder builder = RetryParams.builder(); - builder.initialRetryDelayMillis(-1); + RetryParams.Builder builder = RetryParams.newBuilder(); + builder.setInitialRetryDelayMillis(-1); builder = assertFailure(builder); - builder.maxRetryDelayMillis(RetryParams.defaultInstance().initialRetryDelayMillis() - 1); + builder.setMaxRetryDelayMillis( + RetryParams.getDefaultInstance().getInitialRetryDelayMillis() - 1); builder = assertFailure(builder); - builder.retryDelayBackoffFactor(-1); + builder.setRetryDelayBackoffFactor(-1); builder = assertFailure(builder); - builder.retryMinAttempts(-1); + builder.setRetryMinAttempts(-1); builder = assertFailure(builder); - builder.retryMaxAttempts(RetryParams.defaultInstance().retryMinAttempts() - 1); + builder.setRetryMaxAttempts(RetryParams.getDefaultInstance().getRetryMinAttempts() - 1); builder = assertFailure(builder); - builder.totalRetryPeriodMillis(-1); + builder.setTotalRetryPeriodMillis(-1); builder = assertFailure(builder); // verify that it is OK for min and max to be equal - builder.retryMaxAttempts(RetryParams.defaultInstance().retryMinAttempts()); - builder.maxRetryDelayMillis(RetryParams.defaultInstance().initialRetryDelayMillis()); + builder.setRetryMaxAttempts(RetryParams.getDefaultInstance().getRetryMinAttempts()); + builder.setMaxRetryDelayMillis(RetryParams.getDefaultInstance().getInitialRetryDelayMillis()); builder.build(); } @@ -102,6 +138,6 @@ private static Builder assertFailure(Builder builder) { } catch (IllegalArgumentException ex) { // expected } - return RetryParams.builder(); + return RetryParams.newBuilder(); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java index c66c28a952..7cce4ee4fb 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java @@ -28,6 +28,16 @@ public class RoleTest { @Test public void testOf() { + assertEquals("roles/viewer", VIEWER.getValue()); + assertEquals("roles/editor", EDITOR.getValue()); + assertEquals("roles/owner", OWNER.getValue()); + compareRoles(VIEWER, Role.of("roles/viewer")); + compareRoles(EDITOR, Role.of("roles/editor")); + compareRoles(OWNER, Role.of("roles/owner")); + } + + @Test + public void testOfDeprecated() { assertEquals("roles/viewer", VIEWER.value()); assertEquals("roles/editor", EDITOR.value()); assertEquals("roles/owner", OWNER.value()); @@ -38,17 +48,17 @@ public void testOf() { @Test public void testViewer() { - assertEquals("roles/viewer", Role.viewer().value()); + assertEquals("roles/viewer", Role.viewer().getValue()); } @Test public void testEditor() { - assertEquals("roles/editor", Role.editor().value()); + assertEquals("roles/editor", Role.editor().getValue()); } @Test public void testOwner() { - assertEquals("roles/owner", Role.owner().value()); + assertEquals("roles/owner", Role.owner().getValue()); } @Test(expected = NullPointerException.class) @@ -58,7 +68,7 @@ public void testOfNullValue() { private void compareRoles(Role expected, Role actual) { assertEquals(expected, actual); - assertEquals(expected.value(), actual.value()); + assertEquals(expected.getValue(), actual.getValue()); assertEquals(expected.hashCode(), actual.hashCode()); assertEquals(expected.toString(), actual.toString()); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index ba3194c203..746f2b406b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -32,15 +32,15 @@ public class SerializationTest extends BaseSerializationTest { private static final BaseServiceException BASE_SERVICE_EXCEPTION = new BaseServiceException(42, "message", "reason", true); - private static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.defaultInstance(); + private static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.getDefaultInstance(); private static final Identity IDENTITY = Identity.allAuthenticatedUsers(); private static final PageImpl PAGE = new PageImpl<>(null, "cursor", ImmutableList.of("string1", "string2")); private static final SigningException SIGNING_EXCEPTION = new SigningException("message", BASE_SERVICE_EXCEPTION); - private static final RetryParams RETRY_PARAMS = RetryParams.defaultInstance(); + private static final RetryParams RETRY_PARAMS = RetryParams.getDefaultInstance(); private static final Role SOME_ROLE = Role.viewer(); - private static final Policy SOME_IAM_POLICY = Policy.builder().build(); + private static final Policy SOME_IAM_POLICY = Policy.newBuilder().build(); private static final WaitForOption CHECKING_PERIOD = WaitForOption.checkEvery(42, TimeUnit.SECONDS); private static final LabelDescriptor LABEL_DESCRIPTOR = diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 7792c63e82..e7e74459d1 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -71,7 +71,15 @@ public class ServiceOptionsTest { } private static final Clock TEST_CLOCK = new TestClock(); private static final TestServiceOptions OPTIONS = - TestServiceOptions.builder() + TestServiceOptions.newBuilder() + .setAuthCredentials(authCredentials) + .setClock(TEST_CLOCK) + .setHost("host") + .setProjectId("project-id") + .setRetryParams(RetryParams.noRetries()) + .build(); + private static final TestServiceOptions DEPRECATED_OPTIONS = + TestServiceOptions.newBuilder() .authCredentials(authCredentials) .clock(TEST_CLOCK) .host("host") @@ -79,7 +87,9 @@ public class ServiceOptionsTest { .retryParams(RetryParams.noRetries()) .build(); private static final TestServiceOptions DEFAULT_OPTIONS = - TestServiceOptions.builder().projectId("project-id").build(); + TestServiceOptions.newBuilder().setProjectId("project-id").build(); + private static final TestServiceOptions DEPRECATED_DEFAULT_OPTIONS = + TestServiceOptions.newBuilder().projectId("project-id").build(); private static final TestServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); private static final String LIBRARY_NAME = "gcloud-java"; private static final Pattern APPLICATION_NAME_PATTERN = @@ -151,17 +161,17 @@ private TestServiceOptions(Builder builder) { } @Override - protected TestServiceFactory defaultServiceFactory() { + protected TestServiceFactory getDefaultServiceFactory() { return DefaultTestServiceFactory.INSTANCE; } @Override - protected TestServiceRpcFactory defaultRpcFactory() { + protected TestServiceRpcFactory getDefaultRpcFactory() { return DefaultTestServiceRpcFactory.INSTANCE; } @Override - protected Set scopes() { + protected Set getScopes() { return null; } @@ -170,7 +180,7 @@ public Builder toBuilder() { return new Builder(this); } - private static Builder builder() { + private static Builder newBuilder() { return new Builder(); } @@ -187,14 +197,26 @@ public int hashCode() { @Test public void testBuilder() { - assertSame(authCredentials, OPTIONS.authCredentials()); - assertSame(TEST_CLOCK, OPTIONS.clock()); - assertEquals("host", OPTIONS.host()); - assertEquals("project-id", OPTIONS.projectId()); - assertSame(RetryParams.noRetries(), OPTIONS.retryParams()); - assertSame(Clock.defaultClock(), DEFAULT_OPTIONS.clock()); - assertEquals("https://www.googleapis.com", DEFAULT_OPTIONS.host()); - assertSame(RetryParams.defaultInstance(), DEFAULT_OPTIONS.retryParams()); + assertSame(authCredentials, OPTIONS.getAuthCredentials()); + assertSame(TEST_CLOCK, OPTIONS.getClock()); + assertEquals("host", OPTIONS.getHost()); + assertEquals("project-id", OPTIONS.getProjectId()); + assertSame(RetryParams.noRetries(), OPTIONS.getRetryParams()); + assertSame(Clock.defaultClock(), DEFAULT_OPTIONS.getClock()); + assertEquals("https://www.googleapis.com", DEFAULT_OPTIONS.getHost()); + assertSame(RetryParams.getDefaultInstance(), DEFAULT_OPTIONS.getRetryParams()); + } + + @Test + public void testBuilderDeprecated() { + assertSame(authCredentials, DEPRECATED_OPTIONS.authCredentials()); + assertSame(TEST_CLOCK, DEPRECATED_OPTIONS.clock()); + assertEquals("host", DEPRECATED_OPTIONS.host()); + assertEquals("project-id", DEPRECATED_OPTIONS.projectId()); + assertSame(RetryParams.noRetries(), DEPRECATED_OPTIONS.retryParams()); + assertSame(Clock.defaultClock(), DEPRECATED_DEFAULT_OPTIONS.clock()); + assertEquals("https://www.googleapis.com", DEPRECATED_DEFAULT_OPTIONS.host()); + assertSame(RetryParams.getDefaultInstance(), DEPRECATED_DEFAULT_OPTIONS.retryParams()); } @Test @@ -204,12 +226,12 @@ public void testGetProjectIdRequired() { @Test public void testService() { - assertTrue(OPTIONS.service() instanceof TestServiceImpl); + assertTrue(OPTIONS.getService() instanceof TestServiceImpl); } @Test public void testRpc() { - assertTrue(OPTIONS.rpc() instanceof DefaultTestServiceRpc); + assertTrue(OPTIONS.getRpc() instanceof DefaultTestServiceRpc); } @Test @@ -220,12 +242,12 @@ public void testBaseEquals() { @Test public void testLibraryName() { - assertEquals(LIBRARY_NAME, OPTIONS.libraryName()); + assertEquals(LIBRARY_NAME, OPTIONS.getLibraryName()); } @Test public void testApplicationName() { - assertTrue(APPLICATION_NAME_PATTERN.matcher(OPTIONS.applicationName()).matches()); + assertTrue(APPLICATION_NAME_PATTERN.matcher(OPTIONS.getApplicationName()).matches()); } @Test diff --git a/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java index 82996e1ca3..959b086aed 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java @@ -40,7 +40,14 @@ public class WaitForOptionTest { @Test public void testCheckEvery() { - assertEquals(OptionType.CHECKING_PERIOD, CHECKING_PERIOD_OPTION.optionType()); + assertEquals(OptionType.CHECKING_PERIOD, CHECKING_PERIOD_OPTION.getOptionType()); + assertEquals(42, CHECKING_PERIOD_OPTION.getPeriod()); + assertEquals(TimeUnit.MILLISECONDS, CHECKING_PERIOD_OPTION.getUnit()); + } + + @Test + public void testCheckEveryDeprecated() { + assertEquals(OptionType.CHECKING_PERIOD, CHECKING_PERIOD_OPTION.getOptionType()); assertEquals(42, CHECKING_PERIOD_OPTION.period()); assertEquals(TimeUnit.MILLISECONDS, CHECKING_PERIOD_OPTION.unit()); } @@ -53,8 +60,8 @@ public void testCheckEvery_InvalidPeriod() { } @Test - public void testTimeout() { - assertEquals(OptionType.TIMEOUT, TIMEOUT_OPTION.optionType()); + public void testTimeoutDeprecated() { + assertEquals(OptionType.TIMEOUT, TIMEOUT_OPTION.getOptionType()); assertEquals(43, TIMEOUT_OPTION.timeoutMillis()); Timeout timeoutOption = WaitForOption.timeout(43, TimeUnit.SECONDS); assertEquals(43_000, timeoutOption.timeoutMillis()); @@ -102,10 +109,10 @@ public void testGetOrDefault() { assertEquals(TIMEOUT_OPTION, Timeout.getOrDefault(CHECKING_PERIOD_OPTION, TIMEOUT_OPTION)); CheckingPeriod checkingPeriod = CheckingPeriod.getOrDefault(TIMEOUT_OPTION); - assertEquals(500, checkingPeriod.period()); - assertEquals(TimeUnit.MILLISECONDS, checkingPeriod.unit()); + assertEquals(500, checkingPeriod.getPeriod()); + assertEquals(TimeUnit.MILLISECONDS, checkingPeriod.getUnit()); Timeout timeout = Timeout.getOrDefault(CHECKING_PERIOD_OPTION); - assertEquals(-1, timeout.timeoutMillis()); + assertEquals(-1, timeout.getTimeoutMillis()); } @Test From fc1e0d8abdce44b6b7b82a375cc5715e060424b0 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Sat, 29 Oct 2016 16:25:42 +0200 Subject: [PATCH 233/663] Release 0.5.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1ea4eb6cce..ec6c284be5 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.4.1-SNAPSHOT + 0.5.0 google-cloud-core From f96de21eb8ea8303ca4de23516aac3ab351fe18b Mon Sep 17 00:00:00 2001 From: travis-ci Date: Sat, 29 Oct 2016 17:20:07 +0000 Subject: [PATCH 234/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index aabe170ffe..e727be8f53 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.4.0 + 0.5.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.4.0' +compile 'com.google.cloud:google-cloud-core:0.5.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.4.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.5.0" ``` Troubleshooting From bd2a0c80c67719ab2259990b2c36ae1a8564d26b Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Sat, 29 Oct 2016 23:48:37 +0200 Subject: [PATCH 235/663] Update version to 0.5.1-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index ec6c284be5..a79ffb8ea9 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.5.0 + 0.5.1-SNAPSHOT google-cloud-core From 50f07ae2609cef3b9e7531f824e8b3d22004afac Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 4 Nov 2016 09:53:42 +0100 Subject: [PATCH 236/663] Reduce gRPC dependency footprint, get rid of duplicate classes (#1365) * Reduce gRPC dependency footprint, get rid of duplicate classes * Wrap grpc version inside a pom.xml property --- google-cloud-core/pom.xml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a79ffb8ea9..ae3403cff3 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -103,20 +103,43 @@ protobuf-java 3.0.0 + + io.grpc + grpc-protobuf + ${grpc.version} + com.google.api gax 0.0.21 + + + io.grpc + grpc-all + + com.google.api.grpc grpc-google-common-protos 0.1.0 + + + io.grpc + grpc-all + + com.google.api.grpc grpc-google-iam-v1 0.1.0 + + + io.grpc + grpc-all + + From f6eb175d26b38c7262f41403b9be69ed84b905bc Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 4 Nov 2016 14:26:29 +0100 Subject: [PATCH 237/663] Release 0.5.1 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index ae3403cff3..3fcdcfd556 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.5.1-SNAPSHOT + 0.5.1 google-cloud-core From 78e967187a1f70841778996fb10d2f15954e8ead Mon Sep 17 00:00:00 2001 From: travis-ci Date: Fri, 4 Nov 2016 14:37:58 +0000 Subject: [PATCH 238/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index e727be8f53..1665163a9f 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.5.0 + 0.5.1 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.5.0' +compile 'com.google.cloud:google-cloud-core:0.5.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.5.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.5.1" ``` Troubleshooting From 7dce2efacd8e696ec6c0369f5fe3da3f6d3e32a9 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Sun, 6 Nov 2016 20:12:27 +0100 Subject: [PATCH 239/663] Update version to 0.5.2-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3fcdcfd556..116007ee3d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.5.1 + 0.5.2-SNAPSHOT google-cloud-core From 9426aef05b771632ade6fb051eb756ca71992ec6 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 8 Nov 2016 10:42:25 +0100 Subject: [PATCH 240/663] Remove AuthCredentials and related classes, use google-auth-library-java instead (#1375) * Remove AuthCredentials and related classes, use google-auth-library-java instead * Throw NPE when setCredentials is called with null * Fix wording in main README's Authentication section * Add NoCredentials class and remove setNoCredentials method --- google-cloud-core/pom.xml | 4 +- .../com/google/cloud/AuthCredentials.java | 606 ------------------ .../com/google/cloud/GrpcServiceOptions.java | 10 +- .../com/google/cloud/HttpServiceOptions.java | 21 +- .../java/com/google/cloud/NoCredentials.java | 41 ++ .../google/cloud/ServiceAccountSigner.java | 73 --- .../java/com/google/cloud/ServiceOptions.java | 72 +-- .../com/google/cloud/AuthCredentialsTest.java | 168 ----- .../google/cloud/HttpServiceOptionsTest.java | 2 +- .../com/google/cloud/SerializationTest.java | 19 +- .../com/google/cloud/ServiceOptionsTest.java | 41 +- 11 files changed, 124 insertions(+), 933 deletions(-) delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java delete mode 100644 google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 116007ee3d..cb46970a79 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -20,12 +20,12 @@ com.google.auth google-auth-library-credentials - 0.3.1 + ${google.auth.version} com.google.auth google-auth-library-oauth2-http - 0.3.1 + ${google.auth.version} com.google.guava diff --git a/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java b/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java deleted file mode 100644 index 257e801c6f..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/AuthCredentials.java +++ /dev/null @@ -1,606 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.auth.oauth2.AccessToken; -import com.google.auth.oauth2.GoogleCredentials; -import com.google.auth.oauth2.ServiceAccountCredentials; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.Signature; -import java.security.SignatureException; -import java.util.Collection; -import java.util.Date; -import java.util.Objects; - -/** - * Credentials for accessing Google Cloud services. - */ -public abstract class AuthCredentials implements Restorable { - - /** - * Represents built-in credentials when running in Google App Engine. - */ - public static class AppEngineAuthCredentials extends AuthCredentials - implements ServiceAccountSigner { - - private static final AuthCredentials INSTANCE = new AppEngineAuthCredentials(); - private static final AppEngineAuthCredentialsState STATE = new AppEngineAuthCredentialsState(); - - private AppEngineCredentials credentials; - - private static class AppEngineCredentials extends GoogleCredentials - implements ServiceAccountSigner { - - private final Object appIdentityService; - private final String account; - private final Method getAccessToken; - private final Method getAccessTokenResult; - private final Method getExpirationTime; - private final Method signForApp; - private final Method getSignature; - private final Collection scopes; - - AppEngineCredentials() { - try { - Class factoryClass = - Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory"); - Method method = factoryClass.getMethod("getAppIdentityService"); - this.appIdentityService = method.invoke(null); - Class serviceClass = - Class.forName("com.google.appengine.api.appidentity.AppIdentityService"); - Class tokenResultClass = Class.forName( - "com.google.appengine.api.appidentity.AppIdentityService$GetAccessTokenResult"); - this.getAccessTokenResult = serviceClass.getMethod("getAccessToken", Iterable.class); - this.getAccessToken = tokenResultClass.getMethod("getAccessToken"); - this.getExpirationTime = tokenResultClass.getMethod("getExpirationTime"); - this.account = (String) serviceClass.getMethod("getServiceAccountName") - .invoke(appIdentityService); - this.signForApp = serviceClass.getMethod("signForApp", byte[].class); - Class signingResultClass = Class.forName( - "com.google.appengine.api.appidentity.AppIdentityService$SigningResult"); - this.getSignature = signingResultClass.getMethod("getSignature"); - this.scopes = null; - } catch (Exception e) { - throw new RuntimeException("Could not create AppEngineCredentials.", e); - } - } - - AppEngineCredentials(Collection scopes, AppEngineCredentials unscoped) { - this.appIdentityService = unscoped.appIdentityService; - this.getAccessToken = unscoped.getAccessToken; - this.getAccessTokenResult = unscoped.getAccessTokenResult; - this.getExpirationTime = unscoped.getExpirationTime; - this.account = unscoped.account; - this.signForApp = unscoped.signForApp; - this.getSignature = unscoped.getSignature; - this.scopes = scopes; - } - - /** - * Refresh the access token by getting it from the App Identity service. - */ - @Override - public AccessToken refreshAccessToken() throws IOException { - if (createScopedRequired()) { - throw new IOException("AppEngineCredentials requires createScoped call before use."); - } - try { - Object accessTokenResult = getAccessTokenResult.invoke(appIdentityService, scopes); - String accessToken = (String) getAccessToken.invoke(accessTokenResult); - Date expirationTime = (Date) getExpirationTime.invoke(accessTokenResult); - return new AccessToken(accessToken, expirationTime); - } catch (Exception e) { - throw new IOException("Could not get the access token.", e); - } - } - - @Override - public boolean createScopedRequired() { - return scopes == null || scopes.isEmpty(); - } - - @Override - public GoogleCredentials createScoped(Collection scopes) { - return new AppEngineCredentials(scopes, this); - } - - @Override - public String account() { - return getAccount(); - } - - @Override - public String getAccount() { - return account; - } - - @Override - public byte[] sign(byte[] toSign) { - try { - Object signingResult = signForApp.invoke(appIdentityService, toSign); - return (byte[]) getSignature.invoke(signingResult); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw new SigningException("Failed to sign the provided bytes", ex); - } - } - } - - private static class AppEngineAuthCredentialsState - implements RestorableState, Serializable { - - private static final long serialVersionUID = 3558563960848658928L; - - @Override - public AuthCredentials restore() { - return INSTANCE; - } - - @Override - public int hashCode() { - return getClass().getName().hashCode(); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof AppEngineAuthCredentialsState; - } - } - - @Override - @Deprecated - public AppEngineCredentials credentials() { - return getCredentials(); - } - - @Override - public AppEngineCredentials getCredentials() { - if (credentials == null) { - credentials = new AppEngineCredentials(); - } - return credentials; - } - - @Override - public RestorableState capture() { - return STATE; - } - - @Override - @Deprecated - public String account() { - return getAccount(); - } - - @Override - public String getAccount() { - return getCredentials().getAccount(); - } - - @Override - public byte[] sign(byte[] toSign) { - return getCredentials().sign(toSign); - } - } - - /** - * Represents service account credentials. - * - * @see - * User accounts and service accounts - */ - public static class ServiceAccountAuthCredentials extends AuthCredentials - implements ServiceAccountSigner { - - private final ServiceAccountCredentials credentials; - private final String account; - private final PrivateKey privateKey; - - private static class ServiceAccountAuthCredentialsState - implements RestorableState, Serializable { - - private static final long serialVersionUID = -7302180782414633639L; - - private final String account; - private final PrivateKey privateKey; - - private ServiceAccountAuthCredentialsState(String account, PrivateKey privateKey) { - this.account = account; - this.privateKey = privateKey; - } - - @Override - public AuthCredentials restore() { - return new ServiceAccountAuthCredentials(account, privateKey); - } - - @Override - public int hashCode() { - return Objects.hash(account, privateKey); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ServiceAccountAuthCredentialsState)) { - return false; - } - ServiceAccountAuthCredentialsState other = (ServiceAccountAuthCredentialsState) obj; - return Objects.equals(account, other.account) - && Objects.equals(privateKey, other.privateKey); - } - } - - ServiceAccountAuthCredentials(String account, PrivateKey privateKey) { - this(new ServiceAccountCredentials(null, account, privateKey, null, null)); - } - - ServiceAccountAuthCredentials(ServiceAccountCredentials credentials) { - this.credentials = checkNotNull(credentials); - this.account = checkNotNull(credentials.getClientEmail()); - this.privateKey = checkNotNull(credentials.getPrivateKey()); - } - - @Override - @Deprecated - public ServiceAccountCredentials credentials() { - return getCredentials(); - } - - @Override - public ServiceAccountCredentials getCredentials() { - return credentials; - } - - @Override - @Deprecated - public String account() { - return account; - } - - @Override - public String getAccount() { - return account; - } - - /** - * Returns the private key associated with the service account credentials. - */ - @Deprecated - public PrivateKey privateKey() { - return getPrivateKey(); - } - - /** - * Returns the private key associated with the service account credentials. - */ - public PrivateKey getPrivateKey() { - return privateKey; - } - - @Override - public byte[] sign(byte[] toSign) { - try { - Signature signer = Signature.getInstance("SHA256withRSA"); - signer.initSign(getPrivateKey()); - signer.update(toSign); - return signer.sign(); - } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException ex) { - throw new SigningException("Failed to sign the provided bytes", ex); - } - } - - @Override - public RestorableState capture() { - return new ServiceAccountAuthCredentialsState(account, privateKey); - } - } - - /** - * Represents Application Default Credentials, which are credentials that are inferred from the - * runtime environment. - * - * @see - * Google Application Default Credentials - */ - public static class ApplicationDefaultAuthCredentials extends AuthCredentials { - - private GoogleCredentials googleCredentials; - - private static final ApplicationDefaultAuthCredentialsState STATE = - new ApplicationDefaultAuthCredentialsState(); - - private static class ApplicationDefaultAuthCredentialsState - implements RestorableState, Serializable { - - private static final long serialVersionUID = -8839085552021212257L; - - @Override - public AuthCredentials restore() { - try { - return new ApplicationDefaultAuthCredentials(); - } catch (IOException e) { - throw new IllegalStateException( - "Could not restore " + ApplicationDefaultAuthCredentials.class.getSimpleName(), e); - } - } - - @Override - public int hashCode() { - return getClass().getName().hashCode(); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof ApplicationDefaultAuthCredentialsState; - } - } - - ApplicationDefaultAuthCredentials(GoogleCredentials credentials) { - googleCredentials = credentials; - } - - ApplicationDefaultAuthCredentials() throws IOException { - googleCredentials = GoogleCredentials.getApplicationDefault(); - } - - @Override - @Deprecated - public GoogleCredentials credentials() { - return getCredentials(); - } - - @Override - public GoogleCredentials getCredentials() { - return googleCredentials; - } - - @Override - public RestorableState capture() { - return STATE; - } - } - - /** - * Represents OAuth2 credentials. These credentials can be created given an OAuth2 access token. - * The access token will not be automatically refreshed. - */ - public static class OAuth2AuthCredentials extends AuthCredentials { - - private final GoogleCredentials credentials; - private final String accessToken; - private final Date expirationTime; - - private static class OAuth2AuthCredentialsState - implements RestorableState, Serializable { - - private static final long serialVersionUID = -7760693952274496205L; - - private final String accessToken; - private final Date expirationTime; - - private OAuth2AuthCredentialsState(String accessToken, Date expirationTime) { - this.accessToken = accessToken; - this.expirationTime = expirationTime; - } - - @Override - public AuthCredentials restore() { - return new OAuth2AuthCredentials(accessToken, expirationTime); - } - - @Override - public int hashCode() { - return Objects.hash(accessToken, expirationTime); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof OAuth2AuthCredentialsState)) { - return false; - } - OAuth2AuthCredentialsState other = (OAuth2AuthCredentialsState) obj; - return Objects.equals(accessToken, other.accessToken) - && Objects.equals(expirationTime, other.expirationTime); - } - } - - OAuth2AuthCredentials(String accessToken, Date expirationTime) { - this.accessToken = checkNotNull(accessToken); - this.expirationTime = expirationTime; - this.credentials = new GoogleCredentials(new AccessToken(accessToken, expirationTime)); - } - - @Override - @Deprecated - public GoogleCredentials credentials() { - return getCredentials(); - } - - @Override - public GoogleCredentials getCredentials() { - return credentials; - } - - @Override - public RestorableState capture() { - return new OAuth2AuthCredentialsState(accessToken, expirationTime); - } - } - - /** - * A placeholder for credentials to signify that requests sent to the server should not be - * authenticated. This is typically useful when using the local service emulators, such as - * {@code LocalDatastoreHelper} and {@code LocalResourceManagerHelper}. - */ - public static class NoAuthCredentials extends AuthCredentials { - - private static final AuthCredentials INSTANCE = new NoAuthCredentials(); - private static final NoAuthCredentialsState STATE = new NoAuthCredentialsState(); - - private static class NoAuthCredentialsState - implements RestorableState, Serializable { - - private static final long serialVersionUID = -4022100563954640465L; - - @Override - public AuthCredentials restore() { - return INSTANCE; - } - - @Override - public int hashCode() { - return getClass().getName().hashCode(); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof NoAuthCredentialsState; - } - } - - private NoAuthCredentials() {} - - @Override - @Deprecated - public GoogleCredentials credentials() { - return getCredentials(); - } - - @Override - public GoogleCredentials getCredentials() { - return null; - } - - @Override - public RestorableState capture() { - return STATE; - } - } - - @Deprecated - public abstract GoogleCredentials credentials(); - - public abstract GoogleCredentials getCredentials(); - - public static AuthCredentials createForAppEngine() { - return AppEngineAuthCredentials.INSTANCE; - } - - /** - * Returns the Application Default Credentials. - * - *

    Returns the Application Default Credentials which are credentials that identify and - * authorize the whole application. This is the built-in service account if running on - * Google Compute Engine or the credentials file can be read from the path in the environment - * variable GOOGLE_APPLICATION_CREDENTIALS. - *

    - * - * @return the credentials instance - * @throws IOException if the credentials cannot be created in the current environment - */ - public static AuthCredentials createApplicationDefaults() throws IOException { - GoogleCredentials credentials = GoogleCredentials.getApplicationDefault(); - if (credentials instanceof ServiceAccountCredentials) { - ServiceAccountCredentials serviceAccountCredentials = (ServiceAccountCredentials) credentials; - return new ServiceAccountAuthCredentials(serviceAccountCredentials); - } - return new ApplicationDefaultAuthCredentials(credentials); - } - - /** - * Creates Service Account Credentials given an account id and a private key. - * - *

    For details on how to obtain Service Account Credentials see - * Service - * Account Authentication. - *

    - * - * @param account id of the Service Account - * @param privateKey private key associated to the account - * @return the credentials instance - */ - public static ServiceAccountAuthCredentials createFor(String account, PrivateKey privateKey) { - return new ServiceAccountAuthCredentials(account, privateKey); - } - - /** - * Creates OAuth2 Credentials given the string representation of an access token. The access token - * will not be automatically refreshed. - * - * @param accessToken string representation of an access token - * @return the credentials instance - */ - public static OAuth2AuthCredentials createFor(String accessToken) { - return createFor(accessToken, (Date) null); - } - - /** - * Creates OAuth2 Credentials given the string representation of an access token and its - * expiration time. The access token will not be automatically refreshed. - * - * @param accessToken string representation of an access token - * @return the credentials instance - */ - public static OAuth2AuthCredentials createFor(String accessToken, Date expirationTime) { - return new OAuth2AuthCredentials(accessToken, expirationTime); - } - - /** - * Creates a placeholder denoting that no credentials should be used. This is typically useful - * when using the local service emulators, such as {@code LocalDatastoreHelper} and - * {@code LocalResourceManagerHelper}. - */ - public static AuthCredentials noAuth() { - return NoAuthCredentials.INSTANCE; - } - - /** - * Creates Service Account Credentials given a stream for credentials in JSON format. - * - *

    For details on how to obtain Service Account Credentials in JSON format see - * Service - * Account Authentication. - *

    - * - * @param jsonCredentialStream stream for Service Account Credentials in JSON format - * @return the credentials instance - * @throws IOException if the credentials cannot be created from the stream - */ - public static ServiceAccountAuthCredentials createForJson(InputStream jsonCredentialStream) - throws IOException { - GoogleCredentials tempCredentials = GoogleCredentials.fromStream(jsonCredentialStream); - if (tempCredentials instanceof ServiceAccountCredentials) { - ServiceAccountCredentials tempServiceAccountCredentials = - (ServiceAccountCredentials) tempCredentials; - return new ServiceAccountAuthCredentials( - tempServiceAccountCredentials.getClientEmail(), - tempServiceAccountCredentials.getPrivateKey()); - } - throw new IOException( - "The given JSON Credentials Stream is not for a service account credential."); - } -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java index e0017e0919..25cd8a29cc 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; import com.google.api.gax.grpc.UnaryCallSettings; -import com.google.auth.oauth2.GoogleCredentials; +import com.google.auth.Credentials; import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -52,7 +52,7 @@ public abstract class GrpcServiceOptions, Ser OptionsT extends GrpcServiceOptions> extends ServiceOptions { - private static final long serialVersionUID = 6415982522610509549L; + private static final long serialVersionUID = -3093986242928037007L; private final String executorFactoryClassName; private final int initialTimeout; private final double timeoutMultiplier; @@ -319,9 +319,9 @@ protected ConnectionSettings.Builder getConnectionSettings() { ConnectionSettings.Builder builder = ConnectionSettings.newBuilder() .setServiceAddress(hostAndPort.getHostText()) .setPort(hostAndPort.getPort()); - GoogleCredentials credentials = getAuthCredentials().getCredentials(); - if (credentials != null) { - builder.provideCredentialsWith(credentials.createScoped(getScopes())); + Credentials scopedCredentials = getScopedCredentials(); + if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { + builder.provideCredentialsWith(scopedCredentials); } return builder; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java index 9e49d537f3..d816ed1a7b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java @@ -23,7 +23,9 @@ import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.auth.Credentials; import com.google.auth.http.HttpCredentialsAdapter; +import com.google.auth.http.HttpTransportFactory; import com.google.cloud.spi.ServiceRpcFactory; import java.io.IOException; @@ -42,23 +44,13 @@ public abstract class HttpServiceOptions, Ser OptionsT extends HttpServiceOptions> extends ServiceOptions { - private static final long serialVersionUID = 3652819407083815771L; + private static final long serialVersionUID = 4765436436821178975L; private final int connectTimeout; private final int readTimeout; private final String httpTransportFactoryClassName; private transient HttpTransportFactory httpTransportFactory; - /** - * A base interface for all {@link HttpTransport} factories. - * - *

    Implementation must provide a public no-arg constructor. Loading of a factory implementation - * is done via {@link java.util.ServiceLoader}. - */ - public interface HttpTransportFactory { - HttpTransport create(); - } - public static class DefaultHttpTransportFactory implements HttpTransportFactory { private static final HttpTransportFactory INSTANCE = new DefaultHttpTransportFactory(); @@ -221,11 +213,10 @@ public HttpRequestInitializer httpRequestInitializer() { * options. */ public HttpRequestInitializer getHttpRequestInitializer() { + Credentials scopedCredentials = getScopedCredentials(); final HttpRequestInitializer delegate = - getAuthCredentials() != null && getAuthCredentials().getCredentials() != null - ? new HttpCredentialsAdapter( - getAuthCredentials().getCredentials().createScoped(getScopes())) - : null; + scopedCredentials != null && scopedCredentials != NoCredentials.getInstance() + ? new HttpCredentialsAdapter(scopedCredentials) : null; return new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { diff --git a/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java b/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java new file mode 100644 index 0000000000..3f5cfbdbfc --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java @@ -0,0 +1,41 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.auth.oauth2.OAuth2Credentials; + +import java.io.ObjectStreamException; + +/** + * A placeholder for credentials to signify that requests sent to the server should not be + * authenticated. This is typically useful when using local service emulators. + */ +public class NoCredentials extends OAuth2Credentials { + + private static final long serialVersionUID = -6263971603971044288L; + private static final NoCredentials INSTANCE = new NoCredentials(); + + private NoCredentials() {} + + private Object readResolve() throws ObjectStreamException { + return INSTANCE; + } + + public static NoCredentials getInstance() { + return INSTANCE; + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java deleted file mode 100644 index 29202c69d0..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceAccountSigner.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import java.util.Objects; - -/** - * Interface for a service account signer. A signer for a service account is capable of signing - * bytes using the private key associated with its service account. - */ -public interface ServiceAccountSigner { - - class SigningException extends RuntimeException { - - private static final long serialVersionUID = 8962780757822799255L; - - SigningException(String message, Exception cause) { - super(message, cause); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof SigningException)) { - return false; - } - SigningException other = (SigningException) obj; - return Objects.equals(getCause(), other.getCause()) - && Objects.equals(getMessage(), other.getMessage()); - } - - @Override - public int hashCode() { - return Objects.hash(getMessage(), getCause()); - } - } - - /** - * Returns the service account associated with the signer. - */ - @Deprecated - String account(); - - /** - * Returns the service account associated with the signer. - */ - String getAccount(); - - /** - * Signs the provided bytes using the private key associated with the service account. - * - * @param toSign bytes to sign - * @return signed bytes - * @throws SigningException if the attempt to sign the provided bytes failed - */ - byte[] sign(byte[] toSign); -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index f918cd2188..c14c770e3b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -18,8 +18,11 @@ import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.auth.Credentials; +import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.collect.Iterables; import com.google.common.io.Files; @@ -73,17 +76,16 @@ public abstract class ServiceOptions, Service private static final String LIBRARY_VERSION = defaultLibraryVersion(); private static final String APPLICATION_NAME = LIBRARY_VERSION == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + LIBRARY_VERSION; - private static final long serialVersionUID = 3049375916337507361L; + private static final long serialVersionUID = -5714029257168617973L; private final String projectId; private final String host; - private final RestorableState authCredentialsState; private final RetryParams retryParams; private final String serviceRpcFactoryClassName; private final String serviceFactoryClassName; private final Clock clock; + private final Credentials credentials; - private transient AuthCredentials authCredentials; private transient ServiceRpcFactory serviceRpcFactory; private transient ServiceFactory serviceFactory; private transient ServiceT service; @@ -103,7 +105,7 @@ protected abstract static class Builder, Serv private String projectId; private String host; - private AuthCredentials authCredentials; + private Credentials credentials; private RetryParams retryParams; private ServiceFactory serviceFactory; private ServiceRpcFactory serviceRpcFactory; @@ -114,7 +116,7 @@ protected Builder() {} protected Builder(ServiceOptions options) { projectId = options.projectId; host = options.host; - authCredentials = options.authCredentials; + credentials = options.credentials; retryParams = options.retryParams; serviceFactory = options.serviceFactory; serviceRpcFactory = options.serviceRpcFactory; @@ -209,22 +211,18 @@ public B setHost(String host) { } /** - * Sets the service authentication credentials. + * Sets the service authentication credentials. If no credentials are set, + * {@link GoogleCredentials#getApplicationDefault()} will be used to attempt getting credentials + * from the environment. Use {@link NoCredentials#getInstance()} to skip authentication, this is + * typically useful when using local service emulators. * + * @param credentials authentication credentials, should not be {@code null} * @return the builder + * @throws NullPointerException if {@code credentials} is {@code null}. To disable + * authentication use {@link NoCredentials#getInstance()} */ - @Deprecated - public B authCredentials(AuthCredentials authCredentials) { - return setAuthCredentials(authCredentials); - } - - /** - * Sets the service authentication credentials. - * - * @return the builder - */ - public B setAuthCredentials(AuthCredentials authCredentials) { - this.authCredentials = authCredentials; + public B setCredentials(Credentials credentials) { + this.credentials = checkNotNull(credentials); return self(); } @@ -284,9 +282,7 @@ protected ServiceOptions(Class> ser + "or the environment. Please set a project ID using the builder."); } host = firstNonNull(builder.host, getDefaultHost()); - authCredentials = - builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials(); - authCredentialsState = authCredentials != null ? authCredentials.capture() : null; + credentials = builder.credentials != null ? builder.credentials : defaultCredentials(); retryParams = firstNonNull(builder.retryParams, defaultRetryParams()); serviceFactory = firstNonNull(builder.serviceFactory, getFromServiceLoader(serviceFactoryClass, getDefaultServiceFactory())); @@ -307,18 +303,9 @@ protected boolean projectIdRequired() { return true; } - private static AuthCredentials defaultAuthCredentials() { - // Consider App Engine. - if (appEngineAppId() != null) { - try { - return AuthCredentials.createForAppEngine(); - } catch (Exception ignore) { - // Maybe not on App Engine - } - } - + private static GoogleCredentials defaultCredentials() { try { - return AuthCredentials.createApplicationDefaults(); + return GoogleCredentials.getApplicationDefault(); } catch (Exception ex) { return null; } @@ -528,16 +515,20 @@ public String getHost() { /** * Returns the authentication credentials. */ - @Deprecated - public AuthCredentials authCredentials() { - return getAuthCredentials(); + public Credentials getCredentials() { + return credentials; } /** - * Returns the authentication credentials. + * Returns the authentication credentials. If required, credentials are scoped. */ - public AuthCredentials getAuthCredentials() { - return authCredentials; + public Credentials getScopedCredentials() { + Credentials credentialsToReturn = credentials; + if (credentials instanceof GoogleCredentials + && ((GoogleCredentials) credentials).createScopedRequired()) { + credentialsToReturn = ((GoogleCredentials) credentials).createScoped(getScopes()); + } + return credentialsToReturn; } /** @@ -619,14 +610,14 @@ public String getLibraryVersion() { } protected int baseHashCode() { - return Objects.hash(projectId, host, authCredentialsState, retryParams, serviceFactoryClassName, + return Objects.hash(projectId, host, credentials, retryParams, serviceFactoryClassName, serviceRpcFactoryClassName, clock); } protected boolean baseEquals(ServiceOptions other) { return Objects.equals(projectId, other.projectId) && Objects.equals(host, other.host) - && Objects.equals(authCredentialsState, other.authCredentialsState) + && Objects.equals(credentials, other.credentials) && Objects.equals(retryParams, other.retryParams) && Objects.equals(serviceFactoryClassName, other.serviceFactoryClassName) && Objects.equals(serviceRpcFactoryClassName, other.serviceRpcFactoryClassName) @@ -637,7 +628,6 @@ private void readObject(ObjectInputStream input) throws IOException, ClassNotFou input.defaultReadObject(); serviceFactory = newInstance(serviceFactoryClassName); serviceRpcFactory = newInstance(serviceRpcFactoryClassName); - authCredentials = authCredentialsState != null ? authCredentialsState.restore() : null; } @SuppressWarnings("unchecked") diff --git a/google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java b/google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java deleted file mode 100644 index 3ae34e6ca9..0000000000 --- a/google-cloud-core/src/test/java/com/google/cloud/AuthCredentialsTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import static com.google.common.base.Charsets.UTF_8; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; - -import com.google.auth.oauth2.AccessToken; -import com.google.auth.oauth2.ServiceAccountCredentials; -import com.google.cloud.AuthCredentials.OAuth2AuthCredentials; -import com.google.cloud.AuthCredentials.ServiceAccountAuthCredentials; -import com.google.common.io.BaseEncoding; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.security.InvalidKeyException; -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.Signature; -import java.security.SignatureException; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.PKCS8EncodedKeySpec; -import java.util.Date; - -public class AuthCredentialsTest { - - private static final String ACCESS_TOKEN = "accessToken"; - private static final Date EXPIRATION_DATE = new Date(); - private static final String SERVICE_ACCOUNT = "someclientid@developer.gserviceaccount.com"; - private static final String PRIVATE_KEY_STRING = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoG" - + "BAL2xolH1zrISQ8+GzOV29BNjjzq4/HIP8Psd1+cZb81vDklSF+95wB250MSE0BDc81pvIMwj5OmIfLg1NY6uB1xav" - + "OPpVdx1z664AGc/BEJ1zInXGXaQ6s+SxGenVq40Yws57gikQGMZjttpf1Qbz4DjkxsbRoeaRHn06n9pH1ejAgMBAAE" - + "CgYEAkWcm0AJF5LMhbWKbjkxm/LG06UNApkHX6vTOOOODkonM/qDBnhvKCj8Tan+PaU2j7679Cd19qxCm4SBQJET7e" - + "BhqLD9L2j9y0h2YUQnLbISaqUS1/EXcr2C1Lf9VCEn1y/GYuDYqs85rGoQ4ZYfM9ClROSq86fH+cbIIssqJqukCQQD" - + "18LjfJz/ichFeli5/l1jaFid2XoCH3T6TVuuysszVx68fh60gSIxEF/0X2xB+wuPxTP4IQ+t8tD/ktd232oWXAkEAx" - + "XPych2QBHePk9/lek4tOkKBgfnDzex7S/pI0G1vpB3VmzBbCsokn9lpOv7JV8071GDlW/7R6jlLfpQy3hN31QJAE10" - + "osSk99m5Uv8XDU3hvHnywDrnSFOBulNs7I47AYfSe7TSZhPkxUgsxejddTR27JLyTI8N1PxRSE4feNSOXcQJAMMKJR" - + "JT4U6IS2rmXubREhvaVdLtxFxEnAYQ1JwNfZm/XqBMw6GEy2iaeTetNXVlZRQEIoscyn1y2v/No/F5iYQJBAKBOGAS" - + "oQcBjGTOg/H/SfcE8QVNsKEpthRrs6CkpT80aZ/AV+ksfoIf2zw2M3mAHfrO+TBLdz4sicuFQvlN9SEc="; - private static final String JSON_KEY = "{\n" - + " \"private_key_id\": \"somekeyid\",\n" - + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\n" + PRIVATE_KEY_STRING - + "\\n-----END PRIVATE KEY-----\\n\",\n" - + " \"client_email\": \"someclientid@developer.gserviceaccount.com\",\n" - + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" - + " \"type\": \"service_account\"\n" - + "}"; - private static final AuthCredentials NO_AUTH_CREDENTIALS = AuthCredentials.noAuth(); - private static final OAuth2AuthCredentials OAUTH2_AUTH_CREDENTIALS = - AuthCredentials.createFor(ACCESS_TOKEN, EXPIRATION_DATE); - private static final byte[] BYTES_TO_SIGN = PRIVATE_KEY_STRING.getBytes(UTF_8); - - private static PrivateKey privateKey; - private static byte[] signedBytes; - - @BeforeClass - public static void beforeClass() throws NoSuchAlgorithmException, InvalidKeySpecException, - InvalidKeyException, SignatureException { - KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - privateKey = keyFactory.generatePrivate( - new PKCS8EncodedKeySpec(BaseEncoding.base64().decode(PRIVATE_KEY_STRING))); - Signature signature = Signature.getInstance("SHA256withRSA"); - signature.initSign(privateKey); - signature.update(BYTES_TO_SIGN); - signedBytes = signature.sign(); - } - - @Test - public void testNoAuthCredentials() { - assertSame(NO_AUTH_CREDENTIALS, AuthCredentials.noAuth()); - assertNull(NO_AUTH_CREDENTIALS.getCredentials()); - } - - @Test - public void testNoAuthCredentialsDeprecated() { - assertSame(NO_AUTH_CREDENTIALS, AuthCredentials.noAuth()); - assertNull(NO_AUTH_CREDENTIALS.credentials()); - } - - @Test - public void testOAuth2AuthCredentials() { - AccessToken accessToken = OAUTH2_AUTH_CREDENTIALS.getCredentials().getAccessToken(); - assertEquals(ACCESS_TOKEN, accessToken.getTokenValue()); - assertEquals(EXPIRATION_DATE, accessToken.getExpirationTime()); - OAuth2AuthCredentials oAuth2AuthCredentials = - AuthCredentials.createFor(ACCESS_TOKEN); - accessToken = oAuth2AuthCredentials.getCredentials().getAccessToken(); - assertEquals(ACCESS_TOKEN, accessToken.getTokenValue()); - assertNull(accessToken.getExpirationTime()); - } - - @Test - public void testOAuth2AuthCredentialsDeprecated() { - AccessToken accessToken = OAUTH2_AUTH_CREDENTIALS.credentials().getAccessToken(); - assertEquals(ACCESS_TOKEN, accessToken.getTokenValue()); - assertEquals(EXPIRATION_DATE, accessToken.getExpirationTime()); - OAuth2AuthCredentials oAuth2AuthCredentials = - AuthCredentials.createFor(ACCESS_TOKEN); - accessToken = oAuth2AuthCredentials.credentials().getAccessToken(); - assertEquals(ACCESS_TOKEN, accessToken.getTokenValue()); - assertNull(accessToken.getExpirationTime()); - } - - @Test - public void testServiceAccountFromJson() throws IOException, SignatureException { - ServiceAccountAuthCredentials serviceAccountAuthCredentials = - AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes())); - ServiceAccountCredentials credentials = serviceAccountAuthCredentials.getCredentials(); - assertEquals(SERVICE_ACCOUNT, serviceAccountAuthCredentials.getAccount()); - assertEquals(SERVICE_ACCOUNT, credentials.getClientEmail()); - assertEquals(privateKey, credentials.getPrivateKey()); - assertArrayEquals(signedBytes, serviceAccountAuthCredentials.sign(BYTES_TO_SIGN)); - } - - @Test - public void testServiceAccountFromJsonDeprecated() throws IOException, SignatureException { - ServiceAccountAuthCredentials serviceAccountAuthCredentials = - AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes())); - ServiceAccountCredentials credentials = serviceAccountAuthCredentials.credentials(); - assertEquals(SERVICE_ACCOUNT, serviceAccountAuthCredentials.account()); - assertEquals(SERVICE_ACCOUNT, credentials.getClientEmail()); - assertEquals(privateKey, credentials.getPrivateKey()); - assertArrayEquals(signedBytes, serviceAccountAuthCredentials.sign(BYTES_TO_SIGN)); - } - - @Test - public void testServiceAccountFromKey() throws IOException, SignatureException { - ServiceAccountAuthCredentials serviceAccountAuthCredentials = - AuthCredentials.createFor(SERVICE_ACCOUNT, privateKey); - ServiceAccountCredentials credentials = serviceAccountAuthCredentials.getCredentials(); - assertEquals(SERVICE_ACCOUNT, serviceAccountAuthCredentials.getAccount()); - assertEquals(SERVICE_ACCOUNT, credentials.getClientEmail()); - assertEquals(privateKey, credentials.getPrivateKey()); - assertArrayEquals(signedBytes, serviceAccountAuthCredentials.sign(BYTES_TO_SIGN)); - } - - @Test - public void testServiceAccountFromKeyDeprecated() throws IOException, SignatureException { - ServiceAccountAuthCredentials serviceAccountAuthCredentials = - AuthCredentials.createFor(SERVICE_ACCOUNT, privateKey); - ServiceAccountCredentials credentials = serviceAccountAuthCredentials.credentials(); - assertEquals(SERVICE_ACCOUNT, serviceAccountAuthCredentials.account()); - assertEquals(SERVICE_ACCOUNT, credentials.getClientEmail()); - assertEquals(privateKey, credentials.getPrivateKey()); - assertArrayEquals(signedBytes, serviceAccountAuthCredentials.sign(BYTES_TO_SIGN)); - } -} diff --git a/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java index a372498c21..9ac2891c6c 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java @@ -21,8 +21,8 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import com.google.auth.http.HttpTransportFactory; import com.google.cloud.HttpServiceOptions.DefaultHttpTransportFactory; -import com.google.cloud.HttpServiceOptions.HttpTransportFactory; import com.google.cloud.spi.ServiceRpcFactory; import org.easymock.EasyMock; diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 746f2b406b..d2e2de4f4a 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -18,14 +18,10 @@ import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor; import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor.ValueType; -import com.google.cloud.ServiceAccountSigner.SigningException; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.Serializable; -import java.util.Date; import java.util.concurrent.TimeUnit; public class SerializationTest extends BaseSerializationTest { @@ -36,8 +32,6 @@ public class SerializationTest extends BaseSerializationTest { private static final Identity IDENTITY = Identity.allAuthenticatedUsers(); private static final PageImpl PAGE = new PageImpl<>(null, "cursor", ImmutableList.of("string1", "string2")); - private static final SigningException SIGNING_EXCEPTION = - new SigningException("message", BASE_SERVICE_EXCEPTION); private static final RetryParams RETRY_PARAMS = RetryParams.getDefaultInstance(); private static final Role SOME_ROLE = Role.viewer(); private static final Policy SOME_IAM_POLICY = Policy.newBuilder().build(); @@ -82,19 +76,12 @@ public class SerializationTest extends BaseSerializationTest { @Override protected Serializable[] serializableObjects() { return new Serializable[]{BASE_SERVICE_EXCEPTION, EXCEPTION_HANDLER, IDENTITY, PAGE, - RETRY_PARAMS, SOME_ROLE, SOME_IAM_POLICY, SIGNING_EXCEPTION, CHECKING_PERIOD, - LABEL_DESCRIPTOR, MONITORED_RESOURCE_DESCRIPTOR, MONITORED_RESOURCE}; + RETRY_PARAMS, SOME_ROLE, SOME_IAM_POLICY, CHECKING_PERIOD, LABEL_DESCRIPTOR, + MONITORED_RESOURCE_DESCRIPTOR, MONITORED_RESOURCE}; } @Override protected Restorable[] restorableObjects() { - try { - return new Restorable[]{AuthCredentials.createForAppEngine(), AuthCredentials.noAuth(), - AuthCredentials.createForJson(new ByteArrayInputStream(JSON_KEY.getBytes())), - AuthCredentials.createFor("accessToken", new Date())}; - } catch (IOException ex) { - // never reached - throw new RuntimeException(ex); - } + return null; } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index e7e74459d1..cf364db57e 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -22,9 +22,12 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -61,10 +64,10 @@ public class ServiceOptionsTest { + " \"type\": \"service_account\"\n" + "}"; private static final InputStream JSON_KEY_STREAM = new ByteArrayInputStream(JSON_KEY.getBytes()); - private static AuthCredentials authCredentials; + private static GoogleCredentials credentials; static { try { - authCredentials = AuthCredentials.createForJson(JSON_KEY_STREAM); + credentials = GoogleCredentials.fromStream(JSON_KEY_STREAM); } catch (IOException e) { fail("Couldn't create fake JSON credentials."); } @@ -72,7 +75,15 @@ public class ServiceOptionsTest { private static final Clock TEST_CLOCK = new TestClock(); private static final TestServiceOptions OPTIONS = TestServiceOptions.newBuilder() - .setAuthCredentials(authCredentials) + .setCredentials(credentials) + .setClock(TEST_CLOCK) + .setHost("host") + .setProjectId("project-id") + .setRetryParams(RetryParams.noRetries()) + .build(); + private static final TestServiceOptions OPTIONS_NO_CREDENTIALS = + TestServiceOptions.newBuilder() + .setCredentials(NoCredentials.getInstance()) .setClock(TEST_CLOCK) .setHost("host") .setProjectId("project-id") @@ -80,7 +91,7 @@ public class ServiceOptionsTest { .build(); private static final TestServiceOptions DEPRECATED_OPTIONS = TestServiceOptions.newBuilder() - .authCredentials(authCredentials) + .setCredentials(credentials) .clock(TEST_CLOCK) .host("host") .projectId("project-id") @@ -95,6 +106,9 @@ public class ServiceOptionsTest { private static final Pattern APPLICATION_NAME_PATTERN = Pattern.compile(LIBRARY_NAME + "(/[0-9]+.[0-9]+.[0-9]+)?"); + @Rule + public ExpectedException thrown = ExpectedException.none(); + private static class TestClock extends Clock { @Override public long millis() { @@ -197,7 +211,7 @@ public int hashCode() { @Test public void testBuilder() { - assertSame(authCredentials, OPTIONS.getAuthCredentials()); + assertSame(credentials, OPTIONS.getCredentials()); assertSame(TEST_CLOCK, OPTIONS.getClock()); assertEquals("host", OPTIONS.getHost()); assertEquals("project-id", OPTIONS.getProjectId()); @@ -207,9 +221,24 @@ public void testBuilder() { assertSame(RetryParams.getDefaultInstance(), DEFAULT_OPTIONS.getRetryParams()); } + @Test + public void testBuilderNoCredentials() { + assertEquals(NoCredentials.getInstance(), OPTIONS_NO_CREDENTIALS.getCredentials()); + assertSame(TEST_CLOCK, OPTIONS_NO_CREDENTIALS.getClock()); + assertEquals("host", OPTIONS_NO_CREDENTIALS.getHost()); + assertEquals("project-id", OPTIONS_NO_CREDENTIALS.getProjectId()); + assertSame(RetryParams.noRetries(), OPTIONS_NO_CREDENTIALS.getRetryParams()); + } + + @Test + public void testBuilderNullCredentials() { + thrown.expect(NullPointerException.class); + TestServiceOptions.newBuilder().setCredentials(null).build(); + } + @Test public void testBuilderDeprecated() { - assertSame(authCredentials, DEPRECATED_OPTIONS.authCredentials()); + assertSame(credentials, DEPRECATED_OPTIONS.getCredentials()); assertSame(TEST_CLOCK, DEPRECATED_OPTIONS.clock()); assertEquals("host", DEPRECATED_OPTIONS.host()); assertEquals("project-id", DEPRECATED_OPTIONS.projectId()); From e5d1cdbecb378407cd8a2359503593296fe0915d Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 9 Nov 2016 10:21:17 +0100 Subject: [PATCH 241/663] Add BaseEmulatorHelper class and tests, refactor helper classes (#1377) --- .../cloud/testing/BaseEmulatorHelper.java | 428 ++++++++++++++++++ .../testing/BlockingProcessStreamReader.java | 158 +++++++ .../google/cloud/testing/CommandWrapper.java | 101 +++++ .../com/google/cloud/testing/Version.java | 92 ++++ .../cloud/testing/BaseEmulatorHelperTest.java | 120 +++++ .../BlockingProcessStreamReaderTest.java | 123 +++++ .../cloud/testing/CommandWrapperTest.java | 122 +++++ .../com/google/cloud/testing/VersionTest.java | 85 ++++ 8 files changed, 1229 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/testing/Version.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java new file mode 100644 index 0000000000..65277a7746 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -0,0 +1,428 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.testing; + +import com.google.cloud.ServiceOptions; +import com.google.common.io.CharStreams; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.math.BigInteger; +import java.net.HttpURLConnection; +import java.net.ServerSocket; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +/** + * Utility class to start and stop a local service which is used by unit testing. + */ +public abstract class BaseEmulatorHelper { + + private final String emulator; + private final int port; + private final String projectId; + private EmulatorRunner activeRunner; + private BlockingProcessStreamReader blockingProcessReader; + + protected static final String PROJECT_ID_PREFIX = "test-project-"; + protected static final String DEFAULT_HOST = "localhost"; + protected static final int DEFAULT_PORT = 8080; + + protected BaseEmulatorHelper(String emulator, int port, String projectId) { + this.emulator = emulator; + this.port = port > 0 ? port : DEFAULT_PORT; + this.projectId = projectId; + } + + /** + * Returns the emulator runners supported by this emulator. Runners are evaluated in order, the + * first available runner is selected and executed + */ + protected abstract List getEmulatorRunners(); + + /** + * Returns a logger. + */ + protected abstract Logger getLogger(); + + /** + * Starts the local service as a subprocess. Blocks the execution until {@code blockUntilOutput} + * is found on stdout. + */ + protected final void startProcess(String blockUntilOutput) + throws IOException, InterruptedException { + for (EmulatorRunner runner : getEmulatorRunners()) { + // Iterate through all emulator runners until find first available runner. + if (runner.isAvailable()) { + activeRunner = runner; + runner.start(); + break; + } + } + if (activeRunner != null) { + blockingProcessReader = BlockingProcessStreamReader.start(emulator, + activeRunner.getProcess().getInputStream(), blockUntilOutput, getLogger()); + } else { + // No available runner found. + throw new IOException("No available emulator runner is found."); + } + } + + /** + * Stops the local service's subprocess and any possible thread listening for its output. + */ + protected final void stopProcess() throws IOException, InterruptedException { + if (blockingProcessReader != null) { + blockingProcessReader.terminate(); + blockingProcessReader = null; + } + if (activeRunner != null) { + activeRunner.stop(); + activeRunner = null; + } + } + + /** + * Returns the port to which the local emulator is listening. + */ + public int getPort() { + return port; + } + + /** + * Returns the project ID associated with the local emulator. + */ + public String getProjectId() { + return projectId; + } + + /** + * Returns service options to access the local emulator. + */ + public abstract T getOptions(); + + /** + * Starts the local emulator. + */ + public abstract void start() throws IOException, InterruptedException; + + /** + * Stops the local emulator. + */ + public abstract void stop() throws IOException, InterruptedException; + + /** + * Resets the internal state of the emulator. + */ + public abstract void reset() throws IOException; + + protected final String sendPostRequest(String request) throws IOException { + URL url = new URL("http", DEFAULT_HOST, this.port, request); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("POST"); + con.setDoOutput(true); + OutputStream out = con.getOutputStream(); + out.write("".getBytes()); + out.flush(); + + InputStream in = con.getInputStream(); + String response = CharStreams.toString(new InputStreamReader(con.getInputStream())); + in.close(); + return response; + } + + protected static int findAvailablePort(int defaultPort) { + try (ServerSocket tempSocket = new ServerSocket(0)) { + return tempSocket.getLocalPort(); + } catch (IOException e) { + return defaultPort; + } + } + + protected static boolean isWindows() { + return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"); + } + + /** + * Utility interface to start and run an emulator. + */ + protected interface EmulatorRunner { + + /** + * Returns {@code true} if the emulator associated to this runner is available and can be + * started. + */ + boolean isAvailable(); + + /** + * Starts the emulator associated to this runner. + */ + void start() throws IOException; + + /** + * Stops the emulator associated to this runner. + */ + void stop() throws InterruptedException; + + /** + * Returns the process associated to the emulator, if any. + */ + Process getProcess(); + } + + /** + * Utility class to start and run an emulator from the Google Cloud SDK. + */ + protected static class GcloudEmulatorRunner implements EmulatorRunner { + + private final List commandText; + private final String versionPrefix; + private final Version minVersion; + private Process process; + private static final Logger log = Logger.getLogger(GcloudEmulatorRunner.class.getName()); + + public GcloudEmulatorRunner(List commandText, String versionPrefix, String minVersion) { + this.commandText = commandText; + this.versionPrefix = versionPrefix; + this.minVersion = Version.fromString(minVersion); + } + + @Override + public boolean isAvailable() { + try { + return isGcloudInstalled() && isEmulatorUpToDate() && !commandText.isEmpty(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(System.err); + } + return false; + } + + @Override + public void start() throws IOException { + log.fine("Starting emulator via Google Cloud SDK"); + process = CommandWrapper.create().setCommand(commandText).setRedirectErrorStream().start(); + } + + @Override + public void stop() throws InterruptedException { + if (process != null) { + process.destroy(); + process.waitFor(); + } + } + + @Override + public Process getProcess() { + return process; + } + + private boolean isGcloudInstalled() { + Map env = System.getenv(); + for (String envName : env.keySet()) { + if ("PATH".equals(envName)) { + return env.get(envName).contains("google-cloud-sdk"); + } + } + return false; + } + + private boolean isEmulatorUpToDate() throws IOException, InterruptedException { + Version currentVersion = getInstalledEmulatorVersion(versionPrefix); + return currentVersion != null && currentVersion.compareTo(minVersion) >= 0; + } + + private Version getInstalledEmulatorVersion(String versionPrefix) + throws IOException, InterruptedException { + Process process = + CommandWrapper.create() + .setCommand(Arrays.asList("gcloud", "version")) + // gcloud redirects all output to stderr while emulators' executables use either + // stdout or stderr with no apparent convention. To be able to properly intercept and + // block waiting for emulators to be ready we redirect everything to stdout + .setRedirectErrorStream() + .start(); + process.waitFor(); + try (BufferedReader reader = + new BufferedReader(new InputStreamReader(process.getInputStream()))) { + for (String line = reader.readLine(); line != null; line = reader.readLine()) { + if (line.startsWith(versionPrefix)) { + String[] lineComponents = line.split(" "); + if (lineComponents.length > 1) { + return Version.fromString(lineComponents[1]); + } + } + } + return null; + } + } + } + + /** + * Utility class to start and run an emulator from a download URL. + */ + protected static class DownloadableEmulatorRunner implements EmulatorRunner { + + private final List commandText; + private final String md5CheckSum; + private final URL downloadUrl; + private final String fileName; + private Process process; + private static final Logger log = Logger.getLogger(DownloadableEmulatorRunner.class.getName()); + + public DownloadableEmulatorRunner(List commandText, URL downloadUrl, + String md5CheckSum) { + this.commandText = commandText; + this.md5CheckSum = md5CheckSum; + this.downloadUrl = downloadUrl; + String[] splitUrl = downloadUrl.toString().split("/"); + this.fileName = splitUrl[splitUrl.length - 1]; + } + + @Override + public boolean isAvailable() { + try { + downloadZipFile(); + return true; + } catch (IOException e) { + return false; + } + } + + @Override + public void start() throws IOException { + Path emulatorPath = downloadEmulator(); + process = CommandWrapper.create() + .setCommand(commandText) + .setDirectory(emulatorPath) + // gcloud redirects all output to stderr while emulators' executables use either stdout + // or stderr with no apparent convention. To be able to properly intercept and block + // waiting for emulators to be ready we redirect everything to stdout + .setRedirectErrorStream() + .start(); + } + + @Override + public void stop() throws InterruptedException { + if (process != null) { + process.destroy(); + process.waitFor(); + } + } + + @Override + public Process getProcess() { + return process; + } + + private Path downloadEmulator() throws IOException { + // Retrieve the file name from the download link + String[] splittedUrl = downloadUrl.toString().split("/"); + String fileName = splittedUrl[splittedUrl.length - 1]; + + // Each run is associated with its own folder that is deleted once test completes. + Path emulatorPath = Files.createTempDirectory(fileName.split("\\.")[0]); + File emulatorFolder = emulatorPath.toFile(); + emulatorFolder.deleteOnExit(); + + File zipFile = downloadZipFile(); + // Unzip the emulator + try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFile))) { + if (log.isLoggable(Level.FINE)) { + log.fine("Unzipping emulator"); + } + ZipEntry entry = zipIn.getNextEntry(); + while (entry != null) { + File filePath = new File(emulatorPath.toFile(), entry.getName()); + if (!entry.isDirectory()) { + extractFile(zipIn, filePath); + } else { + filePath.mkdir(); + } + zipIn.closeEntry(); + entry = zipIn.getNextEntry(); + } + } + return emulatorPath; + } + + private File downloadZipFile() throws IOException { + // Check if we already have a local copy of the emulator and download it if not. + File zipFile = new File(System.getProperty("java.io.tmpdir"), fileName); + if (!zipFile.exists() || (md5CheckSum != null && !md5CheckSum.equals(md5(zipFile)))) { + if (log.isLoggable(Level.FINE)) { + log.fine("Fetching emulator"); + } + ReadableByteChannel rbc = Channels.newChannel(downloadUrl.openStream()); + try (FileOutputStream fos = new FileOutputStream(zipFile)) { + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + } + } else { + if (log.isLoggable(Level.FINE)) { + log.fine("Using cached emulator"); + } + } + return zipFile; + } + + private void extractFile(ZipInputStream zipIn, File filePath) throws IOException { + try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath))) { + byte[] bytesIn = new byte[1024]; + int read; + while ((read = zipIn.read(bytesIn)) != -1) { + bos.write(bytesIn, 0, read); + } + } + } + + private static String md5(File zipFile) throws IOException { + try { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + try (InputStream is = new BufferedInputStream(new FileInputStream(zipFile))) { + byte[] bytes = new byte[4 * 1024 * 1024]; + int len; + while ((len = is.read(bytes)) >= 0) { + md5.update(bytes, 0, len); + } + } + return String.format("%032x", new BigInteger(1, md5.digest())); + } catch (NoSuchAlgorithmException e) { + throw new IOException(e); + } + } + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java new file mode 100644 index 0000000000..988b6593a1 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java @@ -0,0 +1,158 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.testing; + +import static com.google.common.base.MoreObjects.firstNonNull; + +import com.google.common.base.Strings; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * This class allows to read a process output stream, block until a provided string appears on the + * stream and redirect pertinent error logs to a provided logger. + */ +class BlockingProcessStreamReader extends Thread { + + private static final int STREAM_READER_SLEEP_INTERVAL_IN_MS = 200; + private static final int LOG_LENGTH_LIMIT = 50000; + + private final BufferedReader errorReader; + private final Logger logger; + private StringBuilder currentLog; + private Level currentLogLevel; + private boolean collectionMode; + private volatile boolean terminated; + private final String emulatorTag; + private final Pattern logLinePattern; + + private BlockingProcessStreamReader(String emulator, InputStream stream, String blockUntil, + Logger logger) throws IOException { + super("blocking-process-stream-reader"); + setDaemon(true); + errorReader = new BufferedReader(new InputStreamReader(stream)); + this.logger = logger; + this.emulatorTag = "[" + emulator + "]"; + this.logLinePattern = Pattern.compile("(\\[" + emulator + "\\]\\s)?(\\w+):.*"); + if (!Strings.isNullOrEmpty(blockUntil)) { + String line; + do { + line = errorReader.readLine(); + } while (line != null && !line.contains(blockUntil)); + } + } + + void terminate() throws IOException { + terminated = true; + errorReader.close(); + interrupt(); + } + + @Override + public void run() { + String previousLine = ""; + String nextLine = ""; + while (!terminated) { + try { + if (errorReader.ready()) { + previousLine = nextLine; + nextLine = errorReader.readLine(); + if (nextLine == null) { + terminated = true; + } else { + processLogLine(previousLine, nextLine); + } + } else { + sleep(STREAM_READER_SLEEP_INTERVAL_IN_MS); + } + } catch (IOException e) { + e.printStackTrace(System.err); + } catch (InterruptedException e) { + previousLine = nextLine; + nextLine = null; + break; + } + } + processLogLine(previousLine, firstNonNull(nextLine, "")); + writeLog(); + } + + private void processLogLine(String previousLine, String nextLine) { + // Each log is two lines with the following format: + // [Emulator]? [Date] [Time] [LoggingClass] [method] + // [Emulator]? [LEVEL]: error message + // [Emulator]? more data + // Exceptions and stack traces are included in error stream, separated by a newline + Level nextLogLevel = getLevel(nextLine); + if (nextLogLevel != null) { + writeLog(); + currentLog = new StringBuilder(); + currentLogLevel = nextLogLevel; + collectionMode = true; + } else if (collectionMode) { + if (currentLog.length() > LOG_LENGTH_LIMIT) { + collectionMode = false; + } else if (currentLog.length() == 0) { + // strip level out of the line + currentLog.append(emulatorTag); + currentLog.append(previousLine.split(":", 2)[1]); + currentLog.append(System.getProperty("line.separator")); + } else { + if (!previousLine.startsWith(emulatorTag)) { + currentLog.append(emulatorTag); + currentLog.append(' '); + } + currentLog.append(previousLine); + currentLog.append(System.getProperty("line.separator")); + } + } + } + + private void writeLog() { + if (currentLogLevel != null && currentLog != null && currentLog.length() != 0) { + logger.log(currentLogLevel, currentLog.toString().trim()); + } + } + + private Level getLevel(String line) { + try { + Matcher matcher = logLinePattern.matcher(line); + if (matcher.matches()) { + return Level.parse(matcher.group(2)); + } else { + return null; + } + } catch (IllegalArgumentException e) { + return null; // level wasn't supplied in this log line + } + } + + static BlockingProcessStreamReader start(String emulator, InputStream stream, String blockUntil, + Logger logger) throws IOException { + BlockingProcessStreamReader thread = + new BlockingProcessStreamReader(emulator, stream, blockUntil, logger); + thread.start(); + return thread; + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java new file mode 100644 index 0000000000..eaafca7939 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java @@ -0,0 +1,101 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.testing; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +/** + * Utility class that executes system commands on both Windows and Unix. + */ +class CommandWrapper { + + private final List prefix; + private List command; + private String nullFilename; + private boolean redirectOutputToNull; + private boolean redirectErrorStream; + private boolean redirectErrorInherit; + private Path directory; + + private CommandWrapper() { + this.prefix = new ArrayList<>(); + if (BaseEmulatorHelper.isWindows()) { + this.prefix.add("cmd"); + this.prefix.add("/C"); + this.nullFilename = "NUL:"; + } else { + this.prefix.add("bash"); + this.nullFilename = "/dev/null"; + } + } + + CommandWrapper setCommand(List command) { + this.command = new ArrayList<>(command.size() + this.prefix.size()); + this.command.addAll(prefix); + this.command.addAll(command); + return this; + } + + CommandWrapper setRedirectOutputToNull() { + this.redirectOutputToNull = true; + return this; + } + + CommandWrapper setRedirectErrorStream() { + this.redirectErrorStream = true; + return this; + } + + CommandWrapper setRedirectErrorInherit() { + this.redirectErrorInherit = true; + return this; + } + + CommandWrapper setDirectory(Path directory) { + this.directory = directory; + return this; + } + + ProcessBuilder getBuilder() { + ProcessBuilder builder = new ProcessBuilder(command); + if (redirectOutputToNull) { + builder.redirectOutput(new File(nullFilename)); + } + if (directory != null) { + builder.directory(directory.toFile()); + } + if (redirectErrorStream) { + builder.redirectErrorStream(true); + } + if (redirectErrorInherit) { + builder.redirectError(ProcessBuilder.Redirect.INHERIT); + } + return builder; + } + + public Process start() throws IOException { + return getBuilder().start(); + } + + static CommandWrapper create() { + return new CommandWrapper(); + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java b/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java new file mode 100644 index 0000000000..bab865eee2 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java @@ -0,0 +1,92 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.google.cloud.testing; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Simplified wrapper for emulator's versions. + */ +class Version implements Comparable { + + private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)$"); + + private final int major; + private final int minor; + private final int patch; + + private Version(int major, int minor, int patch) { + this.major = major; + this.minor = minor; + this.patch = patch; + } + + @Override + public int compareTo(Version version) { + int result = major - version.major; + if (result == 0) { + result = minor - version.minor; + if (result == 0) { + result = patch - version.patch; + } + } + return result; + } + + @Override + public String toString() { + return String.format("%d.%d.%d", major, minor, patch); + } + + @Override + public boolean equals(Object other) { + return this == other || other instanceof Version && compareTo((Version) other) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(major, minor, patch); + } + + int getMajor() { + return major; + } + + int getMinor() { + return minor; + } + + int getPatch() { + return patch; + } + + static Version fromString(String version) { + Matcher matcher = VERSION_PATTERN.matcher(checkNotNull(version)); + if (matcher.matches()) { + return new Version( + Integer.valueOf(matcher.group(1)), + Integer.valueOf(matcher.group(2)), + Integer.valueOf(matcher.group(3))); + } + throw new IllegalArgumentException("Invalid version format"); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java new file mode 100644 index 0000000000..7219dcf802 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java @@ -0,0 +1,120 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.testing; + +import com.google.api.client.util.Charsets; +import com.google.cloud.ServiceOptions; +import com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner; +import com.google.common.collect.ImmutableList; + +import org.easymock.EasyMock; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.logging.Logger; + +public class BaseEmulatorHelperTest { + + private static final String BLOCK_UNTIL = "Block until"; + + private static class TestEmulatorHelper extends BaseEmulatorHelper { + + private final List runners; + private final String blockUntil; + + private TestEmulatorHelper(List runners, String blockUntil) { + super("emulator", 1, "project"); + this.runners = runners; + this.blockUntil = blockUntil; + } + + @Override + protected List getEmulatorRunners() { + return runners; + } + + @Override + protected Logger getLogger() { + return null; + } + + @Override + public ServiceOptions getOptions() { + return null; + } + + @Override + public void start() throws IOException, InterruptedException { + startProcess(blockUntil); + } + + @Override + public void stop() throws IOException, InterruptedException { + stopProcess(); + } + + @Override + public void reset() throws IOException { + // do nothing + } + } + + @Test + public void testEmulatorHelper() throws IOException, InterruptedException { + Process process = EasyMock.createStrictMock(Process.class); + InputStream stream = new ByteArrayInputStream(BLOCK_UNTIL.getBytes(Charsets.UTF_8)); + EmulatorRunner emulatorRunner = EasyMock.createStrictMock(EmulatorRunner.class); + EasyMock.expect(process.getInputStream()).andReturn(stream); + EasyMock.expect(emulatorRunner.isAvailable()).andReturn(true); + emulatorRunner.start(); + EasyMock.expectLastCall(); + EasyMock.expect(emulatorRunner.getProcess()).andReturn(process); + emulatorRunner.stop(); + EasyMock.expectLastCall(); + EasyMock.replay(process, emulatorRunner); + TestEmulatorHelper helper = + new TestEmulatorHelper(ImmutableList.of(emulatorRunner), BLOCK_UNTIL); + helper.start(); + helper.stop(); + EasyMock.verify(); + } + + @Test + public void testEmulatorHelperMultipleRunners() throws IOException, InterruptedException { + Process process = EasyMock.createStrictMock(Process.class); + InputStream stream = new ByteArrayInputStream(BLOCK_UNTIL.getBytes(Charsets.UTF_8)); + EmulatorRunner firstRunner = EasyMock.createStrictMock(EmulatorRunner.class); + EmulatorRunner secondRunner = EasyMock.createStrictMock(EmulatorRunner.class); + EasyMock.expect(process.getInputStream()).andReturn(stream); + EasyMock.expect(firstRunner.isAvailable()).andReturn(false); + EasyMock.expect(secondRunner.isAvailable()).andReturn(true); + secondRunner.start(); + EasyMock.expectLastCall(); + EasyMock.expect(secondRunner.getProcess()).andReturn(process); + secondRunner.stop(); + EasyMock.expectLastCall(); + EasyMock.replay(process, secondRunner); + TestEmulatorHelper helper = + new TestEmulatorHelper(ImmutableList.of(firstRunner, secondRunner), BLOCK_UNTIL); + helper.start(); + helper.stop(); + EasyMock.verify(); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java new file mode 100644 index 0000000000..73456f5e3d --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java @@ -0,0 +1,123 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.testing; + +import static org.junit.Assert.assertEquals; + +import com.google.api.client.util.Charsets; +import com.google.common.collect.LinkedHashMultimap; +import com.google.common.collect.Multimap; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Timeout; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class BlockingProcessStreamReaderTest { + + private static final String BLOCK_UNTIL = "Dev App Server is now running"; + private static final String OUTPUT = "First Line\n" + + "Second Line\n" + + BLOCK_UNTIL; + private static final String OUTPUT_WITH_LOGS = "First Line\n" + + BLOCK_UNTIL + "\n" + + "Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" + + "INFO: log line 1\n" + + "log line 2\n" + + "Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" + + "FINE: log line 3\n"; + private static final String TAGGED_OUTPUT_WITH_LOGS = "[emulator] First Line\n" + + "[emulator]" + BLOCK_UNTIL + "\n" + + "[emulator] Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" + + "[emulator] INFO: log line 1\n" + + "[emulator] log line 2\n" + + "[emulator] Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" + + "[emulator] FINE: log line 3\n"; + + + @Rule + public Timeout globalTimeout = Timeout.seconds(10); + + private static final class TestLogger extends Logger { + + private final Multimap logs = LinkedHashMultimap.create(); + + private TestLogger() { + super("text-logger", null); + } + + public void log(Level level, String msg) { + logs.put(level, msg); + } + + Multimap getLogs() { + return logs; + } + } + + @Test + public void testBlockUntil() throws IOException { + InputStream stream = new ByteArrayInputStream(OUTPUT.getBytes(Charsets.UTF_8)); + BlockingProcessStreamReader thread = + BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, null); + thread.terminate(); + stream.close(); + } + + @Test + public void testForwardLogEntry() throws IOException, InterruptedException { + TestLogger logger = new TestLogger(); + InputStream stream = new ByteArrayInputStream(OUTPUT_WITH_LOGS.getBytes(Charsets.UTF_8)); + BlockingProcessStreamReader thread = + BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, logger); + while (logger.getLogs().get(Level.INFO).isEmpty()) { + Thread.sleep(200); + } + assertEquals("[emulator] log line 1" + System.lineSeparator() + "[emulator] log line 2", + logger.getLogs().get(Level.INFO).iterator().next()); + thread.terminate(); + while (logger.getLogs().get(Level.FINE).isEmpty()) { + Thread.sleep(200); + } + assertEquals("[emulator] log line 3", logger.getLogs().get(Level.FINE).iterator().next()); + stream.close(); + } + + @Test + public void testForwardAlreadyTaggedLogs() throws IOException, InterruptedException { + TestLogger logger = new TestLogger(); + InputStream stream = new ByteArrayInputStream(TAGGED_OUTPUT_WITH_LOGS.getBytes(Charsets.UTF_8)); + BlockingProcessStreamReader thread = + BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, logger); + while (logger.getLogs().get(Level.INFO).isEmpty()) { + Thread.sleep(200); + } + assertEquals("[emulator] log line 1" + System.lineSeparator() + "[emulator] log line 2", + logger.getLogs().get(Level.INFO).iterator().next()); + thread.terminate(); + while (logger.getLogs().get(Level.FINE).isEmpty()) { + Thread.sleep(200); + } + assertEquals("[emulator] log line 3", logger.getLogs().get(Level.FINE).iterator().next()); + stream.close(); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java new file mode 100644 index 0000000000..cfea5a03dd --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java @@ -0,0 +1,122 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.testing; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import com.google.common.collect.ImmutableList; + +import org.junit.Test; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +public class CommandWrapperTest { + + private static final List COMMAND = ImmutableList.of("my", "command"); + private static final List WIN_COMMAND = ImmutableList.of("cmd", "/C", "my", "command"); + private static final List UNIX_COMMAND = ImmutableList.of("bash", "my", "command"); + private static final Path DIRECTORY = Paths.get("my-path"); + private static final File WIN_NULL_FILE = new File("NUL:"); + private static final File UNIX_NULL_FILE = new File("/dev/null"); + + @Test + public void testCommandWrapperCommand() { + CommandWrapper commandWrapper = CommandWrapper.create(); + commandWrapper.setCommand(COMMAND); + ProcessBuilder processBuilder = commandWrapper.getBuilder(); + if (BaseEmulatorHelper.isWindows()) { + assertEquals(WIN_COMMAND, processBuilder.command()); + } else { + assertEquals(UNIX_COMMAND, processBuilder.command()); + } + assertNull(processBuilder.directory()); + assertFalse(processBuilder.redirectErrorStream()); + assertEquals(ProcessBuilder.Redirect.PIPE, processBuilder.redirectError()); + } + + @Test + public void testCommandWrapperRedirectErrorStream() { + CommandWrapper commandWrapper = CommandWrapper.create(); + commandWrapper.setCommand(COMMAND); + commandWrapper.setRedirectErrorStream(); + ProcessBuilder processBuilder = commandWrapper.getBuilder(); + if (BaseEmulatorHelper.isWindows()) { + assertEquals(WIN_COMMAND, processBuilder.command()); + } else { + assertEquals(UNIX_COMMAND, processBuilder.command()); + } + assertNull(processBuilder.directory()); + assertTrue(processBuilder.redirectErrorStream()); + assertEquals(ProcessBuilder.Redirect.PIPE, processBuilder.redirectError()); + } + + @Test + public void testCommandWrapperRedirectErrorInherit() { + CommandWrapper commandWrapper = CommandWrapper.create(); + commandWrapper.setCommand(COMMAND); + commandWrapper.setRedirectErrorInherit(); + ProcessBuilder processBuilder = commandWrapper.getBuilder(); + if (BaseEmulatorHelper.isWindows()) { + assertEquals(WIN_COMMAND, processBuilder.command()); + } else { + assertEquals(UNIX_COMMAND, processBuilder.command()); + } + assertNull(processBuilder.directory()); + assertFalse(processBuilder.redirectErrorStream()); + assertEquals(ProcessBuilder.Redirect.INHERIT, processBuilder.redirectError()); + } + + @Test + public void testCommandWrapperDirectory() { + CommandWrapper commandWrapper = CommandWrapper.create(); + commandWrapper.setCommand(COMMAND); + commandWrapper.setDirectory(DIRECTORY); + ProcessBuilder processBuilder = commandWrapper.getBuilder(); + if (BaseEmulatorHelper.isWindows()) { + assertEquals(WIN_COMMAND, processBuilder.command()); + } else { + assertEquals(UNIX_COMMAND, processBuilder.command()); + } + assertEquals(DIRECTORY, processBuilder.directory().toPath()); + assertFalse(processBuilder.redirectErrorStream()); + assertEquals(ProcessBuilder.Redirect.PIPE, processBuilder.redirectError()); + } + + @Test + public void testCommandWrapperRedirectOutputToNull() { + CommandWrapper commandWrapper = CommandWrapper.create(); + commandWrapper.setCommand(COMMAND); + commandWrapper.setRedirectOutputToNull(); + ProcessBuilder processBuilder = commandWrapper.getBuilder(); + if (BaseEmulatorHelper.isWindows()) { + assertEquals(WIN_COMMAND, processBuilder.command()); + assertEquals(ProcessBuilder.Redirect.to(WIN_NULL_FILE), processBuilder.redirectOutput()); + } else { + assertEquals(UNIX_COMMAND, processBuilder.command()); + assertEquals(ProcessBuilder.Redirect.to(UNIX_NULL_FILE), processBuilder.redirectOutput()); + } + assertNull(processBuilder.directory()); + assertFalse(processBuilder.redirectErrorStream()); + assertEquals(ProcessBuilder.Redirect.PIPE, processBuilder.redirectError()); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java new file mode 100644 index 0000000000..163cf3c3fd --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java @@ -0,0 +1,85 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.testing; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class VersionTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testFromString() { + Version version = Version.fromString("2016.01.13"); + assertEquals(2016, version.getMajor()); + assertEquals(1, version.getMinor()); + assertEquals(13, version.getPatch()); + version = Version.fromString("1.2.0"); + assertEquals(1, version.getMajor()); + assertEquals(2, version.getMinor()); + assertEquals(0, version.getPatch()); + } + + @Test + public void testFromStringWithAlphas() { + thrown.expect(IllegalArgumentException.class); + Version.fromString("2016.01.hello"); + } + + @Test + public void testFromStringMissingPatch() { + thrown.expect(IllegalArgumentException.class); + Version.fromString("2016.01"); + } + + @Test + public void testFromStringMissingMinor() { + thrown.expect(IllegalArgumentException.class); + Version.fromString("2016"); + } + + @Test + public void testFromStringEmpty() { + thrown.expect(IllegalArgumentException.class); + Version.fromString(""); + } + + @Test + public void testFromStringNull() { + thrown.expect(NullPointerException.class); + Version.fromString(null); + } + + @Test + public void testCompare() { + Version version = Version.fromString("2016.01.13"); + Version sameVersion = Version.fromString("2016.01.13"); + Version olderVersion = Version.fromString("2015.12.01"); + Version newerVersion = Version.fromString("2016.08.12"); + assertEquals(0, version.compareTo(sameVersion)); + assertTrue(version.compareTo(olderVersion) > 0); + assertTrue(version.compareTo(newerVersion) < 0); + Version otherVersion = Version.fromString("1.2.0"); + assertTrue(version.compareTo(otherVersion) > 0); + } +} From 15b74378eb66ff9642874fe575586cf142603bc1 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 10 Nov 2016 11:14:46 +0100 Subject: [PATCH 242/663] Regenerating spi layer - GAX 0.0.22 (#1379) * Regenerating spi layer - GAX 0.0.22 * Update options and spi classes to catch GAX changes --- google-cloud-core/pom.xml | 2 +- .../com/google/cloud/GrpcServiceOptions.java | 25 ++++++++----------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index cb46970a79..dc84fa0015 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -111,7 +111,7 @@ com.google.api gax - 0.0.21 + 0.0.22 io.grpc diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java index 25cd8a29cc..c550724c6f 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java @@ -18,8 +18,10 @@ import static com.google.common.base.MoreObjects.firstNonNull; -import com.google.api.gax.core.ConnectionSettings; +import com.google.api.gax.core.FixedCredentialsProvider; import com.google.api.gax.core.RetrySettings; +import com.google.api.gax.grpc.ChannelProvider; +import com.google.api.gax.grpc.InstantiatingChannelProvider; import com.google.api.gax.grpc.UnaryCallSettings; import com.google.auth.Credentials; import com.google.cloud.spi.ServiceRpcFactory; @@ -304,26 +306,19 @@ protected UnaryCallSettings.Builder getApiCallSettings() { } /** - * Returns a builder for connection-related settings. + * Returns a channel provider. */ - @Deprecated - protected ConnectionSettings.Builder connectionSettings() { - return getConnectionSettings(); - } - - /** - * Returns a builder for connection-related settings. - */ - protected ConnectionSettings.Builder getConnectionSettings() { + protected ChannelProvider getChannelProvider() { HostAndPort hostAndPort = HostAndPort.fromString(getHost()); - ConnectionSettings.Builder builder = ConnectionSettings.newBuilder() + InstantiatingChannelProvider.Builder builder = InstantiatingChannelProvider.newBuilder() .setServiceAddress(hostAndPort.getHostText()) - .setPort(hostAndPort.getPort()); + .setPort(hostAndPort.getPort()) + .setClientLibHeader(getLibraryName(), firstNonNull(getLibraryVersion(), "")); Credentials scopedCredentials = getScopedCredentials(); if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { - builder.provideCredentialsWith(scopedCredentials); + builder.setCredentialsProvider(FixedCredentialsProvider.create(scopedCredentials)); } - return builder; + return builder.build(); } /** From c6495e6d3309a62985621e9c0d29fcae34b23109 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 11 Nov 2016 11:59:47 +0100 Subject: [PATCH 243/663] Change BaseWriteChannel.position type to long to fix overflow (#1390) --- .../java/com/google/cloud/BaseWriteChannel.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index aaef34149f..4d01a60e44 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -41,7 +41,7 @@ public abstract class BaseWriteChannel< private final ServiceOptionsT options; private final EntityT entity; private final String uploadId; - private int position; + private long position; private byte[] buffer = new byte[0]; private int limit; private boolean isOpen = true; @@ -101,11 +101,11 @@ protected String getUploadId() { } @Deprecated - protected int position() { + protected long position() { return getPosition(); } - protected int getPosition() { + protected long getPosition() { return position; } @@ -119,7 +119,7 @@ protected byte[] getBuffer() { } @Deprecated - protected int limit() { + protected long limit() { return getLimit(); } @@ -245,7 +245,7 @@ protected abstract static class BaseState< protected final ServiceOptionsT serviceOptions; protected final EntityT entity; protected final String uploadId; - protected final int position; + protected final long position; protected final byte[] buffer; protected final boolean isOpen; protected final int chunkSize; @@ -274,7 +274,7 @@ public abstract static class Builder< private final ServiceOptionsT serviceOptions; private final EntityT entity; private final String uploadId; - private int position; + private long position; private byte[] buffer; private boolean isOpen; private int chunkSize; @@ -290,7 +290,7 @@ public Builder position(int position) { return setPosition(position); } - public Builder setPosition(int position) { + public Builder setPosition(long position) { this.position = position; return this; } From 8078e71becf58c8b4361fe88fe47416da904eb5c Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 14 Nov 2016 14:24:53 +0100 Subject: [PATCH 244/663] Make TableDataWriteChannel expose Job when upload completed --- .../main/java/com/google/cloud/BaseWriteChannel.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index 4d01a60e44..f7a67deece 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -352,14 +352,17 @@ public boolean equals(Object obj) { && this.chunkSize == other.chunkSize; } - @Override - public String toString() { + protected MoreObjects.ToStringHelper toStringHelper() { return MoreObjects.toStringHelper(this) .add("entity", entity) .add("uploadId", uploadId) .add("position", position) - .add("isOpen", isOpen) - .toString(); + .add("isOpen", isOpen); + } + + @Override + public String toString() { + return toStringHelper().toString(); } } } From 12bfc7c80c333b45897ee5914635f8922e36d514 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 14 Nov 2016 19:42:00 +0100 Subject: [PATCH 245/663] Release 0.6.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index dc84fa0015..37104fc206 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.5.2-SNAPSHOT + 0.6.0 google-cloud-core From bcbbc8680590704fa332528f7cd0cba3632a89a0 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Tue, 15 Nov 2016 01:48:55 +0000 Subject: [PATCH 246/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 1665163a9f..e804bf61a7 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.5.1 + 0.6.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.5.1' +compile 'com.google.cloud:google-cloud-core:0.6.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.5.1" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.6.0" ``` Troubleshooting From cda2f593af2bcd94dc3362debc6ab584e872f425 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 15 Nov 2016 04:03:26 +0100 Subject: [PATCH 247/663] Update version to 0.6.1-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 37104fc206..6ec0b5ddfc 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.6.0 + 0.6.1-SNAPSHOT google-cloud-core From 04a3f8cd0f95b5490b2120810fe8bea1ba002f61 Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Thu, 17 Nov 2016 15:24:49 -0600 Subject: [PATCH 248/663] Update gax (#1404) * Update gax * Update language * Error reporting * Logging * Update pubsub * Monitoring * Speech, trace, vision --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6ec0b5ddfc..be95c37cec 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -111,7 +111,7 @@ com.google.api gax - 0.0.22 + 0.0.23 io.grpc From ac0222592f7f0ea0d9ae0300e0e93a561a9e9cd3 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Tue, 22 Nov 2016 08:50:29 -0800 Subject: [PATCH 249/663] SPI layer: renaming Api to Client (#1417) --- google-cloud-core/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index be95c37cec..a5aab2b27e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -111,7 +111,7 @@ com.google.api gax - 0.0.23 + 0.0.24 io.grpc @@ -122,7 +122,7 @@ com.google.api.grpc grpc-google-common-protos - 0.1.0 + 0.1.3 io.grpc @@ -133,7 +133,7 @@ com.google.api.grpc grpc-google-iam-v1 - 0.1.0 + 0.1.3 io.grpc From f0b3ab05f5875a71d1a1add5e5b127a23e59c01d Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Tue, 22 Nov 2016 15:38:35 -0800 Subject: [PATCH 250/663] SPI updates: logging docs, LRO support (#1419) * Logging API: updating docs from proto * Speech API: introducing OperationFuture and OperationCallable to make handling of long-running operations easier --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a5aab2b27e..13a1cc332b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -111,7 +111,7 @@ com.google.api gax - 0.0.24 + 0.0.25 io.grpc From 1dd9ac0d2621a0460c5ad723624242e7f3d90cb6 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Thu, 24 Nov 2016 09:54:25 -0800 Subject: [PATCH 251/663] Release 0.7.0 (#1422) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 13a1cc332b..a5f4ecd27b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.6.1-SNAPSHOT + 0.7.0 google-cloud-core From 22fc62a35183df7c2c957a478a94dda1213bb234 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Thu, 24 Nov 2016 18:21:50 -0800 Subject: [PATCH 252/663] Updating version in README files. (#1424) --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index e804bf61a7..a248cc79f1 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.6.0 + 0.7.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.6.0' +compile 'com.google.cloud:google-cloud-core:0.7.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.6.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.7.0" ``` Troubleshooting From 1c8d8757deb416160292cecc587f8d2691a5928e Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Thu, 24 Nov 2016 18:32:46 -0800 Subject: [PATCH 253/663] Update version to 0.7.1-SNAPSHOT (#1426) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a5f4ecd27b..b35e5d4e4f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.7.0 + 0.7.1-SNAPSHOT google-cloud-core From d7d8e1732a5216f47145a97c9dde1985e9cdf18c Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Thu, 1 Dec 2016 14:38:29 -0800 Subject: [PATCH 254/663] Make defaultLibraryVersion() more robust (#1436) --- .../java/com/google/cloud/ServiceOptions.java | 39 ++++++++++++++++--- .../com/google/cloud/ServiceOptionsTest.java | 2 +- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index c14c770e3b..b7148f0a82 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -48,6 +48,7 @@ import java.util.Enumeration; import java.util.Locale; import java.util.Objects; +import java.util.Properties; import java.util.ServiceLoader; import java.util.Set; import java.util.jar.Attributes; @@ -72,12 +73,15 @@ public abstract class ServiceOptions, Service private static final String MANIFEST_ARTIFACT_ID_KEY = "artifactId"; private static final String MANIFEST_VERSION_KEY = "Implementation-Version"; private static final String ARTIFACT_ID = "google-cloud-core"; - private static final String LIBRARY_NAME = "gcloud-java"; + private static final String LIBRARY_NAME = "google-cloud-java"; private static final String LIBRARY_VERSION = defaultLibraryVersion(); private static final String APPLICATION_NAME = LIBRARY_VERSION == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + LIBRARY_VERSION; private static final long serialVersionUID = -5714029257168617973L; + private static final String META_FILE_ROOT = "/META-INF/maven/"; + private static final String META_VERSION_KEY = "version"; + private final String projectId; private final String host; private final RetryParams retryParams; @@ -566,7 +570,7 @@ public Clock getClock() { } /** - * Returns the application's name as a string in the format {@code gcloud-java/[version]}. + * Returns the application's name as a string in the format {@code google-cloud-java/[version]}. */ @Deprecated public String applicationName() { @@ -574,14 +578,14 @@ public String applicationName() { } /** - * Returns the application's name as a string in the format {@code gcloud-java/[version]}. + * Returns the application's name as a string in the format {@code google-cloud-java/[version]}. */ public String getApplicationName() { return APPLICATION_NAME; } /** - * Returns the library's name, {@code gcloud-java}, as a string. + * Returns the library's name, {@code google-cloud-java}, as a string. */ @Deprecated public String libraryName() { @@ -589,7 +593,7 @@ public String libraryName() { } /** - * Returns the library's name, {@code gcloud-java}, as a string. + * Returns the library's name, {@code google-cloud-java}, as a string. */ public String getLibraryName() { return LIBRARY_NAME; @@ -676,6 +680,31 @@ static T getFromServiceLoader(Class clazz, T defaultInstance) { } private static String defaultLibraryVersion() { + String version = getPomVersion(); + if (version == null) { + version = getManifestVersion(); + } + return version; + } + + private static String getPomVersion() { + try { + Properties properties = new Properties(); + String mavenPropertiesPath = META_FILE_ROOT + + ServiceOptions.class.getPackage().getName() + "/" + + ARTIFACT_ID + "/pom.properties"; + InputStream inputStream = ServiceOptions.class.getResourceAsStream(mavenPropertiesPath); + if (inputStream != null) { + properties.load(inputStream); + return properties.getProperty(META_VERSION_KEY, ""); + } + } catch (Exception e) { + // ignore + } + return null; + } + + private static String getManifestVersion() { String version = null; try { Enumeration resources = diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index cf364db57e..797c0ac72b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -102,7 +102,7 @@ public class ServiceOptionsTest { private static final TestServiceOptions DEPRECATED_DEFAULT_OPTIONS = TestServiceOptions.newBuilder().projectId("project-id").build(); private static final TestServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); - private static final String LIBRARY_NAME = "gcloud-java"; + private static final String LIBRARY_NAME = "google-cloud-java"; private static final Pattern APPLICATION_NAME_PATTERN = Pattern.compile(LIBRARY_NAME + "(/[0-9]+.[0-9]+.[0-9]+)?"); From cdf47b90ed8debba05bce936c9b9e4fbba831ec5 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Mon, 5 Dec 2016 12:57:48 -0800 Subject: [PATCH 255/663] Revert library name to gcloud-java (#1444) --- .../src/main/java/com/google/cloud/ServiceOptions.java | 10 +++++----- .../test/java/com/google/cloud/ServiceOptionsTest.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index b7148f0a82..755b81354e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -73,7 +73,7 @@ public abstract class ServiceOptions, Service private static final String MANIFEST_ARTIFACT_ID_KEY = "artifactId"; private static final String MANIFEST_VERSION_KEY = "Implementation-Version"; private static final String ARTIFACT_ID = "google-cloud-core"; - private static final String LIBRARY_NAME = "google-cloud-java"; + private static final String LIBRARY_NAME = "gcloud-java"; private static final String LIBRARY_VERSION = defaultLibraryVersion(); private static final String APPLICATION_NAME = LIBRARY_VERSION == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + LIBRARY_VERSION; @@ -570,7 +570,7 @@ public Clock getClock() { } /** - * Returns the application's name as a string in the format {@code google-cloud-java/[version]}. + * Returns the application's name as a string in the format {@code gcloud-java/[version]}. */ @Deprecated public String applicationName() { @@ -578,14 +578,14 @@ public String applicationName() { } /** - * Returns the application's name as a string in the format {@code google-cloud-java/[version]}. + * Returns the application's name as a string in the format {@code gcloud-java/[version]}. */ public String getApplicationName() { return APPLICATION_NAME; } /** - * Returns the library's name, {@code google-cloud-java}, as a string. + * Returns the library's name, {@code gcloud-java}, as a string. */ @Deprecated public String libraryName() { @@ -593,7 +593,7 @@ public String libraryName() { } /** - * Returns the library's name, {@code google-cloud-java}, as a string. + * Returns the library's name, {@code gcloud-java}, as a string. */ public String getLibraryName() { return LIBRARY_NAME; diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 797c0ac72b..cf364db57e 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -102,7 +102,7 @@ public class ServiceOptionsTest { private static final TestServiceOptions DEPRECATED_DEFAULT_OPTIONS = TestServiceOptions.newBuilder().projectId("project-id").build(); private static final TestServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); - private static final String LIBRARY_NAME = "google-cloud-java"; + private static final String LIBRARY_NAME = "gcloud-java"; private static final Pattern APPLICATION_NAME_PATTERN = Pattern.compile(LIBRARY_NAME + "(/[0-9]+.[0-9]+.[0-9]+)?"); From 1cbfdd4f5fc9f88278e280b0224ce866d5b2ba66 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 9 Dec 2016 03:07:48 +1100 Subject: [PATCH 256/663] pubsub: fix testStartStopReset (#1453) The test verifies that calling stop() actually stops the emulator. The previous implementation stops the emulator by - sending HTTP POST to /shutdown - terminating the emulator process The second step follows directly after the first. It then queries the server it just shut down to make sure it does not respond. This behavior is incorrect for two reasons. - The server might continue serving request after responding to /shutdown. - The "emulator process" might not be the emulator at all. It might be a script that in-turn runs the emulator. On UNIX systems, killing a parent process does not kill any of its children; the actual emulator might run indefinitely after we kill the process we spawned. This commit changes this behavior. After POSTing to /shutdown, we simply wait for the spawned process to terminate on its own. Technically, there is still a race: Another emulator could have been started on the same port. When we send a request to verify that the old emulator has terminated, we might get a response from the new one. Since we execute tests sequentially though, I believe this should not be a problem in practice. --- .../cloud/testing/BaseEmulatorHelper.java | 67 ++++++++++++++----- .../cloud/testing/BaseEmulatorHelperTest.java | 22 +++--- 2 files changed, 63 insertions(+), 26 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index 65277a7746..dee22e596c 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -18,6 +18,8 @@ import com.google.cloud.ServiceOptions; import com.google.common.io.CharStreams; +import com.google.common.util.concurrent.SettableFuture; +import com.google.common.util.concurrent.UncheckedExecutionException; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -43,10 +45,14 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import org.joda.time.Duration; /** * Utility class to start and stop a local service which is used by unit testing. @@ -104,16 +110,50 @@ protected final void startProcess(String blockUntilOutput) } /** - * Stops the local service's subprocess and any possible thread listening for its output. + * Waits for the local service's subprocess to terminate, + * and stop any possible thread listening for its output. */ - protected final void stopProcess() throws IOException, InterruptedException { + protected final int waitForProcess(Duration timeout) throws IOException, InterruptedException, TimeoutException { if (blockingProcessReader != null) { blockingProcessReader.terminate(); blockingProcessReader = null; } if (activeRunner != null) { - activeRunner.stop(); + int exitCode = activeRunner.waitFor(timeout); activeRunner = null; + return exitCode; + } + return 0; + } + + private static int waitForProcess(final Process process, Duration timeout) throws InterruptedException, TimeoutException { + if (process == null) { + return 0; + } + + final SettableFuture exitValue = SettableFuture.create(); + + Thread waiter = new Thread(new Runnable() { + @Override + public void run() { + try { + exitValue.set(process.waitFor()); + } catch (InterruptedException e) { + exitValue.setException(e); + } + } + }); + waiter.start(); + + try { + return exitValue.get(timeout.getMillis(), TimeUnit.MILLISECONDS); + } catch (ExecutionException e) { + if (e.getCause() instanceof InterruptedException) { + throw (InterruptedException) e.getCause(); + } + throw new UncheckedExecutionException(e); + } finally { + waiter.interrupt(); } } @@ -144,7 +184,7 @@ public String getProjectId() { /** * Stops the local emulator. */ - public abstract void stop() throws IOException, InterruptedException; + public abstract void stop(Duration timeout) throws IOException, InterruptedException, TimeoutException; /** * Resets the internal state of the emulator. @@ -195,9 +235,10 @@ protected interface EmulatorRunner { void start() throws IOException; /** - * Stops the emulator associated to this runner. + * Wait for the emulator associated to this runner to terminate, + * returning the exit status. */ - void stop() throws InterruptedException; + int waitFor(Duration timeout) throws InterruptedException, TimeoutException; /** * Returns the process associated to the emulator, if any. @@ -239,11 +280,8 @@ public void start() throws IOException { } @Override - public void stop() throws InterruptedException { - if (process != null) { - process.destroy(); - process.waitFor(); - } + public int waitFor(Duration timeout) throws InterruptedException, TimeoutException { + return waitForProcess(process, timeout); } @Override @@ -337,11 +375,8 @@ public void start() throws IOException { } @Override - public void stop() throws InterruptedException { - if (process != null) { - process.destroy(); - process.waitFor(); - } + public int waitFor(Duration timeout) throws InterruptedException, TimeoutException { + return waitForProcess(process, timeout); } @Override diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java index 7219dcf802..b4b2579f73 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java @@ -22,12 +22,14 @@ import com.google.common.collect.ImmutableList; import org.easymock.EasyMock; +import org.joda.time.Duration; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.List; +import java.util.concurrent.TimeoutException; import java.util.logging.Logger; public class BaseEmulatorHelperTest { @@ -66,8 +68,8 @@ public void start() throws IOException, InterruptedException { } @Override - public void stop() throws IOException, InterruptedException { - stopProcess(); + public void stop(Duration timeout) throws IOException, InterruptedException, TimeoutException { + waitForProcess(timeout); } @Override @@ -77,7 +79,7 @@ public void reset() throws IOException { } @Test - public void testEmulatorHelper() throws IOException, InterruptedException { + public void testEmulatorHelper() throws IOException, InterruptedException, TimeoutException { Process process = EasyMock.createStrictMock(Process.class); InputStream stream = new ByteArrayInputStream(BLOCK_UNTIL.getBytes(Charsets.UTF_8)); EmulatorRunner emulatorRunner = EasyMock.createStrictMock(EmulatorRunner.class); @@ -86,18 +88,18 @@ public void testEmulatorHelper() throws IOException, InterruptedException { emulatorRunner.start(); EasyMock.expectLastCall(); EasyMock.expect(emulatorRunner.getProcess()).andReturn(process); - emulatorRunner.stop(); - EasyMock.expectLastCall(); + emulatorRunner.waitFor(Duration.standardMinutes(1)); + EasyMock.expectLastCall().andReturn(0); EasyMock.replay(process, emulatorRunner); TestEmulatorHelper helper = new TestEmulatorHelper(ImmutableList.of(emulatorRunner), BLOCK_UNTIL); helper.start(); - helper.stop(); + helper.stop(Duration.standardMinutes(1)); EasyMock.verify(); } @Test - public void testEmulatorHelperMultipleRunners() throws IOException, InterruptedException { + public void testEmulatorHelperMultipleRunners() throws IOException, InterruptedException, TimeoutException { Process process = EasyMock.createStrictMock(Process.class); InputStream stream = new ByteArrayInputStream(BLOCK_UNTIL.getBytes(Charsets.UTF_8)); EmulatorRunner firstRunner = EasyMock.createStrictMock(EmulatorRunner.class); @@ -108,13 +110,13 @@ public void testEmulatorHelperMultipleRunners() throws IOException, InterruptedE secondRunner.start(); EasyMock.expectLastCall(); EasyMock.expect(secondRunner.getProcess()).andReturn(process); - secondRunner.stop(); - EasyMock.expectLastCall(); + secondRunner.waitFor(Duration.standardMinutes(1)); + EasyMock.expectLastCall().andReturn(0); EasyMock.replay(process, secondRunner); TestEmulatorHelper helper = new TestEmulatorHelper(ImmutableList.of(firstRunner, secondRunner), BLOCK_UNTIL); helper.start(); - helper.stop(); + helper.stop(Duration.standardMinutes(1)); EasyMock.verify(); } } From 8747d94783e96da651adfd9883bcf7be21ab8c92 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 9 Dec 2016 03:15:34 +1100 Subject: [PATCH 257/663] simplify BlockingProcessStreamReader; fix tests (#1457) This commit simplifies the main run() method. Previous implementation checks whether the underlying Reader is ready to read then either reads a line or sleeps, catching InterruptedException to watch for any thread interruption. There are subtle difficulties with this approach: - Even if the underlying Reader is ready to read, it might not have enough bytes to form a line. It might still block. - It's not necessary to sleep. If the thread is interrupted while reading. It should throw InterruptedIOException. The method now reads in a loop, waiting for either exceptions or EOF. The test class implements a mock Logger that logs to a data structure. It then verifies that the data structure holds appropriate logs. As implemented, this can cause a race, as two threads, the writer and the verifier, run concurrently. This commit fixes this by waiting for the writing thread to terminate before verifying. --- .../testing/BlockingProcessStreamReader.java | 31 ++++++------------- .../BlockingProcessStreamReaderTest.java | 20 ++---------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java index 988b6593a1..0fa10dcace 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java @@ -35,7 +35,6 @@ */ class BlockingProcessStreamReader extends Thread { - private static final int STREAM_READER_SLEEP_INTERVAL_IN_MS = 200; private static final int LOG_LENGTH_LIMIT = 50000; private final BufferedReader errorReader; @@ -43,7 +42,6 @@ class BlockingProcessStreamReader extends Thread { private StringBuilder currentLog; private Level currentLogLevel; private boolean collectionMode; - private volatile boolean terminated; private final String emulatorTag; private final Pattern logLinePattern; @@ -64,8 +62,6 @@ private BlockingProcessStreamReader(String emulator, InputStream stream, String } void terminate() throws IOException { - terminated = true; - errorReader.close(); interrupt(); } @@ -73,25 +69,18 @@ void terminate() throws IOException { public void run() { String previousLine = ""; String nextLine = ""; - while (!terminated) { - try { - if (errorReader.ready()) { - previousLine = nextLine; - nextLine = errorReader.readLine(); - if (nextLine == null) { - terminated = true; - } else { - processLogLine(previousLine, nextLine); - } - } else { - sleep(STREAM_READER_SLEEP_INTERVAL_IN_MS); + try { + for (;;) { + previousLine = nextLine; + nextLine = errorReader.readLine(); + if (nextLine == null) { + break; } - } catch (IOException e) { + processLogLine(previousLine, nextLine); + } + } catch (IOException e) { + if (!isInterrupted()) { e.printStackTrace(System.err); - } catch (InterruptedException e) { - previousLine = nextLine; - nextLine = null; - break; } } processLogLine(previousLine, firstNonNull(nextLine, "")); diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java index 73456f5e3d..6dedcb55b6 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java @@ -87,17 +87,9 @@ public void testBlockUntil() throws IOException { public void testForwardLogEntry() throws IOException, InterruptedException { TestLogger logger = new TestLogger(); InputStream stream = new ByteArrayInputStream(OUTPUT_WITH_LOGS.getBytes(Charsets.UTF_8)); - BlockingProcessStreamReader thread = - BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, logger); - while (logger.getLogs().get(Level.INFO).isEmpty()) { - Thread.sleep(200); - } + BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, logger).join(); assertEquals("[emulator] log line 1" + System.lineSeparator() + "[emulator] log line 2", logger.getLogs().get(Level.INFO).iterator().next()); - thread.terminate(); - while (logger.getLogs().get(Level.FINE).isEmpty()) { - Thread.sleep(200); - } assertEquals("[emulator] log line 3", logger.getLogs().get(Level.FINE).iterator().next()); stream.close(); } @@ -106,17 +98,9 @@ public void testForwardLogEntry() throws IOException, InterruptedException { public void testForwardAlreadyTaggedLogs() throws IOException, InterruptedException { TestLogger logger = new TestLogger(); InputStream stream = new ByteArrayInputStream(TAGGED_OUTPUT_WITH_LOGS.getBytes(Charsets.UTF_8)); - BlockingProcessStreamReader thread = - BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, logger); - while (logger.getLogs().get(Level.INFO).isEmpty()) { - Thread.sleep(200); - } + BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, logger).join(); assertEquals("[emulator] log line 1" + System.lineSeparator() + "[emulator] log line 2", logger.getLogs().get(Level.INFO).iterator().next()); - thread.terminate(); - while (logger.getLogs().get(Level.FINE).isEmpty()) { - Thread.sleep(200); - } assertEquals("[emulator] log line 3", logger.getLogs().get(Level.FINE).iterator().next()); stream.close(); } From 817c8bb2c92105b786f7da23204154052ba5230e Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Thu, 8 Dec 2016 14:34:48 -0800 Subject: [PATCH 258/663] Release 0.8.0, bump four APIs to beta (#1465) As part of this, introducing some new pom properties: * core.version: version of google-cloud-core * beta.version: version used by beta APIs (which is the project version plus -beta) * storage.version: the version of google-cloud-storage (since several APIs depend on it) Lastly, removing "(Alpha)" from titles in README files except the root README file, because it's hard to keep all those tags up to date. --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b35e5d4e4f..34614cdf1b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.7.1-SNAPSHOT + 0.8.0 google-cloud-core From d94830802f20a6ba6c92b2b20b1d85c47a61bf5a Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Fri, 9 Dec 2016 10:08:58 -0800 Subject: [PATCH 259/663] Update version to 0.8.1-SNAPSHOT (#1467) Also, update versions in README to 0.8.0 --- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index a248cc79f1..f711365e18 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.7.0 + 0.8.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.7.0' +compile 'com.google.cloud:google-cloud-core:0.8.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.7.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 34614cdf1b..489d27cdf1 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.8.0 + 0.8.1-SNAPSHOT google-cloud-core From 6e4c292471c68c6b6a66314bfb08447742f7d5b8 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Mon, 12 Dec 2016 17:34:52 +1100 Subject: [PATCH 260/663] fix more races in pubsub tests Previously BlockingProcessStreamReader has a terminate() method, used to tell the Reader to stop reading from the emulator process. This causes an inter-process race. If the Reader stops before reading emulator's output, the emulator process will hang as it tries to write to stdout/stderr as there's no one to read from the other side of the pipe. Since there is no way to safely stop the Reader, this commit deletes the method and its associated test. Additionally, the timeout for LocalSystemTest is increased to 3 minutes, since the emulator, somehow, consistently takes just longer than a minute to shut down. --- .../com/google/cloud/testing/BaseEmulatorHelper.java | 8 ++++---- .../cloud/testing/BlockingProcessStreamReader.java | 8 +------- .../cloud/testing/BlockingProcessStreamReaderTest.java | 9 --------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index dee22e596c..2b4276068d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -114,15 +114,15 @@ protected final void startProcess(String blockUntilOutput) * and stop any possible thread listening for its output. */ protected final int waitForProcess(Duration timeout) throws IOException, InterruptedException, TimeoutException { - if (blockingProcessReader != null) { - blockingProcessReader.terminate(); - blockingProcessReader = null; - } if (activeRunner != null) { int exitCode = activeRunner.waitFor(timeout); activeRunner = null; return exitCode; } + if (blockingProcessReader != null) { + blockingProcessReader.join(); + blockingProcessReader = null; + } return 0; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java index 0fa10dcace..f4e69b9b6e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java @@ -61,10 +61,6 @@ private BlockingProcessStreamReader(String emulator, InputStream stream, String } } - void terminate() throws IOException { - interrupt(); - } - @Override public void run() { String previousLine = ""; @@ -79,9 +75,7 @@ public void run() { processLogLine(previousLine, nextLine); } } catch (IOException e) { - if (!isInterrupted()) { - e.printStackTrace(System.err); - } + e.printStackTrace(System.err); } processLogLine(previousLine, firstNonNull(nextLine, "")); writeLog(); diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java index 6dedcb55b6..1b22c9f3ff 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java @@ -74,15 +74,6 @@ Multimap getLogs() { } } - @Test - public void testBlockUntil() throws IOException { - InputStream stream = new ByteArrayInputStream(OUTPUT.getBytes(Charsets.UTF_8)); - BlockingProcessStreamReader thread = - BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, null); - thread.terminate(); - stream.close(); - } - @Test public void testForwardLogEntry() throws IOException, InterruptedException { TestLogger logger = new TestLogger(); From c7b904d4f68aee97b02e3b0cf91710b0c404028c Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Tue, 13 Dec 2016 14:34:16 +1100 Subject: [PATCH 261/663] make pubsub high perf compile (#1474) * merge from master * make pubsub high perf compile * make AckDeadlineRenewerTest pass --- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 2 +- .../com/google/cloud/testing/BaseEmulatorHelper.java | 8 ++++---- .../cloud/testing/BlockingProcessStreamReader.java | 8 +------- .../cloud/testing/BlockingProcessStreamReaderTest.java | 9 --------- 5 files changed, 9 insertions(+), 24 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index a248cc79f1..f711365e18 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.7.0 + 0.8.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.7.0' +compile 'com.google.cloud:google-cloud-core:0.8.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.7.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 34614cdf1b..489d27cdf1 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.8.0 + 0.8.1-SNAPSHOT google-cloud-core diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index dee22e596c..2b4276068d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -114,15 +114,15 @@ protected final void startProcess(String blockUntilOutput) * and stop any possible thread listening for its output. */ protected final int waitForProcess(Duration timeout) throws IOException, InterruptedException, TimeoutException { - if (blockingProcessReader != null) { - blockingProcessReader.terminate(); - blockingProcessReader = null; - } if (activeRunner != null) { int exitCode = activeRunner.waitFor(timeout); activeRunner = null; return exitCode; } + if (blockingProcessReader != null) { + blockingProcessReader.join(); + blockingProcessReader = null; + } return 0; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java index 0fa10dcace..f4e69b9b6e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java @@ -61,10 +61,6 @@ private BlockingProcessStreamReader(String emulator, InputStream stream, String } } - void terminate() throws IOException { - interrupt(); - } - @Override public void run() { String previousLine = ""; @@ -79,9 +75,7 @@ public void run() { processLogLine(previousLine, nextLine); } } catch (IOException e) { - if (!isInterrupted()) { - e.printStackTrace(System.err); - } + e.printStackTrace(System.err); } processLogLine(previousLine, firstNonNull(nextLine, "")); writeLog(); diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java index 6dedcb55b6..1b22c9f3ff 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java @@ -74,15 +74,6 @@ Multimap getLogs() { } } - @Test - public void testBlockUntil() throws IOException { - InputStream stream = new ByteArrayInputStream(OUTPUT.getBytes(Charsets.UTF_8)); - BlockingProcessStreamReader thread = - BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, null); - thread.terminate(); - stream.close(); - } - @Test public void testForwardLogEntry() throws IOException, InterruptedException { TestLogger logger = new TestLogger(); From 463fe1fee7cd1471dc86dca910044e89a136b951 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Thu, 5 Jan 2017 11:37:06 -0800 Subject: [PATCH 262/663] Regenerating SPI layer (#1501) * Converting Error Reporting and Monitoring to use resource name types * Removing formatX/parseX methods from pubsub, converting usage of the same to resource name types * New methods in Logging and PubSub --- google-cloud-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 489d27cdf1..613c7f1e98 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -122,7 +122,7 @@ com.google.api.grpc grpc-google-common-protos - 0.1.3 + 0.1.5 io.grpc @@ -133,7 +133,7 @@ com.google.api.grpc grpc-google-iam-v1 - 0.1.3 + 0.1.5 io.grpc From 56c58f3670d0a8f1e129dc4131a5ed1b351bece1 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 6 Jan 2017 12:00:13 +1100 Subject: [PATCH 263/663] make pubsub work with new gax (#1505) * make pubsub work with new gax update documentation links too --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 489d27cdf1..d395b23313 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -111,7 +111,7 @@ com.google.api gax - 0.0.25 + 0.0.27 io.grpc From dbc007ed7c630463b96a43cb5e991829353393df Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Mon, 9 Jan 2017 09:08:26 -0800 Subject: [PATCH 264/663] Release 0.8.1 (#1512) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 613c7f1e98..c0bfd8d15e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.8.1-SNAPSHOT + 0.8.1-alpha google-cloud-core From 980fed973e2ca14797d522838dcd265686fddd62 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 9 Jan 2017 17:22:24 -0800 Subject: [PATCH 265/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f711365e18..2f5971b455 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.8.0 + 0.8.1-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.8.0' +compile 'com.google.cloud:google-cloud-core:0.8.1-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.1-alpha" ``` Troubleshooting From e3ae626c59552a8931140ecf57377f68a1beff96 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 9 Jan 2017 17:53:27 -0800 Subject: [PATCH 266/663] Update version to 0.8.2-alpha-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c0bfd8d15e..34974a4965 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.8.1-alpha + 0.8.2-alpha-SNAPSHOT google-cloud-core From 32d0122f5d7e9bbbf6d77ea29ef7cfcd295894d5 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Mon, 30 Jan 2017 21:15:36 +1100 Subject: [PATCH 267/663] use RpcFuture and remove old BundlingSettings (#1572) * use RpcFuture and remove old BundlingSettings --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 34974a4965..47f215f242 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -111,7 +111,7 @@ com.google.api gax - 0.0.25 + 0.0.28 io.grpc From 196d243bef127ae05ddbe7288e6bff3a5f410bfa Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 1 Feb 2017 11:07:51 -0800 Subject: [PATCH 268/663] Release 0.8.2 Note: This version was accidentally released to Sonatype because of experimenting with deployment commands, combined with the fact that autoReleaseAfterClose is set to true. Since releases can't be taken back, we might as well own up to the release and push the code forward. --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 47f215f242..7ad0a8ae40 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.8.2-alpha-SNAPSHOT + 0.8.2-alpha google-cloud-core From 740b52a304e38280b55f1775fbdcb39fc0266e37 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 1 Feb 2017 11:42:59 -0800 Subject: [PATCH 269/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 2f5971b455..a82cc30ff4 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.8.1-alpha + 0.8.2-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.8.1-alpha' +compile 'com.google.cloud:google-cloud-core:0.8.2-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.1-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.2-alpha" ``` Troubleshooting From 5d301054d82782d1dc0b34e747f2255fcb7fd704 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Wed, 1 Feb 2017 15:12:02 -0800 Subject: [PATCH 270/663] Update version to 0.8.3-*-SNAPSHOT (#1583) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7ad0a8ae40..2ddcdcce45 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.8.2-alpha + 0.8.3-alpha-SNAPSHOT google-cloud-core From 14a68900f263910f99310a90b164a60e5c81b6fd Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 3 Feb 2017 13:31:11 -0800 Subject: [PATCH 271/663] Release 0.8.3 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2ddcdcce45..0c5b2a5b15 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.8.3-alpha-SNAPSHOT + 0.8.3-alpha google-cloud-core From c349727b3b5b53fe089852dec95759e7d37c4cea Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 3 Feb 2017 13:31:42 -0800 Subject: [PATCH 272/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index a82cc30ff4..4bafb86270 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.8.2-alpha + 0.8.3-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.8.2-alpha' +compile 'com.google.cloud:google-cloud-core:0.8.3-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.2-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.3-alpha" ``` Troubleshooting From 523babf3b91c75dcb62851bdda3964dd5361b5ba Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 3 Feb 2017 16:08:18 -0800 Subject: [PATCH 273/663] Update version to 0.8.4-*-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 0c5b2a5b15..000d0359d5 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.8.3-alpha + 0.8.4-alpha-SNAPSHOT google-cloud-core From c3dd019e2aaadf2730adee52cde52bf62daa9bed Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Tue, 7 Feb 2017 13:34:12 +1100 Subject: [PATCH 274/663] merge master into pubsub-hp (#1591) * Update version to 0.8.1-SNAPSHOT (#1467) Also, update versions in README to 0.8.0 * Add link to Maven Central for maven-central badge. (#1468) Used to link to the image, which wasn't super useful. * fix more races in pubsub tests Previously BlockingProcessStreamReader has a terminate() method, used to tell the Reader to stop reading from the emulator process. This causes an inter-process race. If the Reader stops before reading emulator's output, the emulator process will hang as it tries to write to stdout/stderr as there's no one to read from the other side of the pipe. Since there is no way to safely stop the Reader, this commit deletes the method and its associated test. Additionally, the timeout for LocalSystemTest is increased to 3 minutes, since the emulator, somehow, consistently takes just longer than a minute to shut down. * Regenerating SPI layer (#1501) * Converting Error Reporting and Monitoring to use resource name types * Removing formatX/parseX methods from pubsub, converting usage of the same to resource name types * New methods in Logging and PubSub * Updating grpc dependency to 1.0.3 (#1504) * Release 0.8.1 (#1512) * Fix code snippet (wrong method name) in README.md Original code snippet in _"Querying data"_ section: `..while (!queryResponse.jobComplete()) {..` This results in a compile error: _"Cannot resolve method jobComplete()"_ The correct method is `jobCompleted()` * Updating version in README files. [ci skip] * Update version to 0.8.2-alpha-SNAPSHOT * Allow path in URIs passed to newFileSystem (#1470) * This makes it easier for users who start with a URI describing a full path to get a FileSystem that can work with that path, since they no longer have to needlessly remove the path from the URI. Note that Oracle's description of newFileSystem [1] puts no restriction on the passed URI. [1] https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystems.html#newFileSystem(java.net.URI,%20java.util.Map) * Preventing logging re-entrance at FINE level (#1523) * Preventing logging re-entrance at FINE level Also: * Reducing the scope of synchronized blocks * Removing logger exclusions except for Http2FrameLogger * Add a PathMatcher for CloudStorageFileSystem (#1469) Add a test, as well. We reuse the default PathMatcher since it does a fine job of globbing files. * Set timestamp from LogRecord (#1533) * Initialize the default MonitoredResource from a GAE environment (#1535) * BigQuery: Add support to FormatOptions for AVRO https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1441 Added new constant in FormatOptions, and a corresponding factory method. Updated test cases. Confirmed that AVRO does not require special treatment (like CSV does), so no additional changes are required. * Reverting changed commited by mistake before review. * BigQuery: Add support to FormatOptions for AVRO https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1441 Added new constant in FormatOptions and a corresponding factory method. Updated test cases. Confirmed that AVRO does not require special treatment (like CSV does), so no additional changes are required. * use RpcFuture and remove old BundlingSettings (#1572) * use RpcFuture and remove old BundlingSettings * Release 0.8.2 Note: This version was accidentally released to Sonatype because of experimenting with deployment commands, combined with the fact that autoReleaseAfterClose is set to true. Since releases can't be taken back, we might as well own up to the release and push the code forward. * Updating version in README files. [ci skip] * Fixing javadoc error in GaeFlexLoggingEnhancer (#1582) * get tests to compile and pass --- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f711365e18..a82cc30ff4 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.8.0 + 0.8.2-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.8.0' +compile 'com.google.cloud:google-cloud-core:0.8.2-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.2-alpha" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d395b23313..7ad0a8ae40 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.8.1-SNAPSHOT + 0.8.2-alpha google-cloud-core @@ -111,7 +111,7 @@ com.google.api gax - 0.0.27 + 0.0.28 io.grpc @@ -122,7 +122,7 @@ com.google.api.grpc grpc-google-common-protos - 0.1.3 + 0.1.5 io.grpc @@ -133,7 +133,7 @@ com.google.api.grpc grpc-google-iam-v1 - 0.1.3 + 0.1.5 io.grpc From 3bf3698a54446e2273e934b52fb457f5c85bc141 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Wed, 8 Feb 2017 14:31:24 -0800 Subject: [PATCH 275/663] Javadocs: adding links to external types (#1600) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 000d0359d5..31b75fc9d6 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -111,7 +111,7 @@ com.google.api gax - 0.0.28 + ${gax.version} io.grpc From 87454b40eceb92ae015ad70ed3d3485c3d1a4249 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 10 Feb 2017 10:45:27 +1100 Subject: [PATCH 276/663] add zone to GAE Flex logging enhancer (#1589) --- .../src/main/java/com/google/cloud/ServiceOptions.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 755b81354e..bdb2d0d08d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -408,6 +408,8 @@ protected static String googleCloudProjectId() { try { URL url = new URL("http://metadata/computeMetadata/v1/project/project-id"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + // TODO replace X-Google-Metadata-Request with: + // connection.setRequestProperty("Metadata-Flavor", "Google"); connection.setRequestProperty("X-Google-Metadata-Request", "True"); InputStream input = connection.getInputStream(); if (connection.getResponseCode() == 200) { From 4506b2a042492491ac0ff64b47a4e49d44a33166 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Sat, 11 Feb 2017 21:13:51 -0800 Subject: [PATCH 277/663] Release 0.9.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 31b75fc9d6..223a1337dc 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.8.4-alpha-SNAPSHOT + 0.9.0-alpha google-cloud-core From d9b6636e8b314368828d51000b1cee63ae76536d Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Sat, 11 Feb 2017 21:16:57 -0800 Subject: [PATCH 278/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 4bafb86270..27431b2d5e 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.8.3-alpha + 0.9.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.8.3-alpha' +compile 'com.google.cloud:google-cloud-core:0.9.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.8.3-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.9.0-alpha" ``` Troubleshooting From e36210b96248bd6fa2e4674250f6b07b2564bebb Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Mon, 13 Feb 2017 09:15:25 -0800 Subject: [PATCH 279/663] Update version to 0.9.1-*-SNAPSHOT (#1615) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 223a1337dc..a77499fcbc 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.9.0-alpha + 0.9.1-alpha-SNAPSHOT google-cloud-core From bde513b7faa705008a0a3a6bee765c7773dc764f Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 14 Feb 2017 08:33:22 -0800 Subject: [PATCH 280/663] Release 0.9.1 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a77499fcbc..85a233c6f6 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.9.1-alpha-SNAPSHOT + 0.9.1-alpha google-cloud-core From 9cc475b204239ecdf0f9feea40141527800c26b0 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 14 Feb 2017 09:28:16 -0800 Subject: [PATCH 281/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 27431b2d5e..cc567115c7 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.9.0-alpha + 0.9.1-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.9.0-alpha' +compile 'com.google.cloud:google-cloud-core:0.9.1-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.9.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.9.1-alpha" ``` Troubleshooting From 98a385d99f3569760070542c0696ec17bb0b63c2 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 14 Feb 2017 10:09:44 -0800 Subject: [PATCH 282/663] Release 0.9.2 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 85a233c6f6..e0ab852706 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.9.1-alpha + 0.9.2-alpha google-cloud-core From 300fe641f4b8de796b4a9e60e009a6d82b5c9143 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 14 Feb 2017 10:13:00 -0800 Subject: [PATCH 283/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index cc567115c7..f58fcc4db4 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.9.1-alpha + 0.9.2-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.9.1-alpha' +compile 'com.google.cloud:google-cloud-core:0.9.2-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.9.1-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.9.2-alpha" ``` Troubleshooting From 937d775d16eeed6dec9168a5b5fb9aaab47f1ec8 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Tue, 14 Feb 2017 13:02:32 -0800 Subject: [PATCH 284/663] Update version to 0.9.3-*-SNAPSHOT (#1620) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e0ab852706..114ac01519 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.9.2-alpha + 0.9.3-alpha-SNAPSHOT google-cloud-core From 4c3505d5c5c35897ccc49bd7293d8a96535c18d8 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Tue, 21 Feb 2017 14:58:28 -0800 Subject: [PATCH 285/663] Update client name in header for Veneer layer (#1638) --- .../main/java/com/google/cloud/GrpcServiceOptions.java | 2 +- .../src/main/java/com/google/cloud/ServiceOptions.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java index c550724c6f..75c99c9506 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java @@ -313,7 +313,7 @@ protected ChannelProvider getChannelProvider() { InstantiatingChannelProvider.Builder builder = InstantiatingChannelProvider.newBuilder() .setServiceAddress(hostAndPort.getHostText()) .setPort(hostAndPort.getPort()) - .setClientLibHeader(getLibraryName(), firstNonNull(getLibraryVersion(), "")); + .setClientLibHeader(getGoogApiClientLibName(), firstNonNull(getLibraryVersion(), "")); Credentials scopedCredentials = getScopedCredentials(); if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { builder.setCredentialsProvider(FixedCredentialsProvider.create(scopedCredentials)); diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index bdb2d0d08d..5f668a6c4d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -74,6 +74,7 @@ public abstract class ServiceOptions, Service private static final String MANIFEST_VERSION_KEY = "Implementation-Version"; private static final String ARTIFACT_ID = "google-cloud-core"; private static final String LIBRARY_NAME = "gcloud-java"; + private static final String X_GOOGLE_CLIENT_HEADER_NAME = "gccl"; private static final String LIBRARY_VERSION = defaultLibraryVersion(); private static final String APPLICATION_NAME = LIBRARY_VERSION == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + LIBRARY_VERSION; @@ -601,6 +602,13 @@ public String getLibraryName() { return LIBRARY_NAME; } + /** + * Returns the library's name used by x-goog-api-client header as a string. + */ + public String getGoogApiClientLibName() { + return X_GOOGLE_CLIENT_HEADER_NAME; + } + /** * Returns the library's version as a string. */ From 02a55ccf417e79f4ba9b015df5e8069570611b1a Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Wed, 22 Feb 2017 15:02:16 -0800 Subject: [PATCH 286/663] Release 0.9.3 (#1642) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 114ac01519..02380b1d54 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.9.3-alpha-SNAPSHOT + 0.9.3-alpha google-cloud-core From f18c95949aefae2b8cd1fec62ab8da2c21ac6da9 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 22 Feb 2017 11:11:26 -0800 Subject: [PATCH 287/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f58fcc4db4..c3200a0a75 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.9.2-alpha + 0.9.3-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.9.2-alpha' +compile 'com.google.cloud:google-cloud-core:0.9.3-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.9.2-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.9.3-alpha" ``` Troubleshooting From 521e2113395f9339498e860603075b55d532a25e Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 22 Feb 2017 15:11:18 -0800 Subject: [PATCH 288/663] Update version to 0.9.4-*-SNAPSHOT --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 02380b1d54..672b1565a5 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.9.3-alpha + 0.9.4-alpha-SNAPSHOT google-cloud-core From 98145ae4fe7ee282499ef1b4c76e984e5ca1a7d8 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 23 Feb 2017 03:17:57 +0100 Subject: [PATCH 289/663] Expose static method to get default project ID (#1380) --- .../com/google/cloud/HttpServiceOptions.java | 2 +- .../java/com/google/cloud/ServiceOptions.java | 54 ++++++++++++------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java index d816ed1a7b..870e50d358 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java @@ -58,7 +58,7 @@ public static class DefaultHttpTransportFactory implements HttpTransportFactory @Override public HttpTransport create() { // Consider App Engine - if (appEngineAppId() != null) { + if (getAppEngineAppId() != null) { try { return new UrlFetchTransport(); } catch (Exception ignore) { diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 5f668a6c4d..cdf6e0b765 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -176,7 +176,8 @@ public B setClock(Clock clock) { } /** - * Sets project id. + * Sets the project ID. If no project ID is set, {@link #getDefaultProjectId()} will be used to + * attempt getting the project ID from the environment. * * @return the builder */ @@ -186,7 +187,8 @@ public B projectId(String projectId) { } /** - * Sets project id. + * Sets the project ID. If no project ID is set, {@link #getDefaultProjectId()} will be used to + * attempt getting the project ID from the environment. * * @return the builder */ @@ -316,10 +318,6 @@ private static GoogleCredentials defaultCredentials() { } } - protected static String appEngineAppId() { - return System.getProperty("com.google.appengine.application.id"); - } - @Deprecated protected String defaultHost() { return getDefaultHost(); @@ -335,21 +333,41 @@ protected String defaultProject() { } protected String getDefaultProject() { + return getDefaultProjectId(); + } + + /** + * Returns the default project ID, or {@code null} if no default project ID could be found. This + * method returns the first available project ID among the following sources: + *

      + *
    1. The project ID specified by the GOOGLE_CLOUD_PROJECT environment variable + *
    2. The App Engine project ID + *
    3. The project ID specified in the JSON credentials file pointed by the + * {@code GOOGLE_APPLICATION_CREDENTIALS} environment variable + *
    4. The Google Cloud SDK project ID + *
    5. The Compute Engine project ID + *
    + */ + public static String getDefaultProjectId() { String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); if (projectId == null) { projectId = System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); } if (projectId == null) { - projectId = appEngineProjectId(); + projectId = getAppEngineProjectId(); } if (projectId == null) { - projectId = serviceAccountProjectId(); + projectId = getServiceAccountProjectId(); } - return projectId != null ? projectId : googleCloudProjectId(); + return projectId != null ? projectId : getGoogleCloudProjectId(); + } + + protected static String getAppEngineAppId() { + return System.getProperty("com.google.appengine.application.id"); } - private static String activeGoogleCloudConfig(File configDir) { + private static String getActiveGoogleCloudConfig(File configDir) { String activeGoogleCloudConfig = null; try { activeGoogleCloudConfig = @@ -361,7 +379,7 @@ private static String activeGoogleCloudConfig(File configDir) { return firstNonNull(activeGoogleCloudConfig, "default"); } - protected static String googleCloudProjectId() { + protected static String getGoogleCloudProjectId() { File configDir; if (System.getenv().containsKey("CLOUDSDK_CONFIG")) { configDir = new File(System.getenv("CLOUDSDK_CONFIG")); @@ -370,7 +388,7 @@ protected static String googleCloudProjectId() { } else { configDir = new File(System.getProperty("user.home"), ".config/gcloud"); } - String activeConfig = activeGoogleCloudConfig(configDir); + String activeConfig = getActiveGoogleCloudConfig(configDir); FileReader fileReader = null; try { fileReader = new FileReader(new File(configDir, "configurations/config_" + activeConfig)); @@ -429,7 +447,7 @@ private static boolean isWindows() { return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"); } - protected static String appEngineProjectId() { + protected static String getAppEngineProjectId() { try { Class factoryClass = Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory"); @@ -447,7 +465,7 @@ protected static String appEngineProjectId() { } } - protected static String serviceAccountProjectId() { + protected static String getServiceAccountProjectId() { String project = null; String credentialsPath = System.getenv("GOOGLE_APPLICATION_CREDENTIALS"); if (credentialsPath != null) { @@ -488,8 +506,8 @@ public ServiceRpcT getRpc() { } /** - * Returns the project id. Return value can be null (for services that don't require a project - * id). + * Returns the project ID. Return value can be null (for services that don't require a project + * ID). */ @Deprecated public String projectId() { @@ -497,8 +515,8 @@ public String projectId() { } /** - * Returns the project id. Return value can be null (for services that don't require a project - * id). + * Returns the project ID. Return value can be null (for services that don't require a project + * ID). */ public String getProjectId() { return projectId; From d1644075bc6a76ab28a21c80a97574bbec19e0a0 Mon Sep 17 00:00:00 2001 From: Reynald Borer Date: Tue, 28 Feb 2017 21:18:44 +0100 Subject: [PATCH 290/663] Make class com.google.cloud.ServiceOptions$Builder public (#1672) --- .../src/main/java/com/google/cloud/ServiceOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index cdf6e0b765..9122aa525b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -104,7 +104,7 @@ public abstract class ServiceOptions, Service * @param the {@code ServiceOptions} subclass corresponding to the service * @param the {@code ServiceOptions} builder */ - protected abstract static class Builder, ServiceRpcT, + public abstract static class Builder, ServiceRpcT, OptionsT extends ServiceOptions, B extends Builder> { From 1097fc8f935d51f089e64d8af37349ba727015ef Mon Sep 17 00:00:00 2001 From: neozwu Date: Thu, 2 Mar 2017 19:03:56 -0800 Subject: [PATCH 291/663] fix retry logic on HttpResponseException (#1677) * fix retry logic on HttpResponseException (#1545) --- .../google/cloud/BaseServiceException.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index d892d85b6b..00e58a5ce6 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -18,6 +18,7 @@ import com.google.api.client.googleapis.json.GoogleJsonError; import com.google.api.client.googleapis.json.GoogleJsonResponseException; +import com.google.api.client.http.HttpResponseException; import com.google.api.gax.grpc.ApiException; import com.google.common.base.MoreObjects; @@ -140,20 +141,27 @@ public BaseServiceException(IOException exception, boolean idempotent) { String location = null; String debugInfo = null; Boolean retryable = null; - if (exception instanceof GoogleJsonResponseException) { - GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails(); - if (jsonError != null) { - Error error = new Error(jsonError.getCode(), reason(jsonError)); - code = error.code; - reason = error.reason; - retryable = isRetryable(idempotent, error); - if (reason != null) { - GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0); - location = errorInfo.getLocation(); - debugInfo = (String) errorInfo.get("debugInfo"); + if (exception instanceof HttpResponseException) { + if (exception instanceof GoogleJsonResponseException) { + GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails(); + if (jsonError != null) { + Error error = new Error(jsonError.getCode(), reason(jsonError)); + code = error.code; + reason = error.reason; + retryable = isRetryable(idempotent, error); + if (reason != null) { + GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0); + location = errorInfo.getLocation(); + debugInfo = (String) errorInfo.get("debugInfo"); + } + } else { + code = ((GoogleJsonResponseException) exception).getStatusCode(); } } else { - code = ((GoogleJsonResponseException) exception).getStatusCode(); + // In cases where an exception is an instance of HttpResponseException but not + // an instance of GoogleJsonResponseException, check the status code to determine whether it's retryable + code = ((HttpResponseException) exception).getStatusCode(); + retryable = isRetryable(idempotent, new Error(code, null)); } } this.retryable = MoreObjects.firstNonNull(retryable, isRetryable(idempotent, exception)); From 7fc6764ec68eb713940697a138ae0dca4c8e2a33 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Mon, 6 Mar 2017 11:34:18 -0800 Subject: [PATCH 292/663] Release 0.9.4 (#1703) --- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index c3200a0a75..6612e5c8ed 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.9.3-alpha + 0.9.4-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.9.3-alpha' +compile 'com.google.cloud:google-cloud-core:0.9.4-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.9.3-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.9.4-alpha" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 672b1565a5..ac892e59e2 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.9.4-alpha-SNAPSHOT + 0.9.4-alpha google-cloud-core From a6e1d3e7d092040febbf54adaf7e9b616f383b11 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Mon, 6 Mar 2017 13:43:06 -0800 Subject: [PATCH 293/663] Update version to 0.9.5-*-SNAPSHOT (#1704) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index ac892e59e2..0bc251fee7 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.9.4-alpha + 0.9.5-alpha-SNAPSHOT google-cloud-core From 6e5c7412a678c2a8636df21bca6c1460f4ef14a9 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Tue, 7 Mar 2017 10:57:48 -0800 Subject: [PATCH 294/663] Remove deprecated methods and corresponding tests (#1678) Remove deprecated methods and its references in one pass by a self-made script, with a few exceptions: - There are still plenty of manual work involved to update usages of deprecated methods and fields - Manual corrections due to misspell of the word "deprecated" - google-cloud-pubsub: Pubsub has a few deprecated packages and it affects its integrated tests as well. Removing deprecated packages is not in the scope of this PR. - google-cloud-compute: Compute engine has a few "Deprecated" related service which causes lots of noise of the automated script. - google-cloud-datastore - In `ValueBuilder` `getExcludeFromIndexes` was marked as deprecated which is inconsistent with other getter/setter methods - Preserved the fields `meaning` in `ValueBuilder` since it is still wide used in the code. May require a separate PR to deprecate. --- .../main/java/com/google/cloud/AsyncPage.java | 6 - .../java/com/google/cloud/AsyncPageImpl.java | 12 -- .../java/com/google/cloud/BaseService.java | 5 - .../google/cloud/BaseServiceException.java | 67 --------- .../com/google/cloud/BaseWriteChannel.java | 57 -------- .../main/java/com/google/cloud/ByteArray.java | 4 - .../com/google/cloud/ExceptionHandler.java | 29 ---- .../java/com/google/cloud/FieldSelector.java | 6 - .../com/google/cloud/HttpServiceOptions.java | 54 -------- .../main/java/com/google/cloud/Identity.java | 18 --- .../com/google/cloud/MonitoredResource.java | 51 +------ .../cloud/MonitoredResourceDescriptor.java | 64 --------- .../src/main/java/com/google/cloud/Page.java | 15 -- .../main/java/com/google/cloud/PageImpl.java | 17 --- .../main/java/com/google/cloud/Policy.java | 70 ---------- .../java/com/google/cloud/ReadChannel.java | 6 - .../java/com/google/cloud/RetryParams.java | 118 ---------------- .../src/main/java/com/google/cloud/Role.java | 8 -- .../main/java/com/google/cloud/Service.java | 2 - .../java/com/google/cloud/ServiceOptions.java | 130 ------------------ .../java/com/google/cloud/WaitForOption.java | 21 --- .../java/com/google/cloud/WriteChannel.java | 6 - .../com/google/cloud/AsyncPageImplTest.java | 23 ---- .../cloud/BaseServiceExceptionTest.java | 88 ------------ .../google/cloud/BaseWriteChannelTest.java | 11 -- .../google/cloud/FieldSelectorHelperTest.java | 15 -- .../google/cloud/GrpcServiceOptionsTest.java | 22 --- .../google/cloud/HttpServiceOptionsTest.java | 20 --- .../java/com/google/cloud/IdentityTest.java | 30 ---- .../MonitoredResourceDescriptorTest.java | 30 ---- .../google/cloud/MonitoredResourceTest.java | 24 ---- .../java/com/google/cloud/PageImplTest.java | 14 -- .../java/com/google/cloud/PolicyTest.java | 46 ------- .../com/google/cloud/RetryHelperTest.java | 97 ------------- .../com/google/cloud/RetryParamsTest.java | 33 ----- .../test/java/com/google/cloud/RoleTest.java | 9 -- .../com/google/cloud/ServiceOptionsTest.java | 22 --- .../com/google/cloud/WaitForOptionTest.java | 13 -- 38 files changed, 4 insertions(+), 1259 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java index ab836e6e4b..13fa7a6cb9 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java @@ -44,12 +44,6 @@ */ public interface AsyncPage extends Page { - /** - * Returns a {@link Future} object for the next page. {@link Future#get()} returns {@code null} if - * the last page has been reached. - */ - @Deprecated - Future> nextPageAsync(); /** * Returns a {@link Future} object for the next page. {@link Future#get()} returns {@code null} if diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index c5734408d4..bc4858ecb7 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -41,8 +41,6 @@ public class AsyncPageImpl extends PageImpl implements AsyncPage { * @param the value type that the page holds */ public interface NextPageFetcher extends Serializable { - @Deprecated - Future> nextPage(); Future> getNextPage(); } @@ -57,11 +55,6 @@ private SyncNextPageFetcher(NextPageFetcher asyncPageFetcher) { this.asyncPageFetcher = asyncPageFetcher; } - @Override - public Page nextPage() { - return getNextPage(); - } - @Override public Page getNextPage() { try { @@ -81,11 +74,6 @@ public AsyncPageImpl(NextPageFetcher asyncPageFetcher, String cursor, Iterabl this.asyncPageFetcher = asyncPageFetcher; } - @Override - @Deprecated - public Future> nextPageAsync() { - return getNextPageAsync(); - } @Override public Future> getNextPageAsync() { diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java index f221ade324..dcfb097a07 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java @@ -55,11 +55,6 @@ protected BaseService(OptionsT options) { this.options = options; } - @Override - @Deprecated - public OptionsT options() { - return options; - } @Override public OptionsT getOptions() { diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index 00e58a5ce6..cb834f8d36 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -63,13 +63,6 @@ public Error(Integer code, String reason, boolean rejected) { this.rejected = rejected; } - /** - * Returns the code associated with this exception. - */ - @Deprecated - public Integer code() { - return getCode(); - } /** * Returns the code associated with this exception. @@ -78,15 +71,6 @@ public Integer getCode() { return code; } - /** - * Returns true if the error indicates that the API call was certainly not accepted by the - * server. For instance, if the server returns a rate limit exceeded error, it certainly did not - * process the request and this method will return {@code true}. - */ - @Deprecated - public boolean rejected() { - return isRejected(); - } /** * Returns true if the error indicates that the API call was certainly not accepted by the @@ -97,13 +81,6 @@ public boolean isRejected() { return rejected; } - /** - * Returns the reason that caused the exception. - */ - @Deprecated - public String reason() { - return getReason(); - } /** * Returns the reason that caused the exception. @@ -214,10 +191,6 @@ public BaseServiceException(ApiException apiException, boolean idempotent) { this.debugInfo = null; } - @Deprecated - protected Set retryableErrors() { - return getRetryableErrors(); - } protected Set getRetryableErrors() { return Collections.emptySet(); @@ -234,13 +207,6 @@ protected boolean isRetryable(boolean idempotent, IOException exception) { return idempotent && exceptionIsRetryable; } - /** - * Returns the code associated with this exception. - */ - @Deprecated - public int code() { - return getCode(); - } /** * Returns the code associated with this exception. @@ -249,13 +215,6 @@ public int getCode() { return code; } - /** - * Returns the reason that caused the exception. - */ - @Deprecated - public String reason() { - return getReason(); - } /** * Returns the reason that caused the exception. @@ -264,13 +223,6 @@ public String getReason() { return reason; } - /** - * Returns {@code true} when it is safe to retry the operation that caused this exception. - */ - @Deprecated - public boolean retryable() { - return isRetryable(); - } /** * Returns {@code true} when it is safe to retry the operation that caused this exception. @@ -279,13 +231,6 @@ public boolean isRetryable() { return retryable; } - /** - * Returns {@code true} when the operation that caused this exception had no side effects. - */ - @Deprecated - public boolean idempotent() { - return isIdempotent(); - } /** * Returns {@code true} when the operation that caused this exception had no side effects. @@ -294,14 +239,6 @@ public boolean isIdempotent() { return idempotent; } - /** - * Returns the service location where the error causing the exception occurred. Returns {@code - * null} if not available. - */ - @Deprecated - public String location() { - return getLocation(); - } /** * Returns the service location where the error causing the exception occurred. Returns {@code @@ -311,10 +248,6 @@ public String getLocation() { return location; } - @Deprecated - protected String debugInfo() { - return getDebugInfo(); - } protected String getDebugInfo() { return debugInfo; diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index f7a67deece..86105d469d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -47,19 +47,11 @@ public abstract class BaseWriteChannel< private boolean isOpen = true; private int chunkSize = getDefaultChunkSize(); - @Deprecated - protected int minChunkSize() { - return getMinChunkSize(); - } protected int getMinChunkSize() { return MIN_CHUNK_SIZE; } - @Deprecated - protected int defaultChunkSize() { - return getDefaultChunkSize(); - } protected int getDefaultChunkSize() { return DEFAULT_CHUNK_SIZE; @@ -73,74 +65,41 @@ protected int getDefaultChunkSize() { */ protected abstract void flushBuffer(int length, boolean last); - @Deprecated - protected ServiceOptionsT options() { - return options; - } protected ServiceOptionsT getOptions() { return options; } - @Deprecated - protected EntityT entity() { - return getEntity(); - } protected EntityT getEntity() { return entity; } - @Deprecated - protected String uploadId() { - return getUploadId(); - } protected String getUploadId() { return uploadId; } - @Deprecated - protected long position() { - return getPosition(); - } protected long getPosition() { return position; } - @Deprecated - protected byte[] buffer() { - return getBuffer(); - } protected byte[] getBuffer() { return buffer; } - @Deprecated - protected long limit() { - return getLimit(); - } protected int getLimit() { return limit; } - @Deprecated - protected int chunkSize() { - return getChunkSize(); - } protected int getChunkSize() { return chunkSize; } - @Override - @Deprecated - public final void chunkSize(int chunkSize) { - setChunkSize(chunkSize); - } @Override public final void setChunkSize(int chunkSize) { @@ -285,40 +244,24 @@ protected Builder(ServiceOptionsT options, EntityT entity, String uploadId) { this.uploadId = uploadId; } - @Deprecated - public Builder position(int position) { - return setPosition(position); - } public Builder setPosition(long position) { this.position = position; return this; } - @Deprecated - public Builder buffer(byte[] buffer) { - return setBuffer(buffer); - } public Builder setBuffer(byte[] buffer) { this.buffer = buffer; return this; } - @Deprecated - public Builder isOpen(boolean isOpen) { - return setIsOpen(isOpen); - } public Builder setIsOpen(boolean isOpen) { this.isOpen = isOpen; return this; } - @Deprecated - public Builder chunkSize(int chunkSize) { - return setChunkSize(chunkSize); - } public Builder setChunkSize(int chunkSize) { this.chunkSize = chunkSize; diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java index 0c719fb18d..b92b0bac29 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -108,10 +108,6 @@ public final InputStream asInputStream() { return byteString.newInput(); } - @Deprecated - protected ByteString byteString() { - return getByteString(); - } protected ByteString getByteString() { return byteString; diff --git a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java index 91534885a1..a2a69a7376 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java @@ -87,16 +87,6 @@ public static class Builder { private Builder() {} - /** - * Adds the exception handler interceptors. Call order will be maintained. - * - * @param interceptors the interceptors for this exception handler - * @return the Builder for chaining - */ - @Deprecated - public Builder interceptor(Interceptor... interceptors) { - return addInterceptors(interceptors); - } /** * Adds the exception handler interceptors. Call order will be maintained. @@ -243,19 +233,11 @@ void verifyCaller(Callable callable) { } } - @Deprecated - public Set> retriableExceptions() { - return getRetriableExceptions(); - } public Set> getRetriableExceptions() { return retriableExceptions; } - @Deprecated - public Set> nonRetriableExceptions() { - return nonRetriableExceptions; - } public Set> getNonRetriableExceptions() { return nonRetriableExceptions; @@ -301,13 +283,6 @@ public boolean equals(Object obj) { && Objects.equals(retryInfo, other.retryInfo); } - /** - * Returns an instance which retry any checked exception and abort on any runtime exception. - */ - @Deprecated - public static ExceptionHandler defaultInstance() { - return getDefaultInstance(); - } /** * Returns an instance which retry any checked exception and abort on any runtime exception. @@ -316,10 +291,6 @@ public static ExceptionHandler getDefaultInstance() { return DEFAULT_INSTANCE; } - @Deprecated - public static Builder builder() { - return newBuilder(); - } public static Builder newBuilder() { return new Builder(); diff --git a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java index 37190a3c2e..125a03e212 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java +++ b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java @@ -31,12 +31,6 @@ */ public interface FieldSelector { - /** - * Returns a string selector. This selector is passed to a Google Cloud service (possibly with - * other field selectors) to specify which resource fields should be returned by an API call. - */ - @Deprecated - String selector(); /** * Returns a string selector. This selector is passed to a Google Cloud service (possibly with diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java index 870e50d358..1613b68acb 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java @@ -103,15 +103,6 @@ protected B self() { return (B) this; } - /** - * Sets the HTTP transport factory. - * - * @return the builder - */ - @Deprecated - public B httpTransportFactory(HttpTransportFactory httpTransportFactory) { - return setHttpTransportFactory(httpTransportFactory); - } /** * Sets the HTTP transport factory. @@ -123,17 +114,6 @@ public B setHttpTransportFactory(HttpTransportFactory httpTransportFactory) { return self(); } - /** - * Sets the timeout in milliseconds to establish a connection. - * - * @param connectTimeout connection timeout in milliseconds. 0 for an infinite timeout, a - * negative number for the default value (20000). - * @return the builder - */ - @Deprecated - public B connectTimeout(int connectTimeout) { - return setConnectTimeout(connectTimeout); - } /** * Sets the timeout in milliseconds to establish a connection. @@ -147,17 +127,6 @@ public B setConnectTimeout(int connectTimeout) { return self(); } - /** - * Sets the timeout in milliseconds to read data from an established connection. - * - * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a negative number - * for the default value (20000). - * @return the builder - */ - @Deprecated - public B readTimeout(int readTimeout) { - return setReadTimeout(readTimeout); - } /** * Sets the timeout in milliseconds to read data from an established connection. @@ -184,13 +153,6 @@ protected HttpServiceOptions( readTimeout = builder.readTimeout; } - /** - * Returns the HTTP transport factory. - */ - @Deprecated - public HttpTransportFactory httpTransportFactory() { - return getHttpTransportFactory(); - } /** * Returns the HTTP transport factory. @@ -199,14 +161,6 @@ public HttpTransportFactory getHttpTransportFactory() { return httpTransportFactory; } - /** - * Returns a request initializer responsible for initializing requests according to service - * options. - */ - @Deprecated - public HttpRequestInitializer httpRequestInitializer() { - return getHttpRequestInitializer(); - } /** * Returns a request initializer responsible for initializing requests according to service @@ -249,14 +203,6 @@ public int getConnectTimeout() { return connectTimeout; } - /** - * Returns the timeout in milliseconds to read from an established connection. 0 is an infinite - * timeout, a negative number is the default value (20000). - */ - @Deprecated - public int readTimeout() { - return getReadTimeout(); - } /** * Returns the timeout in milliseconds to read from an established connection. 0 is an infinite diff --git a/google-cloud-core/src/main/java/com/google/cloud/Identity.java b/google-cloud-core/src/main/java/com/google/cloud/Identity.java index c82005a38d..cbf2c6292d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Identity.java @@ -86,29 +86,11 @@ private Identity(Type type, String value) { this.value = value; } - @Deprecated - public Type type() { - return getType(); - } public Type getType() { return type; } - /** - * Returns the string identifier for this identity. The value corresponds to: - *
      - *
    • email address (for identities of type {@code USER}, {@code SERVICE_ACCOUNT}, and - * {@code GROUP}) - *
    • domain (for identities of type {@code DOMAIN}) - *
    • {@code null} (for identities of type {@code ALL_USERS} and - * {@code ALL_AUTHENTICATED_USERS}) - *
    - */ - @Deprecated - public String value() { - return getValue(); - } /** * Returns the string identifier for this identity. The value corresponds to: diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java index 66cd15ce1e..052a773560 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java @@ -61,19 +61,10 @@ public static class Builder { this.labels = new HashMap<>(monitoredResource.labels); } - /** - * Sets the monitored resource type. This value must match the one of - * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. - * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. - */ - @Deprecated - public Builder type(String type) { - return setType(type); - } /** * Sets the monitored resource type. This value must match the one of - * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. + * {@link MonitoredResourceDescriptor#getType()} of a {@code MonitoredResourceDescriptor} object. * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. */ public Builder setType(String type) { @@ -81,19 +72,10 @@ public Builder setType(String type) { return this; } - /** - * Sets the values for all the labels required by the corresponding monitored resource - * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute - * Engine VM instances use the labels {@code instance_id} and {@code zone}. - */ - @Deprecated - public Builder labels(Map labels) { - return setLabels(labels); - } /** * Sets the values for all the labels required by the corresponding monitored resource - * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute + * descriptor (see {@link MonitoredResourceDescriptor#getLabels()}. For example, Google Compute * Engine VM instances use the labels {@code instance_id} and {@code zone}. */ public Builder setLabels(Map labels) { @@ -127,38 +109,20 @@ public MonitoredResource build() { this.labels = ImmutableMap.copyOf(builder.labels); } - /** - * Returns the monitored resource type. This value must match the one of - * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. - * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. - */ - @Deprecated - public String type() { - return getType(); - } /** * Returns the monitored resource type. This value must match the one of - * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. + * {@link MonitoredResourceDescriptor#getType()} of a {@code MonitoredResourceDescriptor} object. * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. */ public String getType() { return type; } - /** - * Returns the values for all the labels required by the corresponding monitored resource - * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute - * Engine VM instances use the labels {@code instance_id} and {@code zone}. - */ - @Deprecated - public Map labels() { - return getLabels(); - } /** * Returns the values for all the labels required by the corresponding monitored resource - * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute + * descriptor (see {@link MonitoredResourceDescriptor#getLabels()}. For example, Google Compute * Engine VM instances use the labels {@code instance_id} and {@code zone}. */ public Map getLabels() { @@ -204,13 +168,6 @@ public Builder toBuilder() { return new Builder(this); } - /** - * Returns a builder for {@code MonitoredResource} objects given the resource's type. - */ - @Deprecated - public static Builder builder(String type) { - return newBuilder(type); - } /** * Returns a builder for {@code MonitoredResource} objects given the resource's type. diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java index ebee6544df..d4529124c8 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java @@ -117,13 +117,6 @@ static ValueType fromPb(com.google.api.LabelDescriptor.ValueType typePb) { this.description = description; } - /** - * Returns the key associated to this label. - */ - @Deprecated - public String key() { - return getKey(); - } /** * Returns the key associated to this label. @@ -132,13 +125,6 @@ public String getKey() { return key; } - /** - * Returns the type of data that can be assigned to this label. - */ - @Deprecated - public ValueType valueType() { - return getValueType(); - } /** * Returns the type of data that can be assigned to this label. @@ -147,14 +133,6 @@ public ValueType getValueType() { return valueType; } - /** - * Returns the optional human-readable description for this label. If not set, this method - * returns {@code null}. - */ - @Deprecated - public String description() { - return getDescription(); - } /** * Returns the optional human-readable description for this label. If not set, this method @@ -257,14 +235,6 @@ MonitoredResourceDescriptor build() { this.labels = checkNotNull(builder.labels); } - /** - * Returns the monitored resource type. For example, the type {@code cloudsql_database} represents - * databases in Google Cloud SQL. - */ - @Deprecated - public String type() { - return getType(); - } /** * Returns the monitored resource type. For example, the type {@code cloudsql_database} represents @@ -274,14 +244,6 @@ public String getType() { return type; } - /** - * Returns an optional name for the monitored resource descriptor. If not set, this method returns - * {@code null}. - */ - @Deprecated - public String name() { - return getName(); - } /** * Returns an optional name for the monitored resource descriptor. If not set, this method returns @@ -291,15 +253,6 @@ public String getName() { return name; } - /** - * Returns an optional concise name for the monitored resource type. This value might be displayed - * in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method - * returns {@code null}. - */ - @Deprecated - public String displayName() { - return getDisplayName(); - } /** * Returns an optional concise name for the monitored resource type. This value might be displayed @@ -310,14 +263,6 @@ public String getDisplayName() { return displayName; } - /** - * Returns an optional detailed description of the monitored resource type. This value might be - * used in documentation. If not set, this method returns {@code null}. - */ - @Deprecated - public String description() { - return getDescription(); - } /** * Returns an optional detailed description of the monitored resource type. This value might be @@ -327,15 +272,6 @@ public String getDescription() { return description; } - /** - * Returns a list of labels used to describe instances of this monitored resource type. For - * example, an individual Google Cloud SQL database is identified by values for the labels - * {@code database_id} and {@code region}. - */ - @Deprecated - public List labels() { - return getLabels(); - } /** * Returns a list of labels used to describe instances of this monitored resource type. For diff --git a/google-cloud-core/src/main/java/com/google/cloud/Page.java b/google-cloud-core/src/main/java/com/google/cloud/Page.java index dde285e3aa..03cbe566d4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Page.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Page.java @@ -44,11 +44,6 @@ */ public interface Page { - /** - * Returns the values contained in this page. - */ - @Deprecated - Iterable values(); /** * Returns the values contained in this page. @@ -61,22 +56,12 @@ public interface Page { */ Iterator iterateAll(); - /** - * Returns the cursor for the nextPage or {@code null} if no more results. - */ - @Deprecated - String nextPageCursor(); /** * Returns the cursor for the nextPage or {@code null} if no more results. */ String getNextPageCursor(); - /** - * Returns the next page of results or {@code null} if no more result. - */ - @Deprecated - Page nextPage(); /** * Returns the next page of results or {@code null} if no more result. diff --git a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java index 99c675dea3..37b7fd9dee 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java @@ -44,8 +44,6 @@ public class PageImpl implements Page, Serializable { * @param the value type that the page holds */ public interface NextPageFetcher extends Serializable { - @Deprecated - Page nextPage(); Page getNextPage(); } @@ -83,11 +81,6 @@ public PageImpl(NextPageFetcher pageFetcher, String cursor, Iterable resul this.results = results; } - @Override - @Deprecated - public Iterable values() { - return getValues(); - } @Override public Iterable getValues() { @@ -99,22 +92,12 @@ public Iterator iterateAll() { return new PageIterator<>(this); } - @Override - @Deprecated - public String nextPageCursor() { - return getNextPageCursor(); - } @Override public String getNextPageCursor() { return cursor; } - @Override - @Deprecated - public Page nextPage() { - return getNextPage(); - } @Override public Page getNextPage() { diff --git a/google-cloud-core/src/main/java/com/google/cloud/Policy.java b/google-cloud-core/src/main/java/com/google/cloud/Policy.java index 4307f1dffd..c8fc044086 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Policy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Policy.java @@ -132,16 +132,6 @@ protected Builder(Policy policy) { setVersion(policy.version); } - /** - * Replaces the builder's map of bindings with the given map of bindings. - * - * @throws NullPointerException if the given map is null or contains any null keys or values - * @throws IllegalArgumentException if any identities in the given map are null - */ - @Deprecated - public final Builder bindings(Map> bindings) { - return setBindings(bindings); - } /** * Replaces the builder's map of bindings with the given map of bindings. @@ -212,21 +202,6 @@ public final Builder removeIdentity(Role role, Identity first, Identity... other return this; } - /** - * Sets the policy's etag. - * - *

    Etags are used for optimistic concurrency control as a way to help prevent simultaneous - * updates of a policy from overwriting each other. It is strongly suggested that systems make - * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid - * race conditions. An etag is returned in the response to getIamPolicy, and systems are - * expected to put that etag in the request to setIamPolicy to ensure that their change will be - * applied to the same version of the policy. If no etag is provided in the call to - * setIamPolicy, then the existing policy is overwritten blindly. - */ - @Deprecated - protected final Builder etag(String etag) { - return setEtag(etag); - } /** * Sets the policy's etag. @@ -244,14 +219,6 @@ protected final Builder setEtag(String etag) { return this; } - /** - * Sets the version of the policy. The default version is 0, meaning only the "owner", "editor", - * and "viewer" roles are permitted. If the version is 1, you may also use other roles. - */ - @Deprecated - protected final Builder version(int version) { - return setVersion(version); - } /** * Sets the version of the policy. The default version is 0, meaning only the "owner", "editor", @@ -287,13 +254,6 @@ public Builder toBuilder() { return new Builder(this); } - /** - * Returns the map of bindings that comprises the policy. - */ - @Deprecated - public Map> bindings() { - return getBindings(); - } /** * Returns the map of bindings that comprises the policy. @@ -302,21 +262,6 @@ public Map> getBindings() { return bindings; } - /** - * Returns the policy's etag. - * - *

    Etags are used for optimistic concurrency control as a way to help prevent simultaneous - * updates of a policy from overwriting each other. It is strongly suggested that systems make - * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid - * race conditions. An etag is returned in the response to getIamPolicy, and systems are - * expected to put that etag in the request to setIamPolicy to ensure that their change will be - * applied to the same version of the policy. If no etag is provided in the call to - * setIamPolicy, then the existing policy is overwritten blindly. - */ - @Deprecated - public String etag() { - return getEtag(); - } /** * Returns the policy's etag. @@ -333,14 +278,6 @@ public String getEtag() { return etag; } - /** - * Returns the version of the policy. The default version is 0, meaning only the "owner", - * "editor", and "viewer" roles are permitted. If the version is 1, you may also use other roles. - */ - @Deprecated - public int version() { - return getVersion(); - } /** * Returns the version of the policy. The default version is 0, meaning only the "owner", @@ -378,13 +315,6 @@ public boolean equals(Object obj) { && Objects.equals(version, other.getVersion()); } - /** - * Returns a builder for {@code Policy} objects. - */ - @Deprecated - public static Builder builder() { - return newBuilder(); - } /** * Returns a builder for {@code Policy} objects. diff --git a/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java index a097526928..aa04baaab1 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java @@ -40,12 +40,6 @@ public interface ReadChannel extends ReadableByteChannel, Closeable, Restorable< void seek(long position) throws IOException; - /** - * Sets the minimum size that will be read by a single RPC. - * Read data will be locally buffered until consumed. - */ - @Deprecated - void chunkSize(int chunkSize); /** * Sets the minimum size that will be read by a single RPC. diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java b/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java index e835ad5d3c..f737032cfe 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java @@ -107,16 +107,6 @@ private Builder() { } } - /** - * Sets retryMinAttempts. - * - * @param retryMinAttempts the retryMinAttempts to set - * @return the Builder for chaining - */ - @Deprecated - public Builder retryMinAttempts(int retryMinAttempts) { - return setRetryMinAttempts(retryMinAttempts); - } /** * Sets retryMinAttempts. @@ -129,16 +119,6 @@ public Builder setRetryMinAttempts(int retryMinAttempts) { return this; } - /** - * Sets retryMaxAttempts. - * - * @param retryMaxAttempts the retryMaxAttempts to set - * @return the Builder for chaining - */ - @Deprecated - public Builder retryMaxAttempts(int retryMaxAttempts) { - return setRetryMaxAttempts(retryMaxAttempts); - } /** * Sets retryMaxAttempts. @@ -151,16 +131,6 @@ public Builder setRetryMaxAttempts(int retryMaxAttempts) { return this; } - /** - * Sets initialRetryDelayMillis. - * - * @param initialRetryDelayMillis the initialRetryDelayMillis to set - * @return the Builder for chaining - */ - @Deprecated - public Builder initialRetryDelayMillis(long initialRetryDelayMillis) { - return setInitialRetryDelayMillis(initialRetryDelayMillis); - } /** * Sets initialRetryDelayMillis. @@ -173,16 +143,6 @@ public Builder setInitialRetryDelayMillis(long initialRetryDelayMillis) { return this; } - /** - * Sets maxRetryDelayMillis. - * - * @param maxRetryDelayMillis the maxRetryDelayMillis to set - * @return the Builder for chaining - */ - @Deprecated - public Builder maxRetryDelayMillis(long maxRetryDelayMillis) { - return setMaxRetryDelayMillis(maxRetryDelayMillis); - } /** * Sets maxRetryDelayMillis. @@ -195,16 +155,6 @@ public Builder setMaxRetryDelayMillis(long maxRetryDelayMillis) { return this; } - /** - * Sets retryDelayBackoffFactor. - * - * @param retryDelayBackoffFactor the retryDelayBackoffFactor to set - * @return the Builder for chaining - */ - @Deprecated - public Builder retryDelayBackoffFactor(double retryDelayBackoffFactor) { - return setRetryDelayBackoffFactor(retryDelayBackoffFactor); - } /** * Sets retryDelayBackoffFactor. @@ -217,18 +167,6 @@ public Builder setRetryDelayBackoffFactor(double retryDelayBackoffFactor) { return this; } - /** - * Sets totalRetryPeriodMillis. Note that App Engine Standard Environment front-end modules have - * a 60 second deadline for HTTP requests. For that reason, you should set the total retry - * period to under 60 seconds if you are using it on an App Engine front-end module. - * - * @param totalRetryPeriodMillis the totalRetryPeriodMillis to set - * @return the Builder for chaining - */ - @Deprecated - public Builder totalRetryPeriodMillis(long totalRetryPeriodMillis) { - return setTotalRetryPeriodMillis(totalRetryPeriodMillis); - } /** * Sets totalRetryPeriodMillis. Note that App Engine Standard Environment front-end modules have @@ -275,13 +213,6 @@ private RetryParams(Builder builder) { checkArgument(totalRetryPeriodMillis >= 0, "totalRetryPeriodMillis must not be negative"); } - /** - * Returns an instance with the default parameters. - */ - @Deprecated - public static RetryParams defaultInstance() { - return getDefaultInstance(); - } /** * Returns an instance with the default parameters. @@ -298,13 +229,6 @@ public static RetryParams noRetries() { return NO_RETRIES; } - /** - * Returns the retryMinAttempts. Default value is {@value #DEFAULT_RETRY_MIN_ATTEMPTS}. - */ - @Deprecated - public int retryMinAttempts() { - return getRetryMinAttempts(); - } /** * Returns the retryMinAttempts. Default value is {@value #DEFAULT_RETRY_MIN_ATTEMPTS}. @@ -313,13 +237,6 @@ public int getRetryMinAttempts() { return retryMinAttempts; } - /** - * Returns the retryMaxAttempts. Default value is {@value #DEFAULT_RETRY_MAX_ATTEMPTS}. - */ - @Deprecated - public int retryMaxAttempts() { - return getRetryMaxAttempts(); - } /** * Returns the retryMaxAttempts. Default value is {@value #DEFAULT_RETRY_MAX_ATTEMPTS}. @@ -328,14 +245,6 @@ public int getRetryMaxAttempts() { return retryMaxAttempts; } - /** - * Returns the initialRetryDelayMillis. Default value is - * {@value #DEFAULT_INITIAL_RETRY_DELAY_MILLIS}. - */ - @Deprecated - public long initialRetryDelayMillis() { - return getInitialRetryDelayMillis(); - } /** * Returns the initialRetryDelayMillis. Default value is @@ -345,13 +254,6 @@ public long getInitialRetryDelayMillis() { return initialRetryDelayMillis; } - /** - * Returns the maxRetryDelayMillis. Default values is {@value #DEFAULT_MAX_RETRY_DELAY_MILLIS}. - */ - @Deprecated - public long maxRetryDelayMillis() { - return getMaxRetryDelayMillis(); - } /** * Returns the maxRetryDelayMillis. Default values is {@value #DEFAULT_MAX_RETRY_DELAY_MILLIS}. @@ -360,14 +262,6 @@ public long getMaxRetryDelayMillis() { return maxRetryDelayMillis; } - /** - * Returns the maxRetryDelayBackoffFactor. Default values is - * {@value #DEFAULT_RETRY_DELAY_BACKOFF_FACTOR}. - */ - @Deprecated - public double retryDelayBackoffFactor() { - return getRetryDelayBackoffFactor(); - } /** * Returns the maxRetryDelayBackoffFactor. Default values is @@ -377,14 +271,6 @@ public double getRetryDelayBackoffFactor() { return retryDelayBackoffFactor; } - /** - * Returns the totalRetryPeriodMillis. Default value is - * {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}. - */ - @Deprecated - public long totalRetryPeriodMillis() { - return getTotalRetryPeriodMillis(); - } /** * Returns the totalRetryPeriodMillis. Default value is @@ -428,10 +314,6 @@ public String toString() { return toStringHelper.toString(); } - @Deprecated - public static Builder builder() { - return newBuilder(); - } public static Builder newBuilder() { return new Builder(); diff --git a/google-cloud-core/src/main/java/com/google/cloud/Role.java b/google-cloud-core/src/main/java/com/google/cloud/Role.java index 9444421e6b..e7742b2b93 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Role.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Role.java @@ -40,14 +40,6 @@ private Role(String value) { this.value = value; } - /** - * Returns the string identifier for this role. For example, {@code "roles/viewer"}, - * {@code "roles/editor"}, or {@code "roles/owner"}. - */ - @Deprecated - public String value() { - return getValue(); - } /** * Returns the string identifier for this role. For example, {@code "roles/viewer"}, diff --git a/google-cloud-core/src/main/java/com/google/cloud/Service.java b/google-cloud-core/src/main/java/com/google/cloud/Service.java index 4c64e6fab2..3c3c87bd76 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Service.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Service.java @@ -22,8 +22,6 @@ * @param the {@code ServiceOptions} subclass corresponding to the service */ public interface Service> { - @Deprecated - OptionsT options(); OptionsT getOptions(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 9122aa525b..d5b155486b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -135,13 +135,6 @@ protected B self() { return (B) this; } - /** - * Sets the service factory. - */ - @Deprecated - public B serviceFactory(ServiceFactory serviceFactory) { - return setServiceFactory(serviceFactory); - } /** * Sets the service factory. @@ -151,17 +144,6 @@ public B setServiceFactory(ServiceFactory serviceFactory) { return self(); } - /** - * Sets the service's clock. The clock is mainly used for testing purpose. {@link Clock} will be - * replaced by Java8's {@code java.time.Clock}. - * - * @param clock the clock to set - * @return the builder - */ - @Deprecated - public B clock(Clock clock) { - return setClock(clock); - } /** * Sets the service's clock. The clock is mainly used for testing purpose. {@link Clock} will be @@ -175,16 +157,6 @@ public B setClock(Clock clock) { return self(); } - /** - * Sets the project ID. If no project ID is set, {@link #getDefaultProjectId()} will be used to - * attempt getting the project ID from the environment. - * - * @return the builder - */ - @Deprecated - public B projectId(String projectId) { - return setProjectId(projectId); - } /** * Sets the project ID. If no project ID is set, {@link #getDefaultProjectId()} will be used to @@ -197,15 +169,6 @@ public B setProjectId(String projectId) { return self(); } - /** - * Sets service host. - * - * @return the builder - */ - @Deprecated - public B host(String host) { - return setHost(host); - } /** * Sets service host. @@ -233,17 +196,6 @@ public B setCredentials(Credentials credentials) { return self(); } - /** - * Sets configuration parameters for request retries. If no configuration is set - * {@link RetryParams#getDefaultInstance()} is used. To disable retries, supply - * {@link RetryParams#noRetries()} here. - * - * @return the builder - */ - @Deprecated - public B retryParams(RetryParams retryParams) { - return setRetryParams(retryParams); - } /** * Sets configuration parameters for request retries. If no configuration is set @@ -257,15 +209,6 @@ public B setRetryParams(RetryParams retryParams) { return self(); } - /** - * Sets the factory for rpc services. - * - * @return the builder - */ - @Deprecated - public B serviceRpcFactory(ServiceRpcFactory serviceRpcFactory) { - return setServiceRpcFactory(serviceRpcFactory); - } /** * Sets the factory for rpc services. @@ -318,19 +261,11 @@ private static GoogleCredentials defaultCredentials() { } } - @Deprecated - protected String defaultHost() { - return getDefaultHost(); - } protected String getDefaultHost() { return DEFAULT_HOST; } - @Deprecated - protected String defaultProject() { - return getDefaultProject(); - } protected String getDefaultProject() { return getDefaultProjectId(); @@ -479,10 +414,6 @@ protected static String getServiceAccountProjectId() { return project; } - @Deprecated - public ServiceT service() { - return getService(); - } @SuppressWarnings("unchecked") public ServiceT getService() { @@ -492,10 +423,6 @@ public ServiceT getService() { return service; } - @Deprecated - public ServiceRpcT rpc() { - return getRpc(); - } @SuppressWarnings("unchecked") public ServiceRpcT getRpc() { @@ -505,14 +432,6 @@ public ServiceRpcT getRpc() { return rpc; } - /** - * Returns the project ID. Return value can be null (for services that don't require a project - * ID). - */ - @Deprecated - public String projectId() { - return getProjectId(); - } /** * Returns the project ID. Return value can be null (for services that don't require a project @@ -522,13 +441,6 @@ public String getProjectId() { return projectId; } - /** - * Returns the service host. - */ - @Deprecated - public String host() { - return getHost(); - } /** * Returns the service host. @@ -556,14 +468,6 @@ public Credentials getScopedCredentials() { return credentialsToReturn; } - /** - * Returns configuration parameters for request retries. By default requests are retried: - * {@link RetryParams#getDefaultInstance()} is used. - */ - @Deprecated - public RetryParams retryParams() { - return getRetryParams(); - } /** * Returns configuration parameters for request retries. By default requests are retried: @@ -573,14 +477,6 @@ public RetryParams getRetryParams() { return retryParams; } - /** - * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to get - * current time. - */ - @Deprecated - public Clock clock() { - return getClock(); - } /** * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to get @@ -590,13 +486,6 @@ public Clock getClock() { return clock; } - /** - * Returns the application's name as a string in the format {@code gcloud-java/[version]}. - */ - @Deprecated - public String applicationName() { - return getApplicationName(); - } /** * Returns the application's name as a string in the format {@code gcloud-java/[version]}. @@ -605,13 +494,6 @@ public String getApplicationName() { return APPLICATION_NAME; } - /** - * Returns the library's name, {@code gcloud-java}, as a string. - */ - @Deprecated - public String libraryName() { - return getLibraryName(); - } /** * Returns the library's name, {@code gcloud-java}, as a string. @@ -671,24 +553,12 @@ static T newInstance(String className) throws IOException, ClassNotFoundExce } } - @Deprecated - protected ServiceFactory defaultServiceFactory() { - return getDefaultServiceFactory(); - } protected abstract ServiceFactory getDefaultServiceFactory(); - @Deprecated - protected ServiceRpcFactory defaultRpcFactory() { - return getDefaultRpcFactory(); - } protected abstract ServiceRpcFactory getDefaultRpcFactory(); - @Deprecated - protected Set scopes() { - return getScopes(); - } protected abstract Set getScopes(); diff --git a/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java b/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java index 1938f81994..a84b25bc36 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java +++ b/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java @@ -60,13 +60,6 @@ private CheckingPeriod(long period, TimeUnit unit) { this.unit = unit; } - /** - * Returns the checking period. - */ - @Deprecated - public long period() { - return getPeriod(); - } /** * Returns the checking period. @@ -75,13 +68,6 @@ public long getPeriod() { return period; } - /** - * Returns the time unit for {@link #getPeriod()}. - */ - @Deprecated - public TimeUnit unit() { - return getUnit(); - } /** * Returns the time unit for {@link #getPeriod()}. @@ -152,13 +138,6 @@ private Timeout(long timeoutMillis) { this.timeoutMillis = timeoutMillis; } - /** - * Returns the timeout in milliseconds. - */ - @Deprecated - public long timeoutMillis() { - return getTimeoutMillis(); - } /** * Returns the timeout in milliseconds. diff --git a/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java index f061f55ac5..172e4b03bf 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java @@ -29,12 +29,6 @@ */ public interface WriteChannel extends WritableByteChannel, Closeable, Restorable { - /** - * Sets the minimum size that will be written by a single RPC. - * Written data will be buffered and only flushed upon reaching this size or closing the channel. - */ - @Deprecated - void chunkSize(int chunkSize); /** * Sets the minimum size that will be written by a single RPC. diff --git a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java index 0767d205ec..1f6298857a 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java @@ -50,11 +50,6 @@ private static class TestPageFetcher implements AsyncPageImpl.NextPageFetcher> nextPage() { - return getNextPage(); - } - @Override public Future> getNextPage() { return Futures.>immediateFuture(nextResult); @@ -71,15 +66,6 @@ public void testPage() { assertEquals(VALUES1, result.getValues()); } - @Test - public void testPageDeprecated() { - final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2); - AsyncPageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); - AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1); - assertEquals(nextResult, result.nextPage()); - assertEquals("c", result.nextPageCursor()); - assertEquals(VALUES1, result.values()); - } @Test public void testPageAsync() throws ExecutionException, InterruptedException { @@ -91,15 +77,6 @@ public void testPageAsync() throws ExecutionException, InterruptedException { assertEquals(VALUES1, result.getValues()); } - @Test - public void testPageAsyncDeprecated() throws ExecutionException, InterruptedException { - final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2); - AsyncPageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); - AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1); - assertEquals(nextResult, result.nextPageAsync().get()); - assertEquals("c", result.nextPageCursor()); - assertEquals(VALUES1, result.values()); - } @Test public void testIterateAll() { diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index 8980643b32..9ac4b4b989 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -150,94 +150,6 @@ public void testBaseServiceException() { assertEquals(IDEMPOTENT, serviceException.isIdempotent()); } - @Test - public void testBaseServiceExceptionDeprecated() { - BaseServiceException serviceException = new BaseServiceException(CODE, MESSAGE, REASON, - IDEMPOTENT); - assertEquals(CODE, serviceException.code()); - assertEquals(MESSAGE, serviceException.getMessage()); - assertEquals(REASON, serviceException.reason()); - assertFalse(serviceException.retryable()); - assertEquals(IDEMPOTENT, serviceException.idempotent()); - assertNull(serviceException.getCause()); - - serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); - assertEquals(CODE, serviceException.code()); - assertEquals(MESSAGE, serviceException.getMessage()); - assertEquals(REASON, serviceException.reason()); - assertFalse(serviceException.retryable()); - assertEquals(IDEMPOTENT, serviceException.idempotent()); - assertNull(serviceException.getCause()); - - Exception cause = new RuntimeException(); - serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, cause); - assertEquals(CODE, serviceException.code()); - assertEquals(MESSAGE, serviceException.getMessage()); - assertEquals(REASON, serviceException.reason()); - assertFalse(serviceException.retryable()); - assertEquals(IDEMPOTENT, serviceException.idempotent()); - assertEquals(cause, serviceException.getCause()); - - serviceException = new BaseServiceException(CODE, MESSAGE, REASON, false, cause); - assertEquals(CODE, serviceException.code()); - assertEquals(MESSAGE, serviceException.getMessage()); - assertEquals(REASON, serviceException.reason()); - assertFalse(serviceException.retryable()); - assertFalse(serviceException.idempotent()); - assertEquals(cause, serviceException.getCause()); - - IOException exception = new SocketTimeoutException(); - serviceException = new BaseServiceException(exception, true); - assertTrue(serviceException.retryable()); - assertTrue(serviceException.idempotent()); - assertNull(serviceException.getMessage()); - assertEquals(exception, serviceException.getCause()); - - exception = new SocketException(); - serviceException = new BaseServiceException(exception, true); - assertTrue(serviceException.retryable()); - assertTrue(serviceException.idempotent()); - assertNull(serviceException.getMessage()); - assertEquals(exception, serviceException.getCause()); - - exception = new IOException("insufficient data written"); - serviceException = new BaseServiceException(exception, true); - assertTrue(serviceException.retryable()); - assertTrue(serviceException.idempotent()); - assertEquals("insufficient data written", serviceException.getMessage()); - assertEquals(exception, serviceException.getCause()); - - GoogleJsonError error = new GoogleJsonError(); - error.setCode(CODE); - error.setMessage(MESSAGE); - serviceException = new BaseServiceException(error, true); - assertEquals(CODE, serviceException.code()); - assertEquals(MESSAGE, serviceException.getMessage()); - assertFalse(serviceException.retryable()); - assertTrue(serviceException.idempotent()); - - serviceException = new CustomServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); - assertEquals(CODE, serviceException.code()); - assertEquals(MESSAGE, serviceException.getMessage()); - assertEquals(REASON, serviceException.reason()); - assertEquals(RETRYABLE, serviceException.retryable()); - assertEquals(IDEMPOTENT, serviceException.idempotent()); - - serviceException = new CustomServiceException(CODE_NO_REASON, MESSAGE, null, IDEMPOTENT); - assertEquals(CODE_NO_REASON, serviceException.code()); - assertEquals(MESSAGE, serviceException.getMessage()); - assertNull(serviceException.reason()); - assertEquals(RETRYABLE, serviceException.retryable()); - assertEquals(IDEMPOTENT, serviceException.idempotent()); - - serviceException = new CustomServiceException(UNKNOWN_CODE, MESSAGE, REASON, IDEMPOTENT); - assertEquals(UNKNOWN_CODE, serviceException.code()); - assertEquals(MESSAGE, serviceException.getMessage()); - assertEquals(REASON, serviceException.reason()); - assertEquals(RETRYABLE, serviceException.retryable()); - assertEquals(IDEMPOTENT, serviceException.idempotent()); - } - @Test public void testTranslateAndThrow() throws Exception { BaseServiceException cause = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java index 9fb58a1633..a5c278a832 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java @@ -93,17 +93,6 @@ public void testConstructor() { assertEquals(DEFAULT_CHUNK_SIZE, channel.getChunkSize()); } - @Test - public void testConstructorDeprecated() { - assertEquals(null, channel.options()); - assertEquals(ENTITY, channel.entity()); - assertEquals(0, channel.position()); - assertEquals(UPLOAD_ID, channel.uploadId()); - assertEquals(0, channel.limit()); - assertTrue(channel.isOpen()); - assertArrayEquals(new byte[0], channel.buffer()); - assertEquals(DEFAULT_CHUNK_SIZE, channel.chunkSize()); - } @Test public void testClose() throws IOException { diff --git a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java index 408dc73132..d95200a1c7 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java @@ -29,33 +29,18 @@ public class FieldSelectorHelperTest { private static final FieldSelector FIELD1 = new FieldSelector() { - @Override - public String selector() { - return getSelector(); - } - @Override public String getSelector() { return "field1"; } }; private static final FieldSelector FIELD2 = new FieldSelector() { - @Override - public String selector() { - return getSelector(); - } - @Override public String getSelector() { return "field2"; } }; private static final FieldSelector FIELD3 = new FieldSelector() { - @Override - public String selector() { - return getSelector(); - } - @Override public String getSelector() { return "field3"; diff --git a/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java index f0906fae03..a5c7cebfc4 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java @@ -43,18 +43,8 @@ public class GrpcServiceOptionsTest { .setMaxTimeout(5678) .setExecutorFactory(MOCK_EXECUTOR_FACTORY) .build(); - private static final TestGrpcServiceOptions DEPRECATED_OPTIONS = - TestGrpcServiceOptions.newBuilder() - .projectId("project-id") - .initialTimeout(1234) - .timeoutMultiplier(1.6) - .maxTimeout(5678) - .executorFactory(MOCK_EXECUTOR_FACTORY) - .build(); private static final TestGrpcServiceOptions DEFAULT_OPTIONS = TestGrpcServiceOptions.newBuilder().setProjectId("project-id").build(); - private static final TestGrpcServiceOptions DEPRECATED_DEFAULT_OPTIONS = - TestGrpcServiceOptions.newBuilder().projectId("project-id").build(); private static final TestGrpcServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); private interface TestService extends Service {} @@ -164,18 +154,6 @@ public void testBuilder() { assertTrue(DEFAULT_OPTIONS.getExecutorFactory() instanceof DefaultExecutorFactory); } - @Test - public void testBuilderDeprecated() { - assertEquals(1234, DEPRECATED_OPTIONS.initialTimeout()); - assertEquals(1.6, DEPRECATED_OPTIONS.timeoutMultiplier(), 0.0); - assertEquals(5678, DEPRECATED_OPTIONS.maxTimeout()); - assertSame(MOCK_EXECUTOR_FACTORY, DEPRECATED_OPTIONS.executorFactory()); - assertEquals(20000, DEPRECATED_DEFAULT_OPTIONS.initialTimeout()); - assertEquals(1.5, DEPRECATED_DEFAULT_OPTIONS.timeoutMultiplier(), 0.0); - assertEquals(100000, DEPRECATED_DEFAULT_OPTIONS.maxTimeout()); - assertTrue(DEPRECATED_DEFAULT_OPTIONS.executorFactory() instanceof DefaultExecutorFactory); - } - @Test public void testBuilderError() { try { diff --git a/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java index 9ac2891c6c..81e330236c 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java @@ -40,17 +40,8 @@ public class HttpServiceOptionsTest { .setHttpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) .setReadTimeout(5678) .build(); - private static final TestHttpServiceOptions DEPRECATED_OPTIONS = - TestHttpServiceOptions.newBuilder() - .projectId("project-id") - .connectTimeout(1234) - .httpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) - .readTimeout(5678) - .build(); private static final TestHttpServiceOptions DEFAULT_OPTIONS = TestHttpServiceOptions.newBuilder().setProjectId("project-id").build(); - private static final TestHttpServiceOptions DEPRECATED_DEFAULT_OPTIONS = - TestHttpServiceOptions.newBuilder().projectId("project-id").build(); private static final TestHttpServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); private interface TestService extends Service {} @@ -158,17 +149,6 @@ public void testBuilder() { assertEquals(-1, DEFAULT_OPTIONS.getReadTimeout()); } - @Test - public void testBuilderDeprecated() { - assertEquals(1234, DEPRECATED_OPTIONS.connectTimeout()); - assertSame(MOCK_HTTP_TRANSPORT_FACTORY, DEPRECATED_OPTIONS.httpTransportFactory()); - assertEquals(5678, DEPRECATED_OPTIONS.readTimeout()); - assertEquals(-1, DEPRECATED_DEFAULT_OPTIONS.connectTimeout()); - assertTrue( - DEPRECATED_DEFAULT_OPTIONS.httpTransportFactory() instanceof DefaultHttpTransportFactory); - assertEquals(-1, DEPRECATED_DEFAULT_OPTIONS.readTimeout()); - } - @Test public void testBaseEquals() { assertEquals(OPTIONS, OPTIONS_COPY); diff --git a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java index 5a80daa50d..b7b244adb9 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java @@ -37,11 +37,6 @@ public void testAllUsers() { assertNull(ALL_USERS.getValue()); } - @Test - public void testAllUsersDeprecated() { - assertEquals(Identity.Type.ALL_USERS, ALL_USERS.type()); - assertNull(ALL_USERS.value()); - } @Test public void testAllAuthenticatedUsers() { @@ -49,11 +44,6 @@ public void testAllAuthenticatedUsers() { assertNull(ALL_AUTH_USERS.getValue()); } - @Test - public void testAllAuthenticatedUsersDeprecated() { - assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTH_USERS.type()); - assertNull(ALL_AUTH_USERS.value()); - } @Test public void testUser() { @@ -61,11 +51,6 @@ public void testUser() { assertEquals("abc@gmail.com", USER.getValue()); } - @Test - public void testUserDeprecated() { - assertEquals(Identity.Type.USER, USER.type()); - assertEquals("abc@gmail.com", USER.value()); - } @Test(expected = NullPointerException.class) public void testUserNullEmail() { @@ -78,11 +63,6 @@ public void testServiceAccount() { assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.getValue()); } - @Test - public void testServiceAccountDeprecated() { - assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type()); - assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.value()); - } @Test(expected = NullPointerException.class) public void testServiceAccountNullEmail() { @@ -95,11 +75,6 @@ public void testGroup() { assertEquals("group@gmail.com", GROUP.getValue()); } - @Test - public void testGroupDeprecated() { - assertEquals(Identity.Type.GROUP, GROUP.type()); - assertEquals("group@gmail.com", GROUP.value()); - } @Test(expected = NullPointerException.class) public void testGroupNullEmail() { @@ -112,11 +87,6 @@ public void testDomain() { assertEquals("google.com", DOMAIN.getValue()); } - @Test - public void testDomainDeprecated() { - assertEquals(Identity.Type.DOMAIN, DOMAIN.type()); - assertEquals("google.com", DOMAIN.value()); - } @Test(expected = NullPointerException.class) public void testDomainNullId() { diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java index 24a8be62e7..e380eab471 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java @@ -67,21 +67,6 @@ public void testLabelDescriptor() { assertNull(INT_LABEL_NO_DESCRIPTION.getDescription()); } - @Test - public void testLabelDescriptorDeprecated() { - assertEquals("booleanKey", BOOLEAN_LABEL.key()); - assertEquals(ValueType.BOOL, BOOLEAN_LABEL.valueType()); - assertEquals("Boolean label", BOOLEAN_LABEL.description()); - assertEquals("stringKey", STRING_LABEL.key()); - assertEquals(ValueType.STRING, STRING_LABEL.valueType()); - assertEquals("String label", STRING_LABEL.description()); - assertEquals("intKey", INT_LABEL.key()); - assertEquals(ValueType.INT64, INT_LABEL.valueType()); - assertEquals("Int label", INT_LABEL.description()); - assertEquals("intKey", INT_LABEL_NO_DESCRIPTION.key()); - assertEquals(ValueType.INT64, INT_LABEL_NO_DESCRIPTION.valueType()); - assertNull(INT_LABEL_NO_DESCRIPTION.description()); - } @Test public void testBuilder() { @@ -99,21 +84,6 @@ public void testBuilder() { assertEquals(ImmutableList.of(), resourceDescriptor.getLabels()); } - @Test - public void testBuilderDeprecated() { - assertEquals(TYPE, RESOURCE_DESCRIPTOR.type()); - assertEquals(NAME, RESOURCE_DESCRIPTOR.name()); - assertEquals(DISPLAY_NAME, RESOURCE_DESCRIPTOR.displayName()); - assertEquals(DESCRIPTION, RESOURCE_DESCRIPTOR.description()); - assertEquals(LABELS, RESOURCE_DESCRIPTOR.labels()); - MonitoredResourceDescriptor resourceDescriptor = - MonitoredResourceDescriptor.newBuilder(TYPE).build(); - assertEquals(TYPE, resourceDescriptor.type()); - assertNull(resourceDescriptor.name()); - assertNull(resourceDescriptor.displayName()); - assertNull(resourceDescriptor.description()); - assertEquals(ImmutableList.of(), resourceDescriptor.labels()); - } @Test public void testToAndFromPbLabelDescriptor() { diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java index 845ff035c6..324ed740e4 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java @@ -32,10 +32,6 @@ public class MonitoredResourceTest { private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.newBuilder(TYPE) .setLabels(LABELS) .build(); - private static final MonitoredResource DEPRECATED_MONITORED_RESOURCE = - MonitoredResource.builder(TYPE) - .labels(LABELS) - .build(); @Test public void testBuilder() { @@ -58,26 +54,6 @@ public void testBuilder() { assertEquals(ImmutableMap.of(), monitoredResource.getLabels()); } - @Test - public void testBuilderDeprecated() { - assertEquals(TYPE, DEPRECATED_MONITORED_RESOURCE.type()); - assertEquals(LABELS, DEPRECATED_MONITORED_RESOURCE.labels()); - MonitoredResource monitoredResource = MonitoredResource.builder(TYPE) - .addLabel("dataset-id", "myDataset") - .addLabel("zone", "myZone") - .build(); - assertEquals(TYPE, monitoredResource.type()); - assertEquals(LABELS, monitoredResource.labels()); - compareMonitoredResource(DEPRECATED_MONITORED_RESOURCE, monitoredResource); - monitoredResource = MonitoredResource.builder(TYPE) - .type("global") - .addLabel("dataset-id", "myDataset") - .addLabel("zone", "myZone") - .clearLabels() - .build(); - assertEquals("global", monitoredResource.type()); - assertEquals(ImmutableMap.of(), monitoredResource.labels()); - } @Test public void testToBuilder() { diff --git a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java index 2a70b07ac9..fb1d2c209c 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java @@ -40,11 +40,6 @@ private static class TestPageFetcher implements PageImpl.NextPageFetcher this.nextResult = nextResult; } - @Override - public Page nextPage() { - return getNextPage(); - } - @Override public Page getNextPage() { return nextResult; @@ -61,15 +56,6 @@ public void testPage() { assertEquals(VALUES, result.getValues()); } - @Test - public void testPageDeprecated() { - final PageImpl nextResult = new PageImpl<>(null, "c", NEXT_VALUES); - PageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); - PageImpl result = new PageImpl<>(fetcher, "c", VALUES); - assertEquals(nextResult, result.nextPage()); - assertEquals("c", result.nextPageCursor()); - assertEquals(VALUES, result.values()); - } @Test public void testIterateAll() { diff --git a/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java b/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java index 29583e6482..cc334ec732 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java @@ -55,20 +55,11 @@ public class PolicyTest { .addIdentity(VIEWER, USER, SERVICE_ACCOUNT, ALL_USERS) .addIdentity(EDITOR, ALL_AUTH_USERS, GROUP, DOMAIN) .build(); - private static final Policy DEPRECATED_SIMPLE_POLICY = Policy.builder() - .addIdentity(VIEWER, USER, SERVICE_ACCOUNT, ALL_USERS) - .addIdentity(EDITOR, ALL_AUTH_USERS, GROUP, DOMAIN) - .build(); private static final Policy FULL_POLICY = Policy.newBuilder() .setBindings(SIMPLE_POLICY.getBindings()) .setEtag("etag") .setVersion(1) .build(); - private static final Policy DEPRECATED_FULL_POLICY = Policy.builder() - .bindings(SIMPLE_POLICY.getBindings()) - .etag("etag") - .version(1) - .build(); @Test public void testBuilder() { @@ -108,43 +99,6 @@ public void testBuilder() { assertEquals(0, policy.getVersion()); } - @Test - public void testBuilderDeprecated() { - assertEquals(BINDINGS, DEPRECATED_SIMPLE_POLICY.bindings()); - assertEquals(null, DEPRECATED_SIMPLE_POLICY.etag()); - assertEquals(0, DEPRECATED_SIMPLE_POLICY.version()); - assertEquals(BINDINGS, DEPRECATED_FULL_POLICY.bindings()); - assertEquals("etag", DEPRECATED_FULL_POLICY.etag()); - assertEquals(1, DEPRECATED_FULL_POLICY.version()); - Map> editorBinding = - ImmutableMap.>builder().put(EDITOR, BINDINGS.get(EDITOR)).build(); - Policy policy = DEPRECATED_FULL_POLICY.toBuilder().bindings(editorBinding).build(); - assertEquals(editorBinding, policy.bindings()); - assertEquals("etag", policy.etag()); - assertEquals(1, policy.version()); - policy = DEPRECATED_SIMPLE_POLICY.toBuilder().removeRole(EDITOR).build(); - assertEquals(ImmutableMap.of(VIEWER, BINDINGS.get(VIEWER)), policy.bindings()); - assertNull(policy.etag()); - assertEquals(0, policy.version()); - policy = policy.toBuilder() - .removeIdentity(VIEWER, USER, ALL_USERS) - .addIdentity(VIEWER, DOMAIN, GROUP) - .build(); - assertEquals(ImmutableMap.of(VIEWER, ImmutableSet.of(SERVICE_ACCOUNT, DOMAIN, GROUP)), - policy.bindings()); - assertNull(policy.etag()); - assertEquals(0, policy.version()); - policy = Policy.builder() - .removeIdentity(VIEWER, USER) - .addIdentity(OWNER, USER, SERVICE_ACCOUNT) - .addIdentity(EDITOR, GROUP) - .removeIdentity(EDITOR, GROUP) - .build(); - assertEquals(ImmutableMap.of(OWNER, ImmutableSet.of(USER, SERVICE_ACCOUNT)), policy.bindings()); - assertNull(policy.etag()); - assertEquals(0, policy.version()); - } - @Test public void testIllegalPolicies() { try { diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java index 987cf1daa1..68bb7ce353 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java @@ -101,51 +101,6 @@ public void testTriesWithExceptionHandling() { assertNull(RetryHelper.getContext()); } - @Test - public void testTriesWithExceptionHandlingDeprecated() { - assertNull(RetryHelper.getContext()); - RetryParams params = - RetryParams.builder().initialRetryDelayMillis(0).retryMaxAttempts(3).build(); - ExceptionHandler handler = ExceptionHandler.builder() - .retryOn(IOException.class).abortOn(RuntimeException.class).build(); - final AtomicInteger count = new AtomicInteger(3); - try { - RetryHelper.runWithRetries(new Callable() { - @Override public Void call() throws IOException, NullPointerException { - if (count.decrementAndGet() == 2) { - assertEquals(1, RetryHelper.getContext().getAttemptNumber()); - throw new IOException("should be retried"); - } - assertEquals(2, RetryHelper.getContext().getAttemptNumber()); - throw new NullPointerException("Boo!"); - } - }, params, handler); - fail("Exception should have been thrown"); - } catch (NonRetriableException ex) { - assertEquals("Boo!", ex.getCause().getMessage()); - assertEquals(1, count.intValue()); - } - assertNull(RetryHelper.getContext()); - - params = RetryParams.builder().initialRetryDelayMillis(0).retryMaxAttempts(5).build(); - handler = ExceptionHandler.builder() - .retryOn(E1Exception.class, E4Exception.class) - .abortOn(E3Exception.class).build(); - final Iterator exceptions = Arrays.asList( - new E1Exception(), new E2Exception(), new E4Exception(), new E3Exception()).iterator(); - try { - RetryHelper.runWithRetries(new Callable() { - @Override public Void call() throws E1Exception { - throw exceptions.next(); - } - }, params, handler); - fail("Exception should have been thrown"); - } catch (NonRetriableException ex) { - assertTrue(ex.getCause() instanceof E3Exception); - } - assertNull(RetryHelper.getContext()); - } - @Test public void testTriesAtLeastMinTimes() { // Total retry period set to 60 seconds so as to not factor into test @@ -172,31 +127,6 @@ public void testTriesAtLeastMinTimes() { assertNull(RetryHelper.getContext()); } - @Test - public void testTriesAtLeastMinTimesDeprecated() { - // Total retry period set to 60 seconds so as to not factor into test - RetryParams params = RetryParams.builder().initialRetryDelayMillis(0) - .totalRetryPeriodMillis(60000) - .retryMinAttempts(5) - .retryMaxAttempts(10) - .build(); - final int timesToFail = 7; - assertNull(RetryHelper.getContext()); - int attempted = RetryHelper.runWithRetries(new Callable() { - int timesCalled; - @Override public Integer call() throws IOException { - timesCalled++; - assertEquals(timesCalled, RetryHelper.getContext().getAttemptNumber()); - assertEquals(10, RetryHelper.getContext().getRetryParams().retryMaxAttempts()); - if (timesCalled <= timesToFail) { - throw new IOException(); - } - return timesCalled; - } - }, params, ExceptionHandler.defaultInstance()); - assertEquals(timesToFail + 1, attempted); - assertNull(RetryHelper.getContext()); - } @Test public void testTriesNoMoreThanMaxTimes() { @@ -226,33 +156,6 @@ public void testTriesNoMoreThanMaxTimes() { } } - @Test - public void testTriesNoMoreThanMaxTimesDeprecated() { - // Total retry period set to 60 seconds so as to not factor into test - final int maxAttempts = 10; - RetryParams params = RetryParams.builder().initialRetryDelayMillis(0) - .totalRetryPeriodMillis(60000) - .retryMinAttempts(0) - .retryMaxAttempts(maxAttempts) - .build(); - final AtomicInteger timesCalled = new AtomicInteger(0); - try { - RetryHelper.runWithRetries(callable(new Runnable() { - @Override public void run() { - // Throw an exception up to maxAttempts times, should never be called beyond that - if (timesCalled.incrementAndGet() <= maxAttempts) { - throw new RuntimeException(); - } - fail("Body was executed too many times: " + timesCalled.get()); - } - }), params, ExceptionHandler.builder().retryOn(RuntimeException.class).build()); - // Unnecessary as this line should not be possible reach even if RetryHandler is broken - fail("Should not have succeeded, expected all attempts to fail and give up."); - } catch (RetriesExhaustedException expected) { - // Expect the body to run exactly maxAttempts times - assertEquals(maxAttempts, timesCalled.get()); - } - } private static class FakeClock extends Clock { diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java index c963580429..5f822fe7ae 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java @@ -53,19 +53,6 @@ public void testDefaults() { } } - @Test - public void testDefaultsDeprecated() { - RetryParams params1 = RetryParams.defaultInstance(); - RetryParams params2 = RetryParams.builder().build(); - for (RetryParams params : Arrays.asList(params1, params2)) { - assertEquals(DEFAULT_INITIAL_RETRY_DELAY_MILLIS, params.initialRetryDelayMillis()); - assertEquals(DEFAULT_MAX_RETRY_DELAY_MILLIS, params.maxRetryDelayMillis()); - assertEquals(DEFAULT_RETRY_DELAY_BACKOFF_FACTOR, params.retryDelayBackoffFactor(), 0); - assertEquals(DEFAULT_RETRY_MAX_ATTEMPTS, params.retryMaxAttempts()); - assertEquals(DEFAULT_RETRY_MIN_ATTEMPTS, params.retryMinAttempts()); - assertEquals(DEFAULT_TOTAL_RETRY_PERIOD_MILLIS, params.totalRetryPeriodMillis()); - } - } @Test public void testSetAndCopy() { @@ -88,26 +75,6 @@ public void testSetAndCopy() { } } - @Test - public void testSetAndCopyDeprecated() { - RetryParams.Builder builder = RetryParams.builder(); - builder.initialRetryDelayMillis(101); - builder.maxRetryDelayMillis(102); - builder.retryDelayBackoffFactor(103); - builder.retryMinAttempts(107); - builder.retryMaxAttempts(108); - builder.totalRetryPeriodMillis(109); - RetryParams params1 = builder.build(); - RetryParams params2 = new RetryParams.Builder(params1).build(); - for (RetryParams params : Arrays.asList(params1, params2)) { - assertEquals(101, params.initialRetryDelayMillis()); - assertEquals(102, params.maxRetryDelayMillis()); - assertEquals(103, params.retryDelayBackoffFactor(), 0); - assertEquals(107, params.retryMinAttempts()); - assertEquals(108, params.retryMaxAttempts()); - assertEquals(109, params.totalRetryPeriodMillis()); - } - } @Test public void testBadSettings() { diff --git a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java index 7cce4ee4fb..75df1d301d 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java @@ -36,15 +36,6 @@ public void testOf() { compareRoles(OWNER, Role.of("roles/owner")); } - @Test - public void testOfDeprecated() { - assertEquals("roles/viewer", VIEWER.value()); - assertEquals("roles/editor", EDITOR.value()); - assertEquals("roles/owner", OWNER.value()); - compareRoles(VIEWER, Role.of("roles/viewer")); - compareRoles(EDITOR, Role.of("roles/editor")); - compareRoles(OWNER, Role.of("roles/owner")); - } @Test public void testViewer() { diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index cf364db57e..e08b5c35ce 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -89,18 +89,8 @@ public class ServiceOptionsTest { .setProjectId("project-id") .setRetryParams(RetryParams.noRetries()) .build(); - private static final TestServiceOptions DEPRECATED_OPTIONS = - TestServiceOptions.newBuilder() - .setCredentials(credentials) - .clock(TEST_CLOCK) - .host("host") - .projectId("project-id") - .retryParams(RetryParams.noRetries()) - .build(); private static final TestServiceOptions DEFAULT_OPTIONS = TestServiceOptions.newBuilder().setProjectId("project-id").build(); - private static final TestServiceOptions DEPRECATED_DEFAULT_OPTIONS = - TestServiceOptions.newBuilder().projectId("project-id").build(); private static final TestServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); private static final String LIBRARY_NAME = "gcloud-java"; private static final Pattern APPLICATION_NAME_PATTERN = @@ -236,18 +226,6 @@ public void testBuilderNullCredentials() { TestServiceOptions.newBuilder().setCredentials(null).build(); } - @Test - public void testBuilderDeprecated() { - assertSame(credentials, DEPRECATED_OPTIONS.getCredentials()); - assertSame(TEST_CLOCK, DEPRECATED_OPTIONS.clock()); - assertEquals("host", DEPRECATED_OPTIONS.host()); - assertEquals("project-id", DEPRECATED_OPTIONS.projectId()); - assertSame(RetryParams.noRetries(), DEPRECATED_OPTIONS.retryParams()); - assertSame(Clock.defaultClock(), DEPRECATED_DEFAULT_OPTIONS.clock()); - assertEquals("https://www.googleapis.com", DEPRECATED_DEFAULT_OPTIONS.host()); - assertSame(RetryParams.getDefaultInstance(), DEPRECATED_DEFAULT_OPTIONS.retryParams()); - } - @Test public void testGetProjectIdRequired() { assertTrue(OPTIONS.projectIdRequired()); diff --git a/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java index 959b086aed..dffc160beb 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java @@ -45,12 +45,6 @@ public void testCheckEvery() { assertEquals(TimeUnit.MILLISECONDS, CHECKING_PERIOD_OPTION.getUnit()); } - @Test - public void testCheckEveryDeprecated() { - assertEquals(OptionType.CHECKING_PERIOD, CHECKING_PERIOD_OPTION.getOptionType()); - assertEquals(42, CHECKING_PERIOD_OPTION.period()); - assertEquals(TimeUnit.MILLISECONDS, CHECKING_PERIOD_OPTION.unit()); - } @Test public void testCheckEvery_InvalidPeriod() { @@ -59,13 +53,6 @@ public void testCheckEvery_InvalidPeriod() { WaitForOption.checkEvery(-1, TimeUnit.MILLISECONDS); } - @Test - public void testTimeoutDeprecated() { - assertEquals(OptionType.TIMEOUT, TIMEOUT_OPTION.getOptionType()); - assertEquals(43, TIMEOUT_OPTION.timeoutMillis()); - Timeout timeoutOption = WaitForOption.timeout(43, TimeUnit.SECONDS); - assertEquals(43_000, timeoutOption.timeoutMillis()); - } @Test public void testTimeout_InvalidTimeout() { From 0fbaa62f20077be5063a7b8af4adda6c320317c7 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Tue, 7 Mar 2017 16:28:20 -0800 Subject: [PATCH 295/663] Remove deprecated methods in google-cloud-core (#1707) --- .../com/google/cloud/GrpcServiceOptions.java | 89 ------------------- .../com/google/cloud/HttpServiceOptions.java | 15 +--- 2 files changed, 1 insertion(+), 103 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java index 75c99c9506..8777ac4783 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java @@ -154,17 +154,6 @@ protected Builder(GrpcServiceOptions options) { @Override protected abstract GrpcServiceOptions build(); - /** - * Sets the scheduled executor factory. This method can be used to provide an user-defined - * scheduled executor to execute requests. - * - * @return the builder - */ - @Deprecated - public B executorFactory(ExecutorFactory executorFactory) { - return setExecutorFactory(executorFactory); - } - /** * Sets the scheduled executor factory. This method can be used to provide an user-defined * scheduled executor to execute requests. @@ -176,18 +165,6 @@ public B setExecutorFactory(ExecutorFactory executorFa return self(); } - /** - * Sets the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value - * adjusted according to {@link #setTimeoutMultiplier(double)}. Default value is 20000. - * - * @return the builder - * @throws IllegalArgumentException if the provided timeout is < 0 - */ - @Deprecated - public B initialTimeout(int initialTimeout) { - return setInitialTimeout(initialTimeout); - } - /** * Sets the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value * adjusted according to {@link #setTimeoutMultiplier(double)}. Default value is 20000. @@ -201,18 +178,6 @@ public B setInitialTimeout(int initialTimeout) { return self(); } - /** - * Sets the timeout multiplier. This value is used to compute the timeout for a retried RPC. - * Timeout is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. - * - * @return the builder - * @throws IllegalArgumentException if the provided timeout multiplier is < 0 - */ - @Deprecated - public B timeoutMultiplier(double timeoutMultiplier) { - return setTimeoutMultiplier(timeoutMultiplier); - } - /** * Sets the timeout multiplier. This value is used to compute the timeout for a retried RPC. * Timeout is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. @@ -226,18 +191,6 @@ public B setTimeoutMultiplier(double timeoutMultiplier) { return self(); } - /** - * Sets the maximum timeout for a RPC call, in milliseconds. Default value is 100000. If - * {@code maxTimeout} is lower than the initial timeout the {@link #setInitialTimeout(int)} - * value is used instead. - * - * @return the builder - */ - @Deprecated - public B maxTimeout(int maxTimeout) { - return setMaxTimeout(maxTimeout); - } - /** * Sets the maximum timeout for a RPC call, in milliseconds. Default value is 100000. If * {@code maxTimeout} is lower than the initial timeout the {@link #setInitialTimeout(int)} @@ -265,14 +218,6 @@ protected GrpcServiceOptions( maxTimeout = builder.maxTimeout <= initialTimeout ? initialTimeout : builder.maxTimeout; } - /** - * Returns a scheduled executor service provider. - */ - @Deprecated - protected ExecutorFactory executorFactory() { - return getExecutorFactory(); - } - /** * Returns a scheduled executor service provider. */ @@ -280,14 +225,6 @@ protected ExecutorFactory getExecutorFactory() { return executorFactory; } - /** - * Returns a builder for API call settings. - */ - @Deprecated - protected UnaryCallSettings.Builder apiCallSettings() { - return getApiCallSettings(); - } - /** * Returns a builder for API call settings. */ @@ -321,15 +258,6 @@ protected ChannelProvider getChannelProvider() { return builder.build(); } - /** - * Returns the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value - * adjusted according to {@link #getTimeoutMultiplier()}. Default value is 20000. - */ - @Deprecated - public int initialTimeout() { - return getInitialTimeout(); - } - /** * Returns the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value * adjusted according to {@link #getTimeoutMultiplier()}. Default value is 20000. @@ -338,15 +266,6 @@ public int getInitialTimeout() { return initialTimeout; } - /** - * Returns the timeout multiplier. This values is used to compute the timeout for a RPC. Timeout - * is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. - */ - @Deprecated - public double timeoutMultiplier() { - return getTimeoutMultiplier(); - } - /** * Returns the timeout multiplier. This values is used to compute the timeout for a RPC. Timeout * is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. @@ -355,14 +274,6 @@ public double getTimeoutMultiplier() { return timeoutMultiplier; } - /** - * Returns the maximum timeout for a RPC call, in milliseconds. Default value is 100000. - */ - @Deprecated - public int maxTimeout() { - return getMaxTimeout(); - } - /** * Returns the maximum timeout for a RPC call, in milliseconds. Default value is 100000. */ diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java index 1613b68acb..63ac94c114 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java @@ -98,12 +98,12 @@ protected Builder(HttpServiceOptions options) { @Override protected abstract HttpServiceOptions build(); + @Override @SuppressWarnings("unchecked") protected B self() { return (B) this; } - /** * Sets the HTTP transport factory. * @@ -114,7 +114,6 @@ public B setHttpTransportFactory(HttpTransportFactory httpTransportFactory) { return self(); } - /** * Sets the timeout in milliseconds to establish a connection. * @@ -127,7 +126,6 @@ public B setConnectTimeout(int connectTimeout) { return self(); } - /** * Sets the timeout in milliseconds to read data from an established connection. * @@ -153,7 +151,6 @@ protected HttpServiceOptions( readTimeout = builder.readTimeout; } - /** * Returns the HTTP transport factory. */ @@ -161,7 +158,6 @@ public HttpTransportFactory getHttpTransportFactory() { return httpTransportFactory; } - /** * Returns a request initializer responsible for initializing requests according to service * options. @@ -187,14 +183,6 @@ public void initialize(HttpRequest httpRequest) throws IOException { }; } - /** - * Returns the timeout in milliseconds to establish a connection. 0 is an infinite timeout, a - * negative number is the default value (20000). - */ - public int connectTimeout() { - return getConnectTimeout(); - } - /** * Returns the timeout in milliseconds to establish a connection. 0 is an infinite timeout, a * negative number is the default value (20000). @@ -203,7 +191,6 @@ public int getConnectTimeout() { return connectTimeout; } - /** * Returns the timeout in milliseconds to read from an established connection. 0 is an infinite * timeout, a negative number is the default value (20000). From d14b5c7411cd840d72cda74f41178ee08a8980b4 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Wed, 8 Mar 2017 09:09:42 -0800 Subject: [PATCH 296/663] Pub/Sub: Converting Future -> ApiFuture (#1709) Also, deleting PullFuture which is subsumed by ApiFuture. --- .../src/main/java/com/google/cloud/AsyncPage.java | 8 ++++---- .../src/main/java/com/google/cloud/AsyncPageImpl.java | 11 +++++------ .../test/java/com/google/cloud/AsyncPageImplTest.java | 8 ++++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java index 13fa7a6cb9..abc1c36028 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java @@ -16,7 +16,7 @@ package com.google.cloud; -import java.util.concurrent.Future; +import com.google.api.gax.core.ApiFuture; /** * Interface for asynchronously consuming Google Cloud paginated results. @@ -46,8 +46,8 @@ public interface AsyncPage extends Page { /** - * Returns a {@link Future} object for the next page. {@link Future#get()} returns {@code null} if - * the last page has been reached. + * Returns a {@link ApiFuture} object for the next page. {@link ApiFuture#get()} returns + * {@code null} if the last page has been reached. */ - Future> getNextPageAsync(); + ApiFuture> getNextPageAsync(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index bc4858ecb7..e2d27d75bc 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -16,13 +16,12 @@ package com.google.cloud; +import com.google.api.gax.core.ApiFuture; +import com.google.api.gax.core.ApiFutures; import com.google.common.base.Throwables; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Uninterruptibles; - import java.io.Serializable; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; /** * Base implementation for asynchronously consuming Google Cloud paginated results. @@ -42,7 +41,7 @@ public class AsyncPageImpl extends PageImpl implements AsyncPage { */ public interface NextPageFetcher extends Serializable { - Future> getNextPage(); + ApiFuture> getNextPage(); } private static class SyncNextPageFetcher implements PageImpl.NextPageFetcher { @@ -76,9 +75,9 @@ public AsyncPageImpl(NextPageFetcher asyncPageFetcher, String cursor, Iterabl @Override - public Future> getNextPageAsync() { + public ApiFuture> getNextPageAsync() { if (getNextPageCursor() == null || asyncPageFetcher == null) { - return Futures.immediateCheckedFuture(null); + return ApiFutures.immediateFuture(null); } return asyncPageFetcher.getNextPage(); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java index 1f6298857a..ea1717583d 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java @@ -18,13 +18,13 @@ import static org.junit.Assert.assertEquals; +import com.google.api.gax.core.ApiFuture; +import com.google.api.gax.core.ApiFutures; import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.Futures; import org.junit.Test; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; public class AsyncPageImplTest { @@ -51,8 +51,8 @@ private static class TestPageFetcher implements AsyncPageImpl.NextPageFetcher> getNextPage() { - return Futures.>immediateFuture(nextResult); + public ApiFuture> getNextPage() { + return ApiFutures.>immediateFuture(nextResult); } } From 27e800ef96bb9e152cba7dc820b3092a89a7e3c7 Mon Sep 17 00:00:00 2001 From: Ryan Eiger Date: Thu, 9 Mar 2017 07:12:48 -0800 Subject: [PATCH 297/663] Add project role identities to the Identity helper (#1718) In addition to the standard IAM identities, project membership identities are also supported. For instance, a role can be applied to only the Editors of a project. --- .../main/java/com/google/cloud/Identity.java | 53 ++++++++++++++++++- .../java/com/google/cloud/IdentityTest.java | 39 ++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Identity.java b/google-cloud-core/src/main/java/com/google/cloud/Identity.java index cbf2c6292d..74d55672ef 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Identity.java @@ -78,7 +78,22 @@ public enum Type { /** * Represents all the users of a Google Apps domain name. */ - DOMAIN + DOMAIN, + + /** + * Represents owners of a Google Cloud Platform project. + */ + PROJECT_OWNER, + + /** + * Represents editors of a Google Cloud Platform project. + */ + PROJECT_EDITOR, + + /** + * Represents viewers of a Google Cloud Platform project. + */ + PROJECT_VIEWER } private Identity(Type type, String value) { @@ -161,6 +176,30 @@ public static Identity group(String email) { public static Identity domain(String domain) { return new Identity(Type.DOMAIN, checkNotNull(domain)); } + + /** + * Returns a new project owner identity. + * @param projectId A Google Cloud Platform project ID. For example, my-sample-project. + */ + public static Identity projectOwner(String projectId) { + return new Identity(Type.PROJECT_OWNER, checkNotNull(projectId)); + } + + /** + * Returns a new project editor identity. + * @param projectId A Google Cloud Platform project ID. For example, my-sample-project. + */ + public static Identity projectEditor(String projectId) { + return new Identity(Type.PROJECT_EDITOR, checkNotNull(projectId)); + } + + /** + * Returns a new project viewer identity. + * @param projectId A Google Cloud Platform project ID. For example, my-sample-project. + */ + public static Identity projectViewer(String projectId) { + return new Identity(Type.PROJECT_VIEWER, checkNotNull(projectId)); + } @Override public String toString() { @@ -199,6 +238,12 @@ public String strValue() { return "group:" + value; case DOMAIN: return "domain:" + value; + case PROJECT_OWNER: + return "projectOwner:" + value; + case PROJECT_EDITOR: + return "projectEditor:" + value; + case PROJECT_VIEWER: + return "projectViewer:" + value; default: throw new IllegalStateException("Unexpected identity type: " + type); } @@ -224,6 +269,12 @@ public static Identity valueOf(String identityStr) { return Identity.group(info[1]); case DOMAIN: return Identity.domain(info[1]); + case PROJECT_OWNER: + return Identity.projectOwner(info[1]); + case PROJECT_EDITOR: + return Identity.projectEditor(info[1]); + case PROJECT_VIEWER: + return Identity.projectViewer(info[1]); default: throw new IllegalStateException("Unexpected identity type " + type); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java index b7b244adb9..cf8726a4b6 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java @@ -30,6 +30,9 @@ public class IdentityTest { Identity.serviceAccount("service-account@gmail.com"); private static final Identity GROUP = Identity.group("group@gmail.com"); private static final Identity DOMAIN = Identity.domain("google.com"); + private static final Identity PROJECT_OWNER = Identity.projectOwner("my-sample-project"); + private static final Identity PROJECT_EDITOR = Identity.projectEditor("my-sample-project"); + private static final Identity PROJECT_VIEWER = Identity.projectViewer("my-sample-project"); @Test public void testAllUsers() { @@ -93,6 +96,39 @@ public void testDomainNullId() { Identity.domain(null); } + @Test + public void testProjectOwner() { + assertEquals(Identity.Type.PROJECT_OWNER, PROJECT_OWNER.getType()); + assertEquals("my-sample-project", PROJECT_OWNER.getValue()); + } + + @Test(expected = NullPointerException.class) + public void testProjectOwnerNullId() { + Identity.projectOwner(null); + } + + @Test + public void testProjectEditor() { + assertEquals(Identity.Type.PROJECT_EDITOR, PROJECT_EDITOR.getType()); + assertEquals("my-sample-project", PROJECT_EDITOR.getValue()); + } + + @Test(expected = NullPointerException.class) + public void testProjectEditorNullId() { + Identity.projectEditor(null); + } + + @Test + public void testProjectViewer() { + assertEquals(Identity.Type.PROJECT_VIEWER, PROJECT_VIEWER.getType()); + assertEquals("my-sample-project", PROJECT_VIEWER.getValue()); + } + + @Test(expected = NullPointerException.class) + public void testProjectViewerNullId() { + Identity.projectViewer(null); + } + @Test public void testIdentityToAndFromPb() { compareIdentities(ALL_USERS, Identity.valueOf(ALL_USERS.strValue())); @@ -101,6 +137,9 @@ public void testIdentityToAndFromPb() { compareIdentities(SERVICE_ACCOUNT, Identity.valueOf(SERVICE_ACCOUNT.strValue())); compareIdentities(GROUP, Identity.valueOf(GROUP.strValue())); compareIdentities(DOMAIN, Identity.valueOf(DOMAIN.strValue())); + compareIdentities(PROJECT_OWNER, Identity.valueOf(PROJECT_OWNER.strValue())); + compareIdentities(PROJECT_EDITOR, Identity.valueOf(PROJECT_EDITOR.strValue())); + compareIdentities(PROJECT_VIEWER, Identity.valueOf(PROJECT_VIEWER.strValue())); } private void compareIdentities(Identity expected, Identity actual) { From 660bd166ca9bb07bae68793c9d3df67bec992dde Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Mon, 13 Mar 2017 11:56:14 -0700 Subject: [PATCH 298/663] Make `getProjectId()` supports GAE (#1726) --- .../main/java/com/google/cloud/ServiceOptions.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index d5b155486b..0e6987e93e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -394,8 +394,17 @@ protected static String getAppEngineProjectId() { String serviceAccountName = (String) method.invoke(appIdentityService); int indexOfAtSign = serviceAccountName.indexOf('@'); return serviceAccountName.substring(0, indexOfAtSign); + } catch (ClassNotFoundException exception) { + if (System.getProperty("com.google.appengine.runtime.version") != null) { + // Could not resolve appengine classes under GAE environment. + throw new RuntimeException("Google App Engine runtime detected " + + "(the environment variable \"com.google.appengine.runtime.version\" is set), " + + "but unable to resolve appengine-sdk classes. " + + "For more details see " + + "https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/APPENGINE.md"); + } + return null; } catch (Exception ignore) { - // return null if can't determine return null; } } From 6af126f97ceba9d787310f83a47009db25fa4cb2 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Tue, 14 Mar 2017 18:42:26 -0700 Subject: [PATCH 299/663] Removing transport from ServiceOptions hierarchy (#1723) This allows a client to support multiple transports in the future, e.g. Datastore supports http now but grpc support will be added later. Related changes: * Renaming HttpServiceOptions to HttpTransportOptions * Renaming GrpcServiceOptions to GrpcTransportOptions * Creating new TransportOptions interface --- ...Options.java => GrpcTransportOptions.java} | 113 +++++---- ...Options.java => HttpTransportOptions.java} | 94 ++++---- .../com/google/cloud/ServiceDefaults.java | 29 +++ .../java/com/google/cloud/ServiceOptions.java | 42 ++-- .../com/google/cloud/TransportOptions.java | 25 ++ .../google/cloud/BaseWriteChannelTest.java | 2 +- .../google/cloud/GrpcServiceOptionsTest.java | 218 ------------------ .../cloud/GrpcTransportOptionsTest.java | 117 ++++++++++ .../google/cloud/HttpServiceOptionsTest.java | 163 ------------- .../cloud/HttpTransportOptionsTest.java | 63 +++++ .../com/google/cloud/ServiceOptionsTest.java | 26 ++- 11 files changed, 374 insertions(+), 518 deletions(-) rename google-cloud-core/src/main/java/com/google/cloud/{GrpcServiceOptions.java => GrpcTransportOptions.java} (71%) rename google-cloud-core/src/main/java/com/google/cloud/{HttpServiceOptions.java => HttpTransportOptions.java} (64%) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java delete mode 100644 google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java delete mode 100644 google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java similarity index 71% rename from google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java rename to google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java index 8777ac4783..a960011856 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java @@ -24,16 +24,11 @@ import com.google.api.gax.grpc.InstantiatingChannelProvider; import com.google.api.gax.grpc.UnaryCallSettings; import com.google.auth.Credentials; -import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.net.HostAndPort; - import io.grpc.internal.SharedResourceHolder; import io.grpc.internal.SharedResourceHolder.Resource; - -import org.joda.time.Duration; - import java.io.IOException; import java.io.ObjectInputStream; import java.util.Objects; @@ -41,20 +36,15 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import org.joda.time.Duration; /** - * Abstract class representing service options for those services that use gRPC as the transport + * Class representing service options for those services that use gRPC as the transport * layer. - * - * @param the service subclass - * @param the spi-layer class corresponding to the service - * @param the {@code ServiceOptions} subclass corresponding to the service */ -public abstract class GrpcServiceOptions, ServiceRpcT, - OptionsT extends GrpcServiceOptions> - extends ServiceOptions { +public class GrpcTransportOptions implements TransportOptions { - private static final long serialVersionUID = -3093986242928037007L; + private static final long serialVersionUID = -9049538465533951165L; private final String executorFactoryClassName; private final int initialTimeout; private final double timeoutMultiplier; @@ -124,35 +114,27 @@ public synchronized void release(ScheduledExecutorService executor) { } /** - * Builder for {@code GrpcServiceOptions}. - * - * @param the service subclass - * @param the spi-layer class corresponding to the service - * @param the {@code GrpcServiceOptions} subclass corresponding to the service - * @param the {@code ServiceOptions} builder + * Builder for {@code GrpcTransportOptions}. */ - protected abstract static class Builder, ServiceRpcT, - OptionsT extends GrpcServiceOptions, - B extends Builder> - extends ServiceOptions.Builder { + public static class Builder { private ExecutorFactory executorFactory; private int initialTimeout = 20_000; private double timeoutMultiplier = 1.5; private int maxTimeout = 100_000; - protected Builder() {} + private Builder() {} - protected Builder(GrpcServiceOptions options) { - super(options); + private Builder(GrpcTransportOptions options) { executorFactory = options.executorFactory; initialTimeout = options.initialTimeout; timeoutMultiplier = options.timeoutMultiplier; maxTimeout = options.maxTimeout; } - @Override - protected abstract GrpcServiceOptions build(); + public GrpcTransportOptions build() { + return new GrpcTransportOptions(this); + } /** * Sets the scheduled executor factory. This method can be used to provide an user-defined @@ -160,9 +142,9 @@ protected Builder(GrpcServiceOptions options) { * * @return the builder */ - public B setExecutorFactory(ExecutorFactory executorFactory) { + public Builder setExecutorFactory(ExecutorFactory executorFactory) { this.executorFactory = executorFactory; - return self(); + return this; } /** @@ -172,10 +154,10 @@ public B setExecutorFactory(ExecutorFactory executorFa * @return the builder * @throws IllegalArgumentException if the provided timeout is < 0 */ - public B setInitialTimeout(int initialTimeout) { + public Builder setInitialTimeout(int initialTimeout) { Preconditions.checkArgument(initialTimeout > 0, "Initial timeout must be > 0"); this.initialTimeout = initialTimeout; - return self(); + return this; } /** @@ -185,10 +167,10 @@ public B setInitialTimeout(int initialTimeout) { * @return the builder * @throws IllegalArgumentException if the provided timeout multiplier is < 0 */ - public B setTimeoutMultiplier(double timeoutMultiplier) { + public Builder setTimeoutMultiplier(double timeoutMultiplier) { Preconditions.checkArgument(timeoutMultiplier >= 1.0, "Timeout multiplier must be >= 1"); this.timeoutMultiplier = timeoutMultiplier; - return self(); + return this; } /** @@ -198,20 +180,16 @@ public B setTimeoutMultiplier(double timeoutMultiplier) { * * @return the builder */ - public B setMaxTimeout(int maxTimeout) { + public Builder setMaxTimeout(int maxTimeout) { this.maxTimeout = maxTimeout; - return self(); + return this; } } @SuppressWarnings("unchecked") - protected GrpcServiceOptions( - Class> serviceFactoryClass, - Class> rpcFactoryClass, Builder builder) { - super(serviceFactoryClass, rpcFactoryClass, builder); + private GrpcTransportOptions(Builder builder) { executorFactory = firstNonNull(builder.executorFactory, - getFromServiceLoader(ExecutorFactory.class, DefaultExecutorFactory.INSTANCE)); + ServiceOptions.getFromServiceLoader(ExecutorFactory.class, DefaultExecutorFactory.INSTANCE)); executorFactoryClassName = executorFactory.getClass().getName(); initialTimeout = builder.initialTimeout; timeoutMultiplier = builder.timeoutMultiplier; @@ -221,37 +199,39 @@ protected GrpcServiceOptions( /** * Returns a scheduled executor service provider. */ - protected ExecutorFactory getExecutorFactory() { + public ExecutorFactory getExecutorFactory() { return executorFactory; } /** * Returns a builder for API call settings. */ - protected UnaryCallSettings.Builder getApiCallSettings() { + public UnaryCallSettings.Builder getApiCallSettings(RetryParams retryParams) { // todo(mziccard): specify timeout these settings: // retryParams().retryMaxAttempts(), retryParams().retryMinAttempts() final RetrySettings.Builder builder = RetrySettings.newBuilder() - .setTotalTimeout(Duration.millis(getRetryParams().getTotalRetryPeriodMillis())) + .setTotalTimeout(Duration.millis(retryParams.getTotalRetryPeriodMillis())) .setInitialRpcTimeout(Duration.millis(getInitialTimeout())) .setRpcTimeoutMultiplier(getTimeoutMultiplier()) .setMaxRpcTimeout(Duration.millis(getMaxTimeout())) - .setInitialRetryDelay(Duration.millis(getRetryParams().getInitialRetryDelayMillis())) - .setRetryDelayMultiplier(getRetryParams().getRetryDelayBackoffFactor()) - .setMaxRetryDelay(Duration.millis(getRetryParams().getMaxRetryDelayMillis())); + .setInitialRetryDelay(Duration.millis(retryParams.getInitialRetryDelayMillis())) + .setRetryDelayMultiplier(retryParams.getRetryDelayBackoffFactor()) + .setMaxRetryDelay(Duration.millis(retryParams.getMaxRetryDelayMillis())); return UnaryCallSettings.newBuilder().setRetrySettingsBuilder(builder); } /** * Returns a channel provider. */ - protected ChannelProvider getChannelProvider() { - HostAndPort hostAndPort = HostAndPort.fromString(getHost()); + public static ChannelProvider getChannelProvider( + ServiceOptions serviceOptions) { + HostAndPort hostAndPort = HostAndPort.fromString(serviceOptions.getHost()); InstantiatingChannelProvider.Builder builder = InstantiatingChannelProvider.newBuilder() .setServiceAddress(hostAndPort.getHostText()) .setPort(hostAndPort.getPort()) - .setClientLibHeader(getGoogApiClientLibName(), firstNonNull(getLibraryVersion(), "")); - Credentials scopedCredentials = getScopedCredentials(); + .setClientLibHeader(serviceOptions.getGoogApiClientLibName(), + firstNonNull(serviceOptions.getLibraryVersion(), "")); + Credentials scopedCredentials = serviceOptions.getScopedCredentials(); if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { builder.setCredentialsProvider(FixedCredentialsProvider.create(scopedCredentials)); } @@ -281,15 +261,26 @@ public int getMaxTimeout() { return maxTimeout; } + public Builder toBuilder() { + return new Builder(this); + } + @Override - protected int baseHashCode() { - return Objects.hash(super.baseHashCode(), executorFactoryClassName, initialTimeout, + public int hashCode() { + return Objects.hash(executorFactoryClassName, initialTimeout, timeoutMultiplier, maxTimeout); } - protected boolean baseEquals(GrpcServiceOptions other) { - return super.baseEquals(other) - && Objects.equals(executorFactoryClassName, other.executorFactoryClassName) + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + GrpcTransportOptions other = (GrpcTransportOptions) obj; + return Objects.equals(executorFactoryClassName, other.executorFactoryClassName) && Objects.equals(initialTimeout, other.initialTimeout) && Objects.equals(timeoutMultiplier, other.timeoutMultiplier) && Objects.equals(maxTimeout, other.maxTimeout); @@ -297,6 +288,10 @@ protected boolean baseEquals(GrpcServiceOptions other) { private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException { input.defaultReadObject(); - executorFactory = newInstance(executorFactoryClassName); + executorFactory = ServiceOptions.newInstance(executorFactoryClassName); + } + + public static Builder newBuilder() { + return new Builder(); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java similarity index 64% rename from google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java rename to google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java index 63ac94c114..60ff8f719c 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java @@ -26,25 +26,17 @@ import com.google.auth.Credentials; import com.google.auth.http.HttpCredentialsAdapter; import com.google.auth.http.HttpTransportFactory; -import com.google.cloud.spi.ServiceRpcFactory; - import java.io.IOException; import java.io.ObjectInputStream; import java.util.Objects; /** - * Abstract class representing service options for those services that use HTTP as the transport + * Class representing service options for those services that use HTTP as the transport * layer. - * - * @param the service subclass - * @param the spi-layer class corresponding to the service - * @param the {@code ServiceOptions} subclass corresponding to the service */ -public abstract class HttpServiceOptions, ServiceRpcT, - OptionsT extends HttpServiceOptions> - extends ServiceOptions { +public class HttpTransportOptions implements TransportOptions { - private static final long serialVersionUID = 4765436436821178975L; + private static final long serialVersionUID = 7890117765045419810L; private final int connectTimeout; private final int readTimeout; private final String httpTransportFactoryClassName; @@ -58,7 +50,7 @@ public static class DefaultHttpTransportFactory implements HttpTransportFactory @Override public HttpTransport create() { // Consider App Engine - if (getAppEngineAppId() != null) { + if (ServiceOptions.getAppEngineAppId() != null) { try { return new UrlFetchTransport(); } catch (Exception ignore) { @@ -70,38 +62,24 @@ public HttpTransport create() { } /** - * Builder for {@code HttpServiceOptions}. - * - * @param the service subclass - * @param the spi-layer class corresponding to the service - * @param the {@code HttpServiceOptions} subclass corresponding to the service - * @param the {@code ServiceOptions} builder + * Builder for {@code HttpTransportOptions}. */ - protected abstract static class Builder, ServiceRpcT, - OptionsT extends HttpServiceOptions, - B extends Builder> - extends ServiceOptions.Builder { + public static class Builder { private HttpTransportFactory httpTransportFactory; private int connectTimeout = -1; private int readTimeout = -1; - protected Builder() {} + private Builder() {} - protected Builder(HttpServiceOptions options) { - super(options); + private Builder(HttpTransportOptions options) { httpTransportFactory = options.httpTransportFactory; connectTimeout = options.connectTimeout; readTimeout = options.readTimeout; } - @Override - protected abstract HttpServiceOptions build(); - - @Override - @SuppressWarnings("unchecked") - protected B self() { - return (B) this; + public HttpTransportOptions build() { + return new HttpTransportOptions(this); } /** @@ -109,9 +87,9 @@ protected B self() { * * @return the builder */ - public B setHttpTransportFactory(HttpTransportFactory httpTransportFactory) { + public Builder setHttpTransportFactory(HttpTransportFactory httpTransportFactory) { this.httpTransportFactory = httpTransportFactory; - return self(); + return this; } /** @@ -121,9 +99,9 @@ public B setHttpTransportFactory(HttpTransportFactory httpTransportFactory) { * negative number for the default value (20000). * @return the builder */ - public B setConnectTimeout(int connectTimeout) { + public Builder setConnectTimeout(int connectTimeout) { this.connectTimeout = connectTimeout; - return self(); + return this; } /** @@ -133,19 +111,16 @@ public B setConnectTimeout(int connectTimeout) { * for the default value (20000). * @return the builder */ - public B setReadTimeout(int readTimeout) { + public Builder setReadTimeout(int readTimeout) { this.readTimeout = readTimeout; - return self(); + return this; } } - protected HttpServiceOptions( - Class> serviceFactoryClass, - Class> rpcFactoryClass, Builder builder) { - super(serviceFactoryClass, rpcFactoryClass, builder); + protected HttpTransportOptions(Builder builder) { httpTransportFactory = firstNonNull(builder.httpTransportFactory, - getFromServiceLoader(HttpTransportFactory.class, DefaultHttpTransportFactory.INSTANCE)); + ServiceOptions.getFromServiceLoader(HttpTransportFactory.class, + DefaultHttpTransportFactory.INSTANCE)); httpTransportFactoryClassName = httpTransportFactory.getClass().getName(); connectTimeout = builder.connectTimeout; readTimeout = builder.readTimeout; @@ -162,8 +137,8 @@ public HttpTransportFactory getHttpTransportFactory() { * Returns a request initializer responsible for initializing requests according to service * options. */ - public HttpRequestInitializer getHttpRequestInitializer() { - Credentials scopedCredentials = getScopedCredentials(); + public HttpRequestInitializer getHttpRequestInitializer(ServiceOptions serviceOptions) { + Credentials scopedCredentials = serviceOptions.getScopedCredentials(); final HttpRequestInitializer delegate = scopedCredentials != null && scopedCredentials != NoCredentials.getInstance() ? new HttpCredentialsAdapter(scopedCredentials) : null; @@ -199,21 +174,36 @@ public int getReadTimeout() { return readTimeout; } + public Builder toBuilder() { + return new Builder(this); + } + @Override - protected int baseHashCode() { - return Objects.hash(super.baseHashCode(), httpTransportFactoryClassName, connectTimeout, + public int hashCode() { + return Objects.hash(httpTransportFactoryClassName, connectTimeout, readTimeout); } - protected boolean baseEquals(HttpServiceOptions other) { - return super.baseEquals(other) - && Objects.equals(httpTransportFactoryClassName, other.httpTransportFactoryClassName) + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + HttpTransportOptions other = (HttpTransportOptions) obj; + return Objects.equals(httpTransportFactoryClassName, other.httpTransportFactoryClassName) && Objects.equals(connectTimeout, other.connectTimeout) && Objects.equals(readTimeout, other.readTimeout); } private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException { input.defaultReadObject(); - httpTransportFactory = newInstance(httpTransportFactoryClassName); + httpTransportFactory = ServiceOptions.newInstance(httpTransportFactoryClassName); + } + + public static Builder newBuilder() { + return new Builder(); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java new file mode 100644 index 0000000000..20e9d86f61 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java @@ -0,0 +1,29 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.cloud.spi.ServiceRpcFactory; +import java.io.Serializable; + +public interface ServiceDefaults, ServiceRpcT, + OptionsT extends ServiceOptions> extends Serializable { + ServiceFactory getDefaultServiceFactory(); + + ServiceRpcFactory getDefaultRpcFactory(); + + TransportOptions getDefaultTransportOptions(); +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 0e6987e93e..a4210584e2 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -90,6 +90,7 @@ public abstract class ServiceOptions, Service private final String serviceFactoryClassName; private final Clock clock; private final Credentials credentials; + private final TransportOptions transportOptions; private transient ServiceRpcFactory serviceRpcFactory; private transient ServiceFactory serviceFactory; @@ -115,6 +116,7 @@ public abstract static class Builder, Service private ServiceFactory serviceFactory; private ServiceRpcFactory serviceRpcFactory; private Clock clock; + private TransportOptions transportOptions; protected Builder() {} @@ -126,6 +128,7 @@ protected Builder(ServiceOptions options) { serviceFactory = options.serviceFactory; serviceRpcFactory = options.serviceRpcFactory; clock = options.clock; + transportOptions = options.transportOptions; } protected abstract ServiceOptions build(); @@ -219,11 +222,22 @@ public B setServiceRpcFactory(ServiceRpcFactory serviceRp this.serviceRpcFactory = serviceRpcFactory; return self(); } + + /** + * Sets the transport options. + * + * @return the builder + */ + public B setTransportOptions(TransportOptions transportOptions) { + this.transportOptions = transportOptions; + return self(); + } } protected ServiceOptions(Class> serviceFactoryClass, Class> rpcFactoryClass, - Builder builder) { + Builder builder, + ServiceDefaults serviceDefaults) { projectId = builder.projectId != null ? builder.projectId : getDefaultProject(); if (projectIdRequired()) { checkArgument( @@ -235,12 +249,14 @@ protected ServiceOptions(Class> ser credentials = builder.credentials != null ? builder.credentials : defaultCredentials(); retryParams = firstNonNull(builder.retryParams, defaultRetryParams()); serviceFactory = firstNonNull(builder.serviceFactory, - getFromServiceLoader(serviceFactoryClass, getDefaultServiceFactory())); + getFromServiceLoader(serviceFactoryClass, serviceDefaults.getDefaultServiceFactory())); serviceFactoryClassName = serviceFactory.getClass().getName(); serviceRpcFactory = firstNonNull(builder.serviceRpcFactory, - getFromServiceLoader(rpcFactoryClass, getDefaultRpcFactory())); + getFromServiceLoader(rpcFactoryClass, serviceDefaults.getDefaultRpcFactory())); serviceRpcFactoryClassName = serviceRpcFactory.getClass().getName(); clock = firstNonNull(builder.clock, Clock.defaultClock()); + transportOptions = firstNonNull(builder.transportOptions, + serviceDefaults.getDefaultTransportOptions()); } /** @@ -495,6 +511,12 @@ public Clock getClock() { return clock; } + /** + * Returns the transport-specific options for this service. + */ + public TransportOptions getTransportOptions() { + return transportOptions; + } /** * Returns the application's name as a string in the format {@code gcloud-java/[version]}. @@ -518,13 +540,6 @@ public String getGoogApiClientLibName() { return X_GOOGLE_CLIENT_HEADER_NAME; } - /** - * Returns the library's version as a string. - */ - public String libraryVersion() { - return getLibraryVersion(); - } - /** * Returns the library's version as a string. */ @@ -562,13 +577,6 @@ static T newInstance(String className) throws IOException, ClassNotFoundExce } } - - protected abstract ServiceFactory getDefaultServiceFactory(); - - - protected abstract ServiceRpcFactory getDefaultRpcFactory(); - - protected abstract Set getScopes(); public abstract > B toBuilder(); diff --git a/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java new file mode 100644 index 0000000000..6048db0515 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud; + +import java.io.Serializable; + +/** + * An abstraction for transport-specific options, e.g. for http1.1 vs grpc. + */ +public interface TransportOptions extends Serializable { + +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java index a5c278a832..b13a8087aa 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java @@ -48,7 +48,7 @@ protected CustomServiceOptions( Class> serviceFactoryClass, Class> rpcFactoryClass, Builder builder) { - super(serviceFactoryClass, rpcFactoryClass, builder); + super(serviceFactoryClass, rpcFactoryClass, builder, null); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java deleted file mode 100644 index a5c7cebfc4..0000000000 --- a/google-cloud-core/src/test/java/com/google/cloud/GrpcServiceOptionsTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.google.cloud.GrpcServiceOptions.DefaultExecutorFactory; -import com.google.cloud.GrpcServiceOptions.ExecutorFactory; -import com.google.cloud.spi.ServiceRpcFactory; - -import org.easymock.EasyMock; -import org.junit.Test; - -import java.util.Set; -import java.util.concurrent.ScheduledExecutorService; - -public class GrpcServiceOptionsTest { - - private static final ExecutorFactory MOCK_EXECUTOR_FACTORY = - EasyMock.createMock(ExecutorFactory.class); - private static final TestGrpcServiceOptions OPTIONS = TestGrpcServiceOptions.newBuilder() - .setProjectId("project-id") - .setInitialTimeout(1234) - .setTimeoutMultiplier(1.6) - .setMaxTimeout(5678) - .setExecutorFactory(MOCK_EXECUTOR_FACTORY) - .build(); - private static final TestGrpcServiceOptions DEFAULT_OPTIONS = - TestGrpcServiceOptions.newBuilder().setProjectId("project-id").build(); - private static final TestGrpcServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); - - private interface TestService extends Service {} - - private static class TestServiceImpl - extends BaseService implements TestService { - private TestServiceImpl(TestGrpcServiceOptions options) { - super(options); - } - } - - private interface TestServiceFactory extends ServiceFactory { - } - - private static class DefaultTestServiceFactory implements TestServiceFactory { - private static final TestServiceFactory INSTANCE = new DefaultTestServiceFactory(); - - @Override - public TestService create(TestGrpcServiceOptions options) { - return new TestServiceImpl(options); - } - } - - private interface TestServiceRpcFactory - extends ServiceRpcFactory {} - - private static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory { - private static final TestServiceRpcFactory INSTANCE = new DefaultTestServiceRpcFactory(); - - @Override - public TestServiceRpc create(TestGrpcServiceOptions options) { - return new DefaultTestServiceRpc(options); - } - } - - private interface TestServiceRpc {} - - private static class DefaultTestServiceRpc implements TestServiceRpc { - DefaultTestServiceRpc(TestGrpcServiceOptions options) {} - } - - private static class TestGrpcServiceOptions - extends GrpcServiceOptions { - private static class Builder - extends GrpcServiceOptions.Builder { - private Builder() {} - - private Builder(TestGrpcServiceOptions options) { - super(options); - } - - @Override - protected TestGrpcServiceOptions build() { - return new TestGrpcServiceOptions(this); - } - } - - private TestGrpcServiceOptions(Builder builder) { - super(TestServiceFactory.class, TestServiceRpcFactory.class, builder); - } - - @Override - protected TestServiceFactory getDefaultServiceFactory() { - return DefaultTestServiceFactory.INSTANCE; - } - - @Override - protected TestServiceRpcFactory getDefaultRpcFactory() { - return DefaultTestServiceRpcFactory.INSTANCE; - } - - @Override - protected Set getScopes() { - return null; - } - - @Override - public Builder toBuilder() { - return new Builder(this); - } - - private static Builder newBuilder() { - return new Builder(); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof TestGrpcServiceOptions && baseEquals((TestGrpcServiceOptions) obj); - } - - @Override - public int hashCode() { - return baseHashCode(); - } - } - - @Test - public void testBuilder() { - assertEquals(1234, OPTIONS.getInitialTimeout()); - assertEquals(1.6, OPTIONS.getTimeoutMultiplier(), 0.0); - assertEquals(5678, OPTIONS.getMaxTimeout()); - assertSame(MOCK_EXECUTOR_FACTORY, OPTIONS.getExecutorFactory()); - assertEquals(20000, DEFAULT_OPTIONS.getInitialTimeout()); - assertEquals(1.5, DEFAULT_OPTIONS.getTimeoutMultiplier(), 0.0); - assertEquals(100000, DEFAULT_OPTIONS.getMaxTimeout()); - assertTrue(DEFAULT_OPTIONS.getExecutorFactory() instanceof DefaultExecutorFactory); - } - - @Test - public void testBuilderError() { - try { - TestGrpcServiceOptions.newBuilder().setInitialTimeout(0); - fail("IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - assertEquals("Initial timeout must be > 0", ex.getMessage()); - } - try { - TestGrpcServiceOptions.newBuilder().setInitialTimeout(-1); - fail("IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - assertEquals("Initial timeout must be > 0", ex.getMessage()); - } - try { - TestGrpcServiceOptions.newBuilder().setTimeoutMultiplier(0.9); - fail("IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - assertEquals("Timeout multiplier must be >= 1", ex.getMessage()); - } - } - - @Test - public void testBuilderInvalidMaxTimeout() { - TestGrpcServiceOptions options = TestGrpcServiceOptions.newBuilder() - .setProjectId("project-id") - .setInitialTimeout(1234) - .setTimeoutMultiplier(1.6) - .setMaxTimeout(123) - .build(); - assertEquals(1234, options.getInitialTimeout()); - assertEquals(1.6, options.getTimeoutMultiplier(), 0.0); - assertEquals(1234, options.getMaxTimeout()); - } - - @Test - public void testBaseEquals() { - assertEquals(OPTIONS, OPTIONS_COPY); - assertNotEquals(DEFAULT_OPTIONS, OPTIONS); - TestGrpcServiceOptions options = OPTIONS.toBuilder() - .setExecutorFactory(new DefaultExecutorFactory()) - .build(); - assertNotEquals(OPTIONS, options); - } - - @Test - public void testBaseHashCode() { - assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); - assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); - TestGrpcServiceOptions options = OPTIONS.toBuilder() - .setExecutorFactory(new DefaultExecutorFactory()) - .build(); - assertNotEquals(OPTIONS.hashCode(), options.hashCode()); - } - - @Test - public void testDefaultExecutorFactory() { - ExecutorFactory executorFactory = new DefaultExecutorFactory(); - ScheduledExecutorService executorService = executorFactory.get(); - assertSame(executorService, executorFactory.get()); - } -} diff --git a/google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java new file mode 100644 index 0000000000..aafd264611 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java @@ -0,0 +1,117 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.google.cloud.GrpcTransportOptions.DefaultExecutorFactory; +import com.google.cloud.GrpcTransportOptions.ExecutorFactory; +import java.util.concurrent.ScheduledExecutorService; +import org.easymock.EasyMock; +import org.junit.Test; + +public class GrpcTransportOptionsTest { + + private static final ExecutorFactory MOCK_EXECUTOR_FACTORY = + EasyMock.createMock(ExecutorFactory.class); + private static final GrpcTransportOptions OPTIONS = GrpcTransportOptions.newBuilder() + .setInitialTimeout(1234) + .setTimeoutMultiplier(1.6) + .setMaxTimeout(5678) + .setExecutorFactory(MOCK_EXECUTOR_FACTORY) + .build(); + private static final GrpcTransportOptions DEFAULT_OPTIONS = + GrpcTransportOptions.newBuilder().build(); + private static final GrpcTransportOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); + + @Test + public void testBuilder() { + assertEquals(1234, OPTIONS.getInitialTimeout()); + assertEquals(1.6, OPTIONS.getTimeoutMultiplier(), 0.0); + assertEquals(5678, OPTIONS.getMaxTimeout()); + assertSame(MOCK_EXECUTOR_FACTORY, OPTIONS.getExecutorFactory()); + assertEquals(20000, DEFAULT_OPTIONS.getInitialTimeout()); + assertEquals(1.5, DEFAULT_OPTIONS.getTimeoutMultiplier(), 0.0); + assertEquals(100000, DEFAULT_OPTIONS.getMaxTimeout()); + assertTrue(DEFAULT_OPTIONS.getExecutorFactory() instanceof DefaultExecutorFactory); + } + + @Test + public void testBuilderError() { + try { + GrpcTransportOptions.newBuilder().setInitialTimeout(0); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException ex) { + assertEquals("Initial timeout must be > 0", ex.getMessage()); + } + try { + GrpcTransportOptions.newBuilder().setInitialTimeout(-1); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException ex) { + assertEquals("Initial timeout must be > 0", ex.getMessage()); + } + try { + GrpcTransportOptions.newBuilder().setTimeoutMultiplier(0.9); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException ex) { + assertEquals("Timeout multiplier must be >= 1", ex.getMessage()); + } + } + + @Test + public void testBuilderInvalidMaxTimeout() { + GrpcTransportOptions options = GrpcTransportOptions.newBuilder() + .setInitialTimeout(1234) + .setTimeoutMultiplier(1.6) + .setMaxTimeout(123) + .build(); + assertEquals(1234, options.getInitialTimeout()); + assertEquals(1.6, options.getTimeoutMultiplier(), 0.0); + assertEquals(1234, options.getMaxTimeout()); + } + + @Test + public void testBaseEquals() { + assertEquals(OPTIONS, OPTIONS_COPY); + assertNotEquals(DEFAULT_OPTIONS, OPTIONS); + GrpcTransportOptions options = OPTIONS.toBuilder() + .setExecutorFactory(new DefaultExecutorFactory()) + .build(); + assertNotEquals(OPTIONS, options); + } + + @Test + public void testBaseHashCode() { + assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); + assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); + GrpcTransportOptions options = OPTIONS.toBuilder() + .setExecutorFactory(new DefaultExecutorFactory()) + .build(); + assertNotEquals(OPTIONS.hashCode(), options.hashCode()); + } + + @Test + public void testDefaultExecutorFactory() { + ExecutorFactory executorFactory = new DefaultExecutorFactory(); + ScheduledExecutorService executorService = executorFactory.get(); + assertSame(executorService, executorFactory.get()); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java deleted file mode 100644 index 81e330236c..0000000000 --- a/google-cloud-core/src/test/java/com/google/cloud/HttpServiceOptionsTest.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import com.google.auth.http.HttpTransportFactory; -import com.google.cloud.HttpServiceOptions.DefaultHttpTransportFactory; -import com.google.cloud.spi.ServiceRpcFactory; - -import org.easymock.EasyMock; -import org.junit.Test; - -import java.util.Set; - -public class HttpServiceOptionsTest { - - private static final HttpTransportFactory MOCK_HTTP_TRANSPORT_FACTORY = - EasyMock.createMock(HttpTransportFactory.class); - private static final TestHttpServiceOptions OPTIONS = TestHttpServiceOptions.newBuilder() - .setProjectId("project-id") - .setConnectTimeout(1234) - .setHttpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) - .setReadTimeout(5678) - .build(); - private static final TestHttpServiceOptions DEFAULT_OPTIONS = - TestHttpServiceOptions.newBuilder().setProjectId("project-id").build(); - private static final TestHttpServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); - - private interface TestService extends Service {} - - private static class TestServiceImpl - extends BaseService implements TestService { - private TestServiceImpl(TestHttpServiceOptions options) { - super(options); - } - } - - private interface TestServiceFactory extends ServiceFactory { - } - - private static class DefaultTestServiceFactory implements TestServiceFactory { - private static final TestServiceFactory INSTANCE = new DefaultTestServiceFactory(); - - @Override - public TestService create(TestHttpServiceOptions options) { - return new TestServiceImpl(options); - } - } - - private interface TestServiceRpcFactory - extends ServiceRpcFactory {} - - private static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory { - private static final TestServiceRpcFactory INSTANCE = new DefaultTestServiceRpcFactory(); - - @Override - public TestServiceRpc create(TestHttpServiceOptions options) { - return new DefaultTestServiceRpc(options); - } - } - - private interface TestServiceRpc {} - - private static class DefaultTestServiceRpc implements TestServiceRpc { - DefaultTestServiceRpc(TestHttpServiceOptions options) {} - } - - private static class TestHttpServiceOptions - extends HttpServiceOptions { - private static class Builder - extends HttpServiceOptions.Builder { - private Builder() {} - - private Builder(TestHttpServiceOptions options) { - super(options); - } - - @Override - protected TestHttpServiceOptions build() { - return new TestHttpServiceOptions(this); - } - } - - private TestHttpServiceOptions(Builder builder) { - super(TestServiceFactory.class, TestServiceRpcFactory.class, builder); - } - - @Override - protected TestServiceFactory getDefaultServiceFactory() { - return DefaultTestServiceFactory.INSTANCE; - } - - @Override - protected TestServiceRpcFactory getDefaultRpcFactory() { - return DefaultTestServiceRpcFactory.INSTANCE; - } - - @Override - protected Set getScopes() { - return null; - } - - @Override - public Builder toBuilder() { - return new Builder(this); - } - - private static Builder newBuilder() { - return new Builder(); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof TestHttpServiceOptions && baseEquals((TestHttpServiceOptions) obj); - } - - @Override - public int hashCode() { - return baseHashCode(); - } - } - - @Test - public void testBuilder() { - assertEquals(1234, OPTIONS.getConnectTimeout()); - assertSame(MOCK_HTTP_TRANSPORT_FACTORY, OPTIONS.getHttpTransportFactory()); - assertEquals(5678, OPTIONS.getReadTimeout()); - assertEquals(-1, DEFAULT_OPTIONS.getConnectTimeout()); - assertTrue(DEFAULT_OPTIONS.getHttpTransportFactory() instanceof DefaultHttpTransportFactory); - assertEquals(-1, DEFAULT_OPTIONS.getReadTimeout()); - } - - @Test - public void testBaseEquals() { - assertEquals(OPTIONS, OPTIONS_COPY); - assertNotEquals(DEFAULT_OPTIONS, OPTIONS); - } - - @Test - public void testBaseHashCode() { - assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); - assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); - } -} diff --git a/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java new file mode 100644 index 0000000000..f5013181b2 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import com.google.auth.http.HttpTransportFactory; +import com.google.cloud.HttpTransportOptions.DefaultHttpTransportFactory; +import org.easymock.EasyMock; +import org.junit.Test; + +public class HttpTransportOptionsTest { + + private static final HttpTransportFactory MOCK_HTTP_TRANSPORT_FACTORY = + EasyMock.createMock(HttpTransportFactory.class); + private static final HttpTransportOptions OPTIONS = HttpTransportOptions.newBuilder() + .setConnectTimeout(1234) + .setHttpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) + .setReadTimeout(5678) + .build(); + private static final HttpTransportOptions DEFAULT_OPTIONS = + HttpTransportOptions.newBuilder().build(); + private static final HttpTransportOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); + + @Test + public void testBuilder() { + assertEquals(1234, OPTIONS.getConnectTimeout()); + assertSame(MOCK_HTTP_TRANSPORT_FACTORY, OPTIONS.getHttpTransportFactory()); + assertEquals(5678, OPTIONS.getReadTimeout()); + assertEquals(-1, DEFAULT_OPTIONS.getConnectTimeout()); + assertTrue(DEFAULT_OPTIONS.getHttpTransportFactory() instanceof DefaultHttpTransportFactory); + assertEquals(-1, DEFAULT_OPTIONS.getReadTimeout()); + } + + @Test + public void testBaseEquals() { + assertEquals(OPTIONS, OPTIONS_COPY); + assertNotEquals(DEFAULT_OPTIONS, OPTIONS); + } + + @Test + public void testBaseHashCode() { + assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); + assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index e08b5c35ce..6474b6389b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -161,17 +161,27 @@ protected TestServiceOptions build() { } private TestServiceOptions(Builder builder) { - super(TestServiceFactory.class, TestServiceRpcFactory.class, builder); + super(TestServiceFactory.class, TestServiceRpcFactory.class, builder, + new TestServiceDefaults()); } - @Override - protected TestServiceFactory getDefaultServiceFactory() { - return DefaultTestServiceFactory.INSTANCE; - } + private static class TestServiceDefaults implements + ServiceDefaults { - @Override - protected TestServiceRpcFactory getDefaultRpcFactory() { - return DefaultTestServiceRpcFactory.INSTANCE; + @Override + public TestServiceFactory getDefaultServiceFactory() { + return DefaultTestServiceFactory.INSTANCE; + } + + @Override + public TestServiceRpcFactory getDefaultRpcFactory() { + return DefaultTestServiceRpcFactory.INSTANCE; + } + + @Override + public TransportOptions getDefaultTransportOptions() { + return HttpTransportOptions.newBuilder().build(); + } } @Override From 0530524669611db2325ce669cfbc4a94a2f18372 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 16 Mar 2017 16:58:39 -0700 Subject: [PATCH 300/663] Release 0.10.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 0bc251fee7..fea1e6cbfd 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.9.5-alpha-SNAPSHOT + 0.10.0-alpha google-cloud-core From 85f8fcbfab007e422127593a66259a6c5b74de96 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 16 Mar 2017 17:02:04 -0700 Subject: [PATCH 301/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 6612e5c8ed..c7cfe230a4 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.9.4-alpha + 0.10.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.9.4-alpha' +compile 'com.google.cloud:google-cloud-core:0.10.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.9.4-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.10.0-alpha" ``` Troubleshooting From cf40a87590df2bf555f48e1d94f7313624b4123a Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Fri, 17 Mar 2017 08:54:37 -0700 Subject: [PATCH 302/663] Update version to 0.10.1-SNAPSHOT (#1765) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index fea1e6cbfd..077921cf2d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.10.0-alpha + 0.10.1-alpha-SNAPSHOT google-cloud-core From 21db8198cb02ce161cb885c450b2fea21f0bcf76 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Fri, 17 Mar 2017 09:04:50 -0700 Subject: [PATCH 303/663] Removing ServiceRpcT parameterization (#1759) Also: * Moving spi/*Rpc classes to spi/{MAJOR_VERSION}/*Rpc * Renaming DefaultRpc classes to HttpRpc/Grpc*Rpc as appropriate --- .../java/com/google/cloud/BaseService.java | 2 +- .../com/google/cloud/BaseWriteChannel.java | 6 ++-- .../google/cloud/GrpcTransportOptions.java | 2 +- .../google/cloud/HttpTransportOptions.java | 2 +- .../main/java/com/google/cloud/Service.java | 2 +- .../com/google/cloud/ServiceDefaults.java | 6 ++-- .../java/com/google/cloud/ServiceOptions.java | 36 +++++++++---------- .../java/com/google/cloud/ServiceRpc.java | 21 +++++++++++ .../google/cloud/spi/ServiceRpcFactory.java | 5 +-- .../google/cloud/BaseWriteChannelTest.java | 6 ++-- .../com/google/cloud/ServiceOptionsTest.java | 10 +++--- 11 files changed, 59 insertions(+), 39 deletions(-) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java index dcfb097a07..619341bc37 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java @@ -23,7 +23,7 @@ * * @param the {@code ServiceOptions} subclass corresponding to the service */ -public abstract class BaseService> +public abstract class BaseService> implements Service { public static final Interceptor EXCEPTION_HANDLER_INTERCEPTOR = new Interceptor() { diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index 86105d469d..ddc191b1e4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -32,7 +32,7 @@ * @param the entity this channel writes data to. Possibly with additional configuration */ public abstract class BaseWriteChannel< - ServiceOptionsT extends ServiceOptions, + ServiceOptionsT extends ServiceOptions, EntityT extends Serializable> implements WriteChannel { private static final int MIN_CHUNK_SIZE = 256 * 1024; @@ -196,7 +196,7 @@ protected void restore(BaseState state) { } protected abstract static class BaseState< - ServiceOptionsT extends ServiceOptions, EntityT extends Serializable> + ServiceOptionsT extends ServiceOptions, EntityT extends Serializable> implements RestorableState, Serializable { private static final long serialVersionUID = 8541062465055125619L; @@ -228,7 +228,7 @@ protected BaseState(Builder builder) { * configuration */ public abstract static class Builder< - ServiceOptionsT extends ServiceOptions, + ServiceOptionsT extends ServiceOptions, EntityT extends Serializable> { private final ServiceOptionsT serviceOptions; private final EntityT entity; diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java index a960011856..be31c98747 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java @@ -224,7 +224,7 @@ public UnaryCallSettings.Builder getApiCallSettings(RetryParams retryParams) { * Returns a channel provider. */ public static ChannelProvider getChannelProvider( - ServiceOptions serviceOptions) { + ServiceOptions serviceOptions) { HostAndPort hostAndPort = HostAndPort.fromString(serviceOptions.getHost()); InstantiatingChannelProvider.Builder builder = InstantiatingChannelProvider.newBuilder() .setServiceAddress(hostAndPort.getHostText()) diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java index 60ff8f719c..1ef0276faf 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java @@ -137,7 +137,7 @@ public HttpTransportFactory getHttpTransportFactory() { * Returns a request initializer responsible for initializing requests according to service * options. */ - public HttpRequestInitializer getHttpRequestInitializer(ServiceOptions serviceOptions) { + public HttpRequestInitializer getHttpRequestInitializer(ServiceOptions serviceOptions) { Credentials scopedCredentials = serviceOptions.getScopedCredentials(); final HttpRequestInitializer delegate = scopedCredentials != null && scopedCredentials != NoCredentials.getInstance() diff --git a/google-cloud-core/src/main/java/com/google/cloud/Service.java b/google-cloud-core/src/main/java/com/google/cloud/Service.java index 3c3c87bd76..44a9f5372d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Service.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Service.java @@ -21,7 +21,7 @@ * * @param the {@code ServiceOptions} subclass corresponding to the service */ -public interface Service> { +public interface Service> { OptionsT getOptions(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java index 20e9d86f61..6918545774 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java @@ -19,11 +19,11 @@ import com.google.cloud.spi.ServiceRpcFactory; import java.io.Serializable; -public interface ServiceDefaults, ServiceRpcT, - OptionsT extends ServiceOptions> extends Serializable { +public interface ServiceDefaults, + OptionsT extends ServiceOptions> extends Serializable { ServiceFactory getDefaultServiceFactory(); - ServiceRpcFactory getDefaultRpcFactory(); + ServiceRpcFactory getDefaultRpcFactory(); TransportOptions getDefaultTransportOptions(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index a4210584e2..39e6c2ac2d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -61,11 +61,10 @@ * Abstract class representing service options. * * @param the service subclass - * @param the spi-layer class corresponding to the service * @param the {@code ServiceOptions} subclass corresponding to the service */ -public abstract class ServiceOptions, ServiceRpcT, - OptionsT extends ServiceOptions> implements Serializable { +public abstract class ServiceOptions, + OptionsT extends ServiceOptions> implements Serializable { private static final String DEFAULT_HOST = "https://www.googleapis.com"; private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; @@ -92,35 +91,34 @@ public abstract class ServiceOptions, Service private final Credentials credentials; private final TransportOptions transportOptions; - private transient ServiceRpcFactory serviceRpcFactory; + private transient ServiceRpcFactory serviceRpcFactory; private transient ServiceFactory serviceFactory; private transient ServiceT service; - private transient ServiceRpcT rpc; + private transient ServiceRpc rpc; /** * Builder for {@code ServiceOptions}. * * @param the service subclass - * @param the spi-layer class corresponding to the service * @param the {@code ServiceOptions} subclass corresponding to the service * @param the {@code ServiceOptions} builder */ - public abstract static class Builder, ServiceRpcT, - OptionsT extends ServiceOptions, - B extends Builder> { + public abstract static class Builder, + OptionsT extends ServiceOptions, + B extends Builder> { private String projectId; private String host; private Credentials credentials; private RetryParams retryParams; private ServiceFactory serviceFactory; - private ServiceRpcFactory serviceRpcFactory; + private ServiceRpcFactory serviceRpcFactory; private Clock clock; private TransportOptions transportOptions; protected Builder() {} - protected Builder(ServiceOptions options) { + protected Builder(ServiceOptions options) { projectId = options.projectId; host = options.host; credentials = options.credentials; @@ -131,7 +129,7 @@ protected Builder(ServiceOptions options) { transportOptions = options.transportOptions; } - protected abstract ServiceOptions build(); + protected abstract ServiceOptions build(); @SuppressWarnings("unchecked") protected B self() { @@ -218,7 +216,7 @@ public B setRetryParams(RetryParams retryParams) { * * @return the builder */ - public B setServiceRpcFactory(ServiceRpcFactory serviceRpcFactory) { + public B setServiceRpcFactory(ServiceRpcFactory serviceRpcFactory) { this.serviceRpcFactory = serviceRpcFactory; return self(); } @@ -235,9 +233,9 @@ public B setTransportOptions(TransportOptions transportOptions) { } protected ServiceOptions(Class> serviceFactoryClass, - Class> rpcFactoryClass, - Builder builder, - ServiceDefaults serviceDefaults) { + Class> rpcFactoryClass, + Builder builder, + ServiceDefaults serviceDefaults) { projectId = builder.projectId != null ? builder.projectId : getDefaultProject(); if (projectIdRequired()) { checkArgument( @@ -450,7 +448,7 @@ public ServiceT getService() { @SuppressWarnings("unchecked") - public ServiceRpcT getRpc() { + public ServiceRpc getRpc() { if (rpc == null) { rpc = serviceRpcFactory.create((OptionsT) this); } @@ -552,7 +550,7 @@ protected int baseHashCode() { serviceRpcFactoryClassName, clock); } - protected boolean baseEquals(ServiceOptions other) { + protected boolean baseEquals(ServiceOptions other) { return Objects.equals(projectId, other.projectId) && Objects.equals(host, other.host) && Objects.equals(credentials, other.credentials) @@ -579,7 +577,7 @@ static T newInstance(String className) throws IOException, ClassNotFoundExce protected abstract Set getScopes(); - public abstract > B toBuilder(); + public abstract > B toBuilder(); /** * Some services may have different backoff requirements listed in their SLAs. Be sure to override diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java new file mode 100644 index 0000000000..554e33271a --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java @@ -0,0 +1,21 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +public interface ServiceRpc { + +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java b/google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java index 21a061f4a5..4dcf540253 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java +++ b/google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java @@ -17,13 +17,14 @@ package com.google.cloud.spi; import com.google.cloud.ServiceOptions; +import com.google.cloud.ServiceRpc; /** * A base interface for all service RPC factories. Implementation must provide a public no-arg * constructor. Loading of a factory implementation is done via {@link java.util.ServiceLoader}. */ @SuppressWarnings("rawtypes") -public interface ServiceRpcFactory { +public interface ServiceRpcFactory { - ServiceRpcT create(OptionsT options); + ServiceRpc create(OptionsT options); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java index b13a8087aa..1baae9a7e7 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java @@ -40,14 +40,14 @@ public class BaseWriteChannelTest { private abstract static class CustomService implements Service {} private abstract static class CustomServiceOptions - extends ServiceOptions { + extends ServiceOptions { private static final long serialVersionUID = 3302358029307467197L; protected CustomServiceOptions( Class> serviceFactoryClass, - Class> rpcFactoryClass, - Builder builder) { + Class> rpcFactoryClass, + Builder builder) { super(serviceFactoryClass, rpcFactoryClass, builder, null); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 6474b6389b..22c230e8d4 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -127,7 +127,7 @@ public TestService create(TestServiceOptions options) { } private interface TestServiceRpcFactory - extends ServiceRpcFactory {} + extends ServiceRpcFactory {} private static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory { private static final TestServiceRpcFactory INSTANCE = new DefaultTestServiceRpcFactory(); @@ -138,16 +138,16 @@ public TestServiceRpc create(TestServiceOptions options) { } } - private interface TestServiceRpc {} + private interface TestServiceRpc extends ServiceRpc {} private static class DefaultTestServiceRpc implements TestServiceRpc { DefaultTestServiceRpc(TestServiceOptions options) {} } private static class TestServiceOptions - extends ServiceOptions { + extends ServiceOptions { private static class Builder - extends ServiceOptions.Builder { + extends ServiceOptions.Builder { private Builder() {} private Builder(TestServiceOptions options) { @@ -166,7 +166,7 @@ private TestServiceOptions(Builder builder) { } private static class TestServiceDefaults implements - ServiceDefaults { + ServiceDefaults { @Override public TestServiceFactory getDefaultServiceFactory() { From c453dea1422489efaa39bb1b8cc4ceb7b0fc6022 Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Fri, 17 Mar 2017 11:28:27 -0700 Subject: [PATCH 304/663] Narrowing dependencies to avoid servlet-api (#1766) --- google-cloud-core/pom.xml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 077921cf2d..950d5dce9e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -52,7 +52,19 @@ com.google.api-client - google-api-client-appengine + google-api-client + 1.21.0 + compile + + + guava-jdk5 + com.google.guava + + + + + com.google.http-client + google-http-client-appengine 1.21.0 compile From 76fee5b2f27e0865b7037b7321a919b6cd722ca1 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Mon, 20 Mar 2017 18:09:33 -0700 Subject: [PATCH 305/663] Reconcile RetrySettings & Clock (google-cloud-java part) (#1738) Reconcile RetrySettings & Clock (google-cloud-java part) Reconcile RetrySettings in GAX with RetryParams in google-cloud-java GoogleCloudPlatform/google-cloud-java#1574 Reconcile NanoClock in GAX with Clock in google-cloud-java GoogleCloudPlatform/google-cloud-java#1575 --- .../google/cloud/BaseServiceException.java | 5 +- .../src/main/java/com/google/cloud/Clock.java | 59 ---- .../com/google/cloud/ExceptionHandler.java | 31 +- .../google/cloud/GrpcTransportOptions.java | 15 +- .../java/com/google/cloud/RetryHelper.java | 246 ++----------- .../java/com/google/cloud/RetryParams.java | 325 ------------------ .../java/com/google/cloud/ServiceOptions.java | 82 +++-- .../cloud/BaseServiceExceptionTest.java | 2 +- .../google/cloud/ExceptionHandlerTest.java | 50 +-- .../com/google/cloud/RetryHelperTest.java | 263 -------------- .../com/google/cloud/RetryParamsTest.java | 110 ------ .../com/google/cloud/SerializationTest.java | 29 +- .../com/google/cloud/ServiceOptionsTest.java | 87 ++--- 13 files changed, 200 insertions(+), 1104 deletions(-) delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/Clock.java delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/RetryParams.java delete mode 100644 google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java delete mode 100644 google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index cb834f8d36..4bebfc9259 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -295,12 +295,9 @@ private static String message(IOException exception) { return exception.getMessage(); } - protected static void translateAndPropagateIfPossible(RetryHelper.RetryHelperException ex) { + protected static void translate(RetryHelper.RetryHelperException ex) { if (ex.getCause() instanceof BaseServiceException) { throw (BaseServiceException) ex.getCause(); } - if (ex instanceof RetryHelper.RetryInterruptedException) { - RetryHelper.RetryInterruptedException.propagate(); - } } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/Clock.java b/google-cloud-core/src/main/java/com/google/cloud/Clock.java deleted file mode 100644 index 447200b03b..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/Clock.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import java.io.ObjectStreamException; -import java.io.Serializable; - -/** - * A class providing access to the current time in milliseconds. This class is mainly used for - * testing and will be replaced by Java8's {@code java.time.Clock}. - * - *

    Implementations should implement {@code Serializable} wherever possible and must document - * whether or not they do support serialization. - */ -public abstract class Clock { - - private static final Clock DEFAULT_TIME_SOURCE = new DefaultClock(); - - /** - * Returns current time in milliseconds according to this clock. - */ - public abstract long millis(); - - /** - * Returns the default clock. Default clock uses {@link System#currentTimeMillis()} to get time - * in milliseconds. - */ - public static Clock defaultClock() { - return DEFAULT_TIME_SOURCE; - } - - private static class DefaultClock extends Clock implements Serializable { - - private static final long serialVersionUID = -5077300394286703864L; - - @Override - public long millis() { - return System.currentTimeMillis(); - } - - private Object readResolve() throws ObjectStreamException { - return DEFAULT_TIME_SOURCE; - } - } -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java index a2a69a7376..81703b5612 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java @@ -18,6 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.api.gax.retrying.ExceptionRetryAlgorithm; +import com.google.api.gax.retrying.TimedAttemptSettings; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -31,9 +33,9 @@ import java.util.concurrent.Callable; /** - * Exception handling used by {@link RetryHelper}. + * Exception retry algorithm implementation used by {@link RetryHelper}. */ -public final class ExceptionHandler implements Serializable { +public final class ExceptionHandler implements ExceptionRetryAlgorithm, Serializable { private static final long serialVersionUID = -2460707015779532919L; @@ -233,17 +235,12 @@ void verifyCaller(Callable callable) { } } - - public Set> getRetriableExceptions() { - return retriableExceptions; - } - - - public Set> getNonRetriableExceptions() { - return nonRetriableExceptions; - } - - boolean shouldRetry(Exception ex) { + @Override + public boolean accept(Throwable prevThrowable) { + if(!(prevThrowable instanceof Exception)) { + return false; + } + Exception ex = (Exception) prevThrowable; for (Interceptor interceptor : interceptors) { Interceptor.RetryResult retryResult = checkNotNull(interceptor.beforeEval(ex)); if (retryResult != Interceptor.RetryResult.CONTINUE_EVALUATION) { @@ -263,6 +260,14 @@ boolean shouldRetry(Exception ex) { return retryResult == Interceptor.RetryResult.RETRY; } + @Override + public TimedAttemptSettings createNextAttempt(Throwable prevThrowable, + TimedAttemptSettings prevSettings) { + // Return null to indicate that this implementaiton does not provide any specific attempt + // settings, so by default the TimedRetryAlgorithm options can be used instead. + return null; + } + @Override public int hashCode() { return Objects.hash(interceptors, retriableExceptions, nonRetriableExceptions, retryInfo); diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java index be31c98747..0295b00972 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java @@ -36,7 +36,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import org.joda.time.Duration; /** * Class representing service options for those services that use gRPC as the transport @@ -206,18 +205,8 @@ public ExecutorFactory getExecutorFactory() { /** * Returns a builder for API call settings. */ - public UnaryCallSettings.Builder getApiCallSettings(RetryParams retryParams) { - // todo(mziccard): specify timeout these settings: - // retryParams().retryMaxAttempts(), retryParams().retryMinAttempts() - final RetrySettings.Builder builder = RetrySettings.newBuilder() - .setTotalTimeout(Duration.millis(retryParams.getTotalRetryPeriodMillis())) - .setInitialRpcTimeout(Duration.millis(getInitialTimeout())) - .setRpcTimeoutMultiplier(getTimeoutMultiplier()) - .setMaxRpcTimeout(Duration.millis(getMaxTimeout())) - .setInitialRetryDelay(Duration.millis(retryParams.getInitialRetryDelayMillis())) - .setRetryDelayMultiplier(retryParams.getRetryDelayBackoffFactor()) - .setMaxRetryDelay(Duration.millis(retryParams.getMaxRetryDelayMillis())); - return UnaryCallSettings.newBuilder().setRetrySettingsBuilder(builder); + public UnaryCallSettings.Builder getApiCallSettings(RetrySettings retrySettings) { + return UnaryCallSettings.newBuilder().setRetrySettingsBuilder(retrySettings.toBuilder()); } /** diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index b23a516cca..6d36096bb6 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -16,234 +16,48 @@ package com.google.cloud; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.StrictMath.max; -import static java.lang.StrictMath.min; -import static java.lang.StrictMath.pow; -import static java.lang.StrictMath.random; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -import java.io.InterruptedIOException; -import java.nio.channels.ClosedByInterruptException; +import com.google.api.gax.core.ApiClock; +import com.google.api.gax.core.RetrySettings; + +import com.google.api.gax.retrying.DirectRetryingExecutor; +import com.google.api.gax.retrying.ExponentialRetryAlgorithm; +import com.google.api.gax.retrying.RetryAlgorithm; +import com.google.api.gax.retrying.RetryingExecutor; +import com.google.api.gax.retrying.RetryingFuture; import java.util.concurrent.Callable; -import java.util.logging.Level; -import java.util.logging.Logger; /** - * Utility class for retrying operations. For more details about the parameters, see - * {@link RetryParams}. If the request is never successful, a {@link RetriesExhaustedException} will - * be thrown. - * - * @param return value of the closure that is being run with retries + * Utility class for retrying operations. For more details about the parameters, see {@link + * RetrySettings}. In case if retrying is unsuccessful, {@link RetryHelperException} will be + * thrown. */ -public class RetryHelper { - - private static final Logger log = Logger.getLogger(RetryHelper.class.getName()); - - private final Clock clock; - private final Callable callable; - private final RetryParams params; - private final ExceptionHandler exceptionHandler; - private int attemptNumber; +public class RetryHelper { + public static V runWithRetries( + Callable callable, + RetrySettings retrySettings, + ExceptionHandler exceptionRetryAlgorithm, + ApiClock clock) + throws RetryHelperException { + try { + RetryAlgorithm retryAlgorithm = + new RetryAlgorithm(exceptionRetryAlgorithm, new ExponentialRetryAlgorithm(retrySettings, clock)); + RetryingExecutor executor = new DirectRetryingExecutor<>(retryAlgorithm); + RetryingFuture retryingFuture = executor.createFuture(callable); + executor.submit(retryingFuture); - private static final ThreadLocal context = new ThreadLocal<>(); + return retryingFuture.get(); + } catch (Exception e) { + throw new RetryHelperException(e.getCause()); + } + } public static class RetryHelperException extends RuntimeException { - private static final long serialVersionUID = -2907061015610448235L; - - RetryHelperException() {} - - RetryHelperException(String message) { - super(message); - } + private static final long serialVersionUID = -8519852520090965314L; RetryHelperException(Throwable cause) { super(cause); } - - RetryHelperException(String message, Throwable cause) { - super(message, cause); - } - } - - /** - * Thrown when a RetryHelper failed to complete its work due to interruption. Throwing this - * exception also sets the thread interrupt flag. - */ - public static final class RetryInterruptedException extends RetryHelperException { - - private static final long serialVersionUID = 1678966737697204885L; - - RetryInterruptedException() {} - - /** - * Sets the caller thread interrupt flag and throws {@code RetryInterruptedException}. - */ - public static void propagate() throws RetryInterruptedException { - Thread.currentThread().interrupt(); - throw new RetryInterruptedException(); - } - } - - /** - * Thrown when a RetryHelper has attempted the maximum number of attempts allowed by RetryParams - * and was not successful. - */ - public static final class RetriesExhaustedException extends RetryHelperException { - - private static final long serialVersionUID = 780199686075408083L; - - RetriesExhaustedException(String message) { - super(message); - } - - RetriesExhaustedException(String message, Throwable cause) { - super(message, cause); - } - } - - /** - * Thrown when RetryHelper callable has indicate it should not be retried. - */ - public static final class NonRetriableException extends RetryHelperException { - - private static final long serialVersionUID = -2331878521983499652L; - - NonRetriableException(Throwable throwable) { - super(throwable); - } - } - - static class Context { - - private final RetryHelper helper; - - Context(RetryHelper helper) { - this.helper = helper; - } - - public RetryParams getRetryParams() { - return helper.params; - } - - public int getAttemptNumber() { - return helper.attemptNumber; - } - } - - @VisibleForTesting - static void setContext(Context ctx) { - if (ctx == null) { - context.remove(); - } else { - context.set(ctx); - } - } - - static Context getContext() { - return context.get(); - } - - @VisibleForTesting - RetryHelper(Callable callable, RetryParams params, ExceptionHandler exceptionHandler, - Clock clock) { - this.callable = checkNotNull(callable); - this.params = checkNotNull(params); - this.clock = checkNotNull(clock); - this.exceptionHandler = checkNotNull(exceptionHandler); - exceptionHandler.verifyCaller(callable); - } - - @Override - public String toString() { - ToStringHelper toStringHelper = MoreObjects.toStringHelper(this); - toStringHelper.add("params", params); - toStringHelper.add("clock", clock); - toStringHelper.add("attemptNumber", attemptNumber); - toStringHelper.add("callable", callable); - toStringHelper.add("exceptionHandler", exceptionHandler); - return toStringHelper.toString(); - } - - private V doRetry() throws RetryHelperException { - long start = clock.millis(); - while (true) { - attemptNumber++; - Exception exception; - try { - V value = callable.call(); - if (attemptNumber > 1 && log.isLoggable(Level.FINE)) { - log.fine(this + ": attempt #" + attemptNumber + " succeeded"); - } - return value; - } catch (InterruptedException | InterruptedIOException | ClosedByInterruptException e) { - if (!exceptionHandler.shouldRetry(e)) { - RetryInterruptedException.propagate(); - } - exception = e; - } catch (Exception e) { - if (!exceptionHandler.shouldRetry(e)) { - throw new NonRetriableException(e); - } - exception = e; - } - if (attemptNumber >= params.getRetryMaxAttempts() - || attemptNumber >= params.getRetryMinAttempts() - && clock.millis() - start >= params.getTotalRetryPeriodMillis()) { - throw new RetriesExhaustedException(this + ": Too many failures, giving up", exception); - } - long sleepDurationMillis = getSleepDuration(params, attemptNumber); - if (log.isLoggable(Level.FINE)) { - log.fine(this + ": Attempt #" + attemptNumber + " failed [" + exception - + "], sleeping for " + sleepDurationMillis + " ms"); - } - try { - Thread.sleep(sleepDurationMillis); - } catch (InterruptedException e) { - // propagate as RetryInterruptedException - RetryInterruptedException.propagate(); - } - } - } - - @VisibleForTesting - static long getSleepDuration(RetryParams retryParams, int attemptsSoFar) { - long initialDelay = retryParams.getInitialRetryDelayMillis(); - double backoffFactor = retryParams.getRetryDelayBackoffFactor(); - long maxDelay = retryParams.getMaxRetryDelayMillis(); - long retryDelay = getExponentialValue(initialDelay, backoffFactor, maxDelay, attemptsSoFar); - return (long) ((random() / 2.0 + .75) * retryDelay); - } - - private static long getExponentialValue(long initialDelay, double backoffFactor, long maxDelay, - int attemptsSoFar) { - return (long) min(maxDelay, pow(backoffFactor, max(1, attemptsSoFar) - 1) * initialDelay); - } - - public static V runWithRetries(Callable callable) throws RetryHelperException { - return runWithRetries(callable, RetryParams.getDefaultInstance(), - ExceptionHandler.getDefaultInstance()); - } - - public static V runWithRetries(Callable callable, RetryParams params, - ExceptionHandler exceptionHandler) throws RetryHelperException { - return runWithRetries(callable, params, exceptionHandler, Clock.defaultClock()); - } - - public static V runWithRetries(Callable callable, RetryParams params, - ExceptionHandler exceptionHandler, Clock clock) throws RetryHelperException { - RetryHelper retryHelper = new RetryHelper<>(callable, params, exceptionHandler, clock); - Context previousContext = getContext(); - setContext(new Context(retryHelper)); - try { - return retryHelper.doRetry(); - } finally { - setContext(previousContext); - } } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java b/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java deleted file mode 100644 index f737032cfe..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryParams.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -import java.io.Serializable; -import java.util.Objects; - -/** - * Parameters for configuring retries with an exponential backoff. Initial request is executed - * immediately. If the request fails but passes the {@link ExceptionHandler} criteria the calling - * thread sleeps for {@code initialRetryDelayMillis}. Each subsequent failure the sleep interval is - * calculated as: - *

    - * {@code retryDelayBackoffFactor ^ attempts * initialRetryDelayMillis} but would be upper-bounded - * to {@code maxRetryDelayMillis} - *

    - * This proceeds until either the request is successful, {@code retryMaxAttempts} are made, or both - * {@code retryMinAttempts} are made and {@code totalRetryPeriodMillis} have elapsed. To construct - * {@code RetryParams}, first create a {@link RetryParams.Builder}. The builder is mutable and each - * of the parameters can be set (any unset parameters will fallback to the defaults). The - * {@code Builder} can be then used to create an immutable {@code RetryParams} object. For default - * {@code RetryParams} use {@link #getDefaultInstance}. Default settings are subject to change - * release to release. If you require specific settings, explicitly create an instance of - * {@code RetryParams} with all the required settings. - * - * @see RetryHelper - */ -public final class RetryParams implements Serializable { - - private static final long serialVersionUID = -8492751576749007700L; - - /** - * Note that App Engine Standard Environment front-end modules have a 60 second deadline for HTTP - * requests. For that reason, we set the default total retry period to less than 60 seconds. - */ - public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L; - public static final int DEFAULT_RETRY_MIN_ATTEMPTS = 3; - public static final int DEFAULT_RETRY_MAX_ATTEMPTS = 6; - public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 1000L; - public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 32_000L; - public static final double DEFAULT_RETRY_DELAY_BACKOFF_FACTOR = 2.0; - - private final int retryMinAttempts; - private final int retryMaxAttempts; - private final long initialRetryDelayMillis; - private final long maxRetryDelayMillis; - private final double retryDelayBackoffFactor; - private final long totalRetryPeriodMillis; - - // Some services may have different backoff requirements listed in their SLAs. Be sure to override - // ServiceOptions.defaultRetryParams() in options subclasses when the service's backoff - // requirement differs from the default parameters used here. - private static final RetryParams DEFAULT_INSTANCE = new RetryParams(new Builder()); - private static final RetryParams NO_RETRIES = - newBuilder().setRetryMaxAttempts(1).setRetryMinAttempts(1).build(); - - /** - * RetryParams builder. - */ - public static final class Builder { - - private int retryMinAttempts; - private int retryMaxAttempts; - private long initialRetryDelayMillis; - private long maxRetryDelayMillis; - private double retryDelayBackoffFactor; - private long totalRetryPeriodMillis; - - private Builder() { - this(null); - } - - Builder(/* Nullable */RetryParams retryParams) { - if (retryParams == null) { - retryMinAttempts = DEFAULT_RETRY_MIN_ATTEMPTS; - retryMaxAttempts = DEFAULT_RETRY_MAX_ATTEMPTS; - initialRetryDelayMillis = DEFAULT_INITIAL_RETRY_DELAY_MILLIS; - maxRetryDelayMillis = DEFAULT_MAX_RETRY_DELAY_MILLIS; - retryDelayBackoffFactor = DEFAULT_RETRY_DELAY_BACKOFF_FACTOR; - totalRetryPeriodMillis = DEFAULT_TOTAL_RETRY_PERIOD_MILLIS; - } else { - retryMinAttempts = retryParams.getRetryMinAttempts(); - retryMaxAttempts = retryParams.getRetryMaxAttempts(); - initialRetryDelayMillis = retryParams.getInitialRetryDelayMillis(); - maxRetryDelayMillis = retryParams.getMaxRetryDelayMillis(); - retryDelayBackoffFactor = retryParams.getRetryDelayBackoffFactor(); - totalRetryPeriodMillis = retryParams.getTotalRetryPeriodMillis(); - } - } - - - /** - * Sets retryMinAttempts. - * - * @param retryMinAttempts the retryMinAttempts to set - * @return the Builder for chaining - */ - public Builder setRetryMinAttempts(int retryMinAttempts) { - this.retryMinAttempts = retryMinAttempts; - return this; - } - - - /** - * Sets retryMaxAttempts. - * - * @param retryMaxAttempts the retryMaxAttempts to set - * @return the Builder for chaining - */ - public Builder setRetryMaxAttempts(int retryMaxAttempts) { - this.retryMaxAttempts = retryMaxAttempts; - return this; - } - - - /** - * Sets initialRetryDelayMillis. - * - * @param initialRetryDelayMillis the initialRetryDelayMillis to set - * @return the Builder for chaining - */ - public Builder setInitialRetryDelayMillis(long initialRetryDelayMillis) { - this.initialRetryDelayMillis = initialRetryDelayMillis; - return this; - } - - - /** - * Sets maxRetryDelayMillis. - * - * @param maxRetryDelayMillis the maxRetryDelayMillis to set - * @return the Builder for chaining - */ - public Builder setMaxRetryDelayMillis(long maxRetryDelayMillis) { - this.maxRetryDelayMillis = maxRetryDelayMillis; - return this; - } - - - /** - * Sets retryDelayBackoffFactor. - * - * @param retryDelayBackoffFactor the retryDelayBackoffFactor to set - * @return the Builder for chaining - */ - public Builder setRetryDelayBackoffFactor(double retryDelayBackoffFactor) { - this.retryDelayBackoffFactor = retryDelayBackoffFactor; - return this; - } - - - /** - * Sets totalRetryPeriodMillis. Note that App Engine Standard Environment front-end modules have - * a 60 second deadline for HTTP requests. For that reason, you should set the total retry - * period to under 60 seconds if you are using it on an App Engine front-end module. - * - * @param totalRetryPeriodMillis the totalRetryPeriodMillis to set - * @return the Builder for chaining - */ - public Builder setTotalRetryPeriodMillis(long totalRetryPeriodMillis) { - this.totalRetryPeriodMillis = totalRetryPeriodMillis; - return this; - } - - /** - * Create an instance of RetryParams with the parameters set in this builder. - * - * @return a new instance of RetryParams - */ - public RetryParams build() { - return new RetryParams(this); - } - } - - /** - * Create a new RetryParams with the parameters from a {@link RetryParams.Builder} - * - * @param builder the parameters to use to construct the RetryParams object - */ - private RetryParams(Builder builder) { - retryMinAttempts = builder.retryMinAttempts; - retryMaxAttempts = builder.retryMaxAttempts; - initialRetryDelayMillis = builder.initialRetryDelayMillis; - maxRetryDelayMillis = builder.maxRetryDelayMillis; - retryDelayBackoffFactor = builder.retryDelayBackoffFactor; - totalRetryPeriodMillis = builder.totalRetryPeriodMillis; - checkArgument(retryMinAttempts >= 0, "retryMinAttempts must not be negative"); - checkArgument(retryMaxAttempts >= retryMinAttempts, - "retryMaxAttempts must not be smaller than retryMinAttempts"); - checkArgument(initialRetryDelayMillis >= 0, "initialRetryDelayMillis must not be negative"); - checkArgument(maxRetryDelayMillis >= initialRetryDelayMillis, - "maxRetryDelayMillis must not be smaller than initialRetryDelayMillis"); - checkArgument(retryDelayBackoffFactor >= 0, "retryDelayBackoffFactor must not be negative"); - checkArgument(totalRetryPeriodMillis >= 0, "totalRetryPeriodMillis must not be negative"); - } - - - /** - * Returns an instance with the default parameters. - */ - public static RetryParams getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - /** - * Returns an instance of {@code RetryParams} where `retryMaxAttempts` and `retryMinAttempts` are - * set to `1`. - */ - public static RetryParams noRetries() { - return NO_RETRIES; - } - - - /** - * Returns the retryMinAttempts. Default value is {@value #DEFAULT_RETRY_MIN_ATTEMPTS}. - */ - public int getRetryMinAttempts() { - return retryMinAttempts; - } - - - /** - * Returns the retryMaxAttempts. Default value is {@value #DEFAULT_RETRY_MAX_ATTEMPTS}. - */ - public int getRetryMaxAttempts() { - return retryMaxAttempts; - } - - - /** - * Returns the initialRetryDelayMillis. Default value is - * {@value #DEFAULT_INITIAL_RETRY_DELAY_MILLIS}. - */ - public long getInitialRetryDelayMillis() { - return initialRetryDelayMillis; - } - - - /** - * Returns the maxRetryDelayMillis. Default values is {@value #DEFAULT_MAX_RETRY_DELAY_MILLIS}. - */ - public long getMaxRetryDelayMillis() { - return maxRetryDelayMillis; - } - - - /** - * Returns the maxRetryDelayBackoffFactor. Default values is - * {@value #DEFAULT_RETRY_DELAY_BACKOFF_FACTOR}. - */ - public double getRetryDelayBackoffFactor() { - return retryDelayBackoffFactor; - } - - - /** - * Returns the totalRetryPeriodMillis. Default value is - * {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}. - */ - public long getTotalRetryPeriodMillis() { - return totalRetryPeriodMillis; - } - - @Override - public int hashCode() { - return Objects.hash(retryMinAttempts, retryMaxAttempts, initialRetryDelayMillis, - maxRetryDelayMillis, retryDelayBackoffFactor, totalRetryPeriodMillis); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof RetryParams)) { - return false; - } - RetryParams other = (RetryParams) obj; - return retryMinAttempts == other.retryMinAttempts && retryMaxAttempts == other.retryMaxAttempts - && initialRetryDelayMillis == other.initialRetryDelayMillis - && maxRetryDelayMillis == other.maxRetryDelayMillis - && retryDelayBackoffFactor == other.retryDelayBackoffFactor - && totalRetryPeriodMillis == other.totalRetryPeriodMillis; - } - - @Override - public String toString() { - ToStringHelper toStringHelper = MoreObjects.toStringHelper(this); - toStringHelper.add("retryMinAttempts", retryMinAttempts); - toStringHelper.add("retryMaxAttempts", retryMaxAttempts); - toStringHelper.add("initialRetryDelayMillis", initialRetryDelayMillis); - toStringHelper.add("maxRetryDelayMillis", maxRetryDelayMillis); - toStringHelper.add("retryDelayBackoffFactor", retryDelayBackoffFactor); - toStringHelper.add("totalRetryPeriodMillis", totalRetryPeriodMillis); - return toStringHelper.toString(); - } - - - public static Builder newBuilder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 39e6c2ac2d..843f775eca 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -21,12 +21,16 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.api.gax.core.CurrentMillisClock; +import com.google.api.gax.core.ApiClock; +import com.google.api.gax.core.RetrySettings; import com.google.auth.Credentials; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.collect.Iterables; import com.google.common.io.Files; +import org.joda.time.Duration; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; @@ -77,17 +81,22 @@ public abstract class ServiceOptions, private static final String LIBRARY_VERSION = defaultLibraryVersion(); private static final String APPLICATION_NAME = LIBRARY_VERSION == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + LIBRARY_VERSION; - private static final long serialVersionUID = -5714029257168617973L; private static final String META_FILE_ROOT = "/META-INF/maven/"; private static final String META_VERSION_KEY = "version"; + private static final RetrySettings DEFAULT_RETRY_SETTINGS = getDefaultRetrySettingsBuilder() + .build(); + private static final RetrySettings NO_RETRY_SETTINGS = getDefaultRetrySettingsBuilder() + .setMaxAttempts(1).build(); + + private static final long serialVersionUID = 9198896031667942014L; private final String projectId; private final String host; - private final RetryParams retryParams; + private final RetrySettings retrySettings; private final String serviceRpcFactoryClassName; private final String serviceFactoryClassName; - private final Clock clock; + private final ApiClock clock; private final Credentials credentials; private final TransportOptions transportOptions; @@ -110,10 +119,10 @@ public abstract static class Builder, private String projectId; private String host; private Credentials credentials; - private RetryParams retryParams; + private RetrySettings retrySettings; private ServiceFactory serviceFactory; private ServiceRpcFactory serviceRpcFactory; - private Clock clock; + private ApiClock clock; private TransportOptions transportOptions; protected Builder() {} @@ -122,7 +131,7 @@ protected Builder(ServiceOptions options) { projectId = options.projectId; host = options.host; credentials = options.credentials; - retryParams = options.retryParams; + retrySettings = options.retrySettings; serviceFactory = options.serviceFactory; serviceRpcFactory = options.serviceRpcFactory; clock = options.clock; @@ -147,13 +156,13 @@ public B setServiceFactory(ServiceFactory serviceFactory) { /** - * Sets the service's clock. The clock is mainly used for testing purpose. {@link Clock} will be - * replaced by Java8's {@code java.time.Clock}. + * Sets the service's clock. The clock is mainly used for testing purpose. {@link ApiClock} + * will be replaced by Java8's {@code java.time.Clock}. * * @param clock the clock to set * @return the builder */ - public B setClock(Clock clock) { + public B setClock(ApiClock clock) { this.clock = clock; return self(); } @@ -190,7 +199,7 @@ public B setHost(String host) { * @param credentials authentication credentials, should not be {@code null} * @return the builder * @throws NullPointerException if {@code credentials} is {@code null}. To disable - * authentication use {@link NoCredentials#getInstance()} + * authentication use {@link NoCredentials#getInstance()} */ public B setCredentials(Credentials credentials) { this.credentials = checkNotNull(credentials); @@ -199,14 +208,12 @@ public B setCredentials(Credentials credentials) { /** - * Sets configuration parameters for request retries. If no configuration is set - * {@link RetryParams#getDefaultInstance()} is used. To disable retries, supply - * {@link RetryParams#noRetries()} here. + * Sets configuration parameters for request retries. * * @return the builder */ - public B setRetryParams(RetryParams retryParams) { - this.retryParams = retryParams; + public B setRetrySettings(RetrySettings retrySettings) { + this.retrySettings = retrySettings; return self(); } @@ -241,18 +248,18 @@ protected ServiceOptions(Class> ser checkArgument( projectId != null, "A project ID is required for this service but could not be determined from the builder " - + "or the environment. Please set a project ID using the builder."); + + "or the environment. Please set a project ID using the builder."); } host = firstNonNull(builder.host, getDefaultHost()); credentials = builder.credentials != null ? builder.credentials : defaultCredentials(); - retryParams = firstNonNull(builder.retryParams, defaultRetryParams()); + retrySettings = firstNonNull(builder.retrySettings, getDefaultRetrySettings()); serviceFactory = firstNonNull(builder.serviceFactory, getFromServiceLoader(serviceFactoryClass, serviceDefaults.getDefaultServiceFactory())); serviceFactoryClassName = serviceFactory.getClass().getName(); serviceRpcFactory = firstNonNull(builder.serviceRpcFactory, getFromServiceLoader(rpcFactoryClass, serviceDefaults.getDefaultRpcFactory())); serviceRpcFactoryClassName = serviceRpcFactory.getClass().getName(); - clock = firstNonNull(builder.clock, Clock.defaultClock()); + clock = firstNonNull(builder.clock, CurrentMillisClock.getDefaultClock()); transportOptions = firstNonNull(builder.transportOptions, serviceDefaults.getDefaultTransportOptions()); } @@ -493,11 +500,10 @@ public Credentials getScopedCredentials() { /** - * Returns configuration parameters for request retries. By default requests are retried: - * {@link RetryParams#getDefaultInstance()} is used. + * Returns configuration parameters for request retries. */ - public RetryParams getRetryParams() { - return retryParams; + public RetrySettings getRetrySettings() { + return retrySettings; } @@ -505,7 +511,7 @@ public RetryParams getRetryParams() { * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to get * current time. */ - public Clock getClock() { + public ApiClock getClock() { return clock; } @@ -546,7 +552,7 @@ public String getLibraryVersion() { } protected int baseHashCode() { - return Objects.hash(projectId, host, credentials, retryParams, serviceFactoryClassName, + return Objects.hash(projectId, host, credentials, retrySettings, serviceFactoryClassName, serviceRpcFactoryClassName, clock); } @@ -554,7 +560,7 @@ protected boolean baseEquals(ServiceOptions other) { return Objects.equals(projectId, other.projectId) && Objects.equals(host, other.host) && Objects.equals(credentials, other.credentials) - && Objects.equals(retryParams, other.retryParams) + && Objects.equals(retrySettings, other.retrySettings) && Objects.equals(serviceFactoryClassName, other.serviceFactoryClassName) && Objects.equals(serviceRpcFactoryClassName, other.serviceRpcFactoryClassName) && Objects.equals(clock, clock); @@ -575,6 +581,26 @@ static T newInstance(String className) throws IOException, ClassNotFoundExce } } + public static RetrySettings getDefaultRetrySettings() { + return DEFAULT_RETRY_SETTINGS; + } + + public static RetrySettings getNoRetrySettings() { + return NO_RETRY_SETTINGS; + } + + private static RetrySettings.Builder getDefaultRetrySettingsBuilder() { + return RetrySettings.newBuilder() + .setMaxAttempts(6) + .setInitialRetryDelay(Duration.millis(1000L)) + .setMaxRetryDelay(Duration.millis(32_000L)) + .setRetryDelayMultiplier(2.0) + .setTotalTimeout(Duration.millis(50_000L)) + .setInitialRpcTimeout(Duration.millis(50_000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.millis(50_000L)); + } + protected abstract Set getScopes(); public abstract > B toBuilder(); @@ -582,10 +608,10 @@ static T newInstance(String className) throws IOException, ClassNotFoundExce /** * Some services may have different backoff requirements listed in their SLAs. Be sure to override * this method in options subclasses when the service's backoff requirement differs from the - * default parameters listed in {@link RetryParams}. + * default parameters listed in {@link RetrySettings}. */ - protected RetryParams defaultRetryParams() { - return RetryParams.getDefaultInstance(); + protected RetrySettings defaultRetrySettings() { + return getDefaultRetrySettings(); } static T getFromServiceLoader(Class clazz, T defaultInstance) { diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index 9ac4b4b989..7992f9e803 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -158,7 +158,7 @@ public void testTranslateAndThrow() throws Exception { expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try { - BaseServiceException.translateAndPropagateIfPossible(exceptionMock); + BaseServiceException.translate(exceptionMock); } catch (BaseServiceException ex) { assertEquals(CODE, ex.getCode()); assertEquals(MESSAGE, ex.getMessage()); diff --git a/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java index f489207019..c78f7773d3 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java @@ -117,9 +117,9 @@ private static void assertInvalidCallable(Callable callable, ExceptionHan @Test public void testShouldTry() { ExceptionHandler handler = ExceptionHandler.newBuilder().retryOn(IOException.class).build(); - assertTrue(handler.shouldRetry(new IOException())); - assertTrue(handler.shouldRetry(new ClosedByInterruptException())); - assertFalse(handler.shouldRetry(new RuntimeException())); + assertTrue(handler.accept(new IOException())); + assertTrue(handler.accept(new ClosedByInterruptException())); + assertFalse(handler.accept(new RuntimeException())); ExceptionHandler.Builder builder = ExceptionHandler.newBuilder() .retryOn(IOException.class, NullPointerException.class) @@ -127,11 +127,11 @@ public void testShouldTry() { InterruptedException.class); handler = builder.build(); - assertTrue(handler.shouldRetry(new IOException())); - assertFalse(handler.shouldRetry(new ClosedByInterruptException())); - assertFalse(handler.shouldRetry(new InterruptedException())); - assertFalse(handler.shouldRetry(new RuntimeException())); - assertTrue(handler.shouldRetry(new NullPointerException())); + assertTrue(handler.accept(new IOException())); + assertFalse(handler.accept(new ClosedByInterruptException())); + assertFalse(handler.accept(new InterruptedException())); + assertFalse(handler.accept(new RuntimeException())); + assertTrue(handler.accept(new NullPointerException())); final AtomicReference before = new AtomicReference<>(RetryResult.NO_RETRY); @SuppressWarnings("serial") @@ -150,25 +150,25 @@ public RetryResult beforeEval(Exception exception) { builder.addInterceptors(interceptor); handler = builder.build(); - assertFalse(handler.shouldRetry(new IOException())); - assertFalse(handler.shouldRetry(new ClosedByInterruptException())); - assertFalse(handler.shouldRetry(new InterruptedException())); - assertFalse(handler.shouldRetry(new RuntimeException())); - assertFalse(handler.shouldRetry(new NullPointerException())); + assertFalse(handler.accept(new IOException())); + assertFalse(handler.accept(new ClosedByInterruptException())); + assertFalse(handler.accept(new InterruptedException())); + assertFalse(handler.accept(new RuntimeException())); + assertFalse(handler.accept(new NullPointerException())); before.set(RetryResult.RETRY); - assertTrue(handler.shouldRetry(new IOException())); - assertTrue(handler.shouldRetry(new ClosedByInterruptException())); - assertTrue(handler.shouldRetry(new InterruptedException())); - assertTrue(handler.shouldRetry(new RuntimeException())); - assertTrue(handler.shouldRetry(new NullPointerException())); + assertTrue(handler.accept(new IOException())); + assertTrue(handler.accept(new ClosedByInterruptException())); + assertTrue(handler.accept(new InterruptedException())); + assertTrue(handler.accept(new RuntimeException())); + assertTrue(handler.accept(new NullPointerException())); before.set(RetryResult.CONTINUE_EVALUATION); - assertFalse(handler.shouldRetry(new IOException())); - assertTrue(handler.shouldRetry(new ClosedByInterruptException())); - assertTrue(handler.shouldRetry(new InterruptedException())); - assertTrue(handler.shouldRetry(new RuntimeException())); - assertFalse(handler.shouldRetry(new NullPointerException())); + assertFalse(handler.accept(new IOException())); + assertTrue(handler.accept(new ClosedByInterruptException())); + assertTrue(handler.accept(new InterruptedException())); + assertTrue(handler.accept(new RuntimeException())); + assertFalse(handler.accept(new NullPointerException())); } @Test @@ -190,7 +190,7 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build(); thrown.expect(NullPointerException.class); - handler.shouldRetry(new Exception()); + handler.accept(new Exception()); } @Test @@ -212,6 +212,6 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build(); thrown.expect(NullPointerException.class); - handler.shouldRetry(new Exception()); + handler.accept(new Exception()); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java deleted file mode 100644 index 68bb7ce353..0000000000 --- a/google-cloud-core/src/test/java/com/google/cloud/RetryHelperTest.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import static java.util.concurrent.Executors.callable; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.google.cloud.RetryHelper.NonRetriableException; -import com.google.cloud.RetryHelper.RetriesExhaustedException; - -import org.junit.Test; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Iterator; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -/** - * Tests for {@link RetryHelper}. - */ -public class RetryHelperTest { - - static class E1Exception extends Exception { - private static final long serialVersionUID = 3874933713392137001L; - } - - static class E2Exception extends E1Exception { - private static final long serialVersionUID = -8710227162480133598L; - } - - static class E3Exception extends E1Exception { - private static final long serialVersionUID = -7794256022024001666L; - } - - static class E4Exception extends E2Exception { - private static final long serialVersionUID = -5508018234693709156L; - } - - @Test - public void testTriesWithExceptionHandling() { - assertNull(RetryHelper.getContext()); - RetryParams params = - RetryParams.newBuilder().setInitialRetryDelayMillis(0).setRetryMaxAttempts(3).build(); - ExceptionHandler handler = ExceptionHandler.newBuilder() - .retryOn(IOException.class).abortOn(RuntimeException.class).build(); - final AtomicInteger count = new AtomicInteger(3); - try { - RetryHelper.runWithRetries(new Callable() { - @Override public Void call() throws IOException, NullPointerException { - if (count.decrementAndGet() == 2) { - assertEquals(1, RetryHelper.getContext().getAttemptNumber()); - throw new IOException("should be retried"); - } - assertEquals(2, RetryHelper.getContext().getAttemptNumber()); - throw new NullPointerException("Boo!"); - } - }, params, handler); - fail("Exception should have been thrown"); - } catch (NonRetriableException ex) { - assertEquals("Boo!", ex.getCause().getMessage()); - assertEquals(1, count.intValue()); - } - assertNull(RetryHelper.getContext()); - - params = RetryParams.newBuilder().setInitialRetryDelayMillis(0).setRetryMaxAttempts(5).build(); - handler = ExceptionHandler.newBuilder() - .retryOn(E1Exception.class, E4Exception.class) - .abortOn(E3Exception.class).build(); - final Iterator exceptions = Arrays.asList( - new E1Exception(), new E2Exception(), new E4Exception(), new E3Exception()).iterator(); - try { - RetryHelper.runWithRetries(new Callable() { - @Override public Void call() throws E1Exception { - throw exceptions.next(); - } - }, params, handler); - fail("Exception should have been thrown"); - } catch (NonRetriableException ex) { - assertTrue(ex.getCause() instanceof E3Exception); - } - assertNull(RetryHelper.getContext()); - } - - @Test - public void testTriesAtLeastMinTimes() { - // Total retry period set to 60 seconds so as to not factor into test - RetryParams params = RetryParams.newBuilder().setInitialRetryDelayMillis(0) - .setTotalRetryPeriodMillis(60000) - .setRetryMinAttempts(5) - .setRetryMaxAttempts(10) - .build(); - final int timesToFail = 7; - assertNull(RetryHelper.getContext()); - int attempted = RetryHelper.runWithRetries(new Callable() { - int timesCalled; - @Override public Integer call() throws IOException { - timesCalled++; - assertEquals(timesCalled, RetryHelper.getContext().getAttemptNumber()); - assertEquals(10, RetryHelper.getContext().getRetryParams().getRetryMaxAttempts()); - if (timesCalled <= timesToFail) { - throw new IOException(); - } - return timesCalled; - } - }, params, ExceptionHandler.getDefaultInstance()); - assertEquals(timesToFail + 1, attempted); - assertNull(RetryHelper.getContext()); - } - - - @Test - public void testTriesNoMoreThanMaxTimes() { - // Total retry period set to 60 seconds so as to not factor into test - final int maxAttempts = 10; - RetryParams params = RetryParams.newBuilder().setInitialRetryDelayMillis(0) - .setTotalRetryPeriodMillis(60000) - .setRetryMinAttempts(0) - .setRetryMaxAttempts(maxAttempts) - .build(); - final AtomicInteger timesCalled = new AtomicInteger(0); - try { - RetryHelper.runWithRetries(callable(new Runnable() { - @Override public void run() { - // Throw an exception up to maxAttempts times, should never be called beyond that - if (timesCalled.incrementAndGet() <= maxAttempts) { - throw new RuntimeException(); - } - fail("Body was executed too many times: " + timesCalled.get()); - } - }), params, ExceptionHandler.newBuilder().retryOn(RuntimeException.class).build()); - // Unnecessary as this line should not be possible reach even if RetryHandler is broken - fail("Should not have succeeded, expected all attempts to fail and give up."); - } catch (RetriesExhaustedException expected) { - // Expect the body to run exactly maxAttempts times - assertEquals(maxAttempts, timesCalled.get()); - } - } - - - private static class FakeClock extends Clock { - - private final AtomicLong millis = new AtomicLong(); - - // Advances the clock value by {@code time} in {@code timeUnit}. - void advance(long time, TimeUnit timeUnit) { - millis.addAndGet(timeUnit.toMillis(time)); - } - - @Override - public long millis() { - return millis.get(); - } - } - - @Test - public void testTriesNoMoreLongerThanTotalRetryPeriod() { - final FakeClock fakeClock = new FakeClock(); - // The 8th attempt (after min and before max) will trigger a 1 second (virtual) delay exceeding - // total retry period which is set just under 1 second. Test occurs faster than realtime. - RetryParams params = RetryParams.newBuilder().setInitialRetryDelayMillis(0) - .setTotalRetryPeriodMillis(999) - .setRetryMinAttempts(5) - .setRetryMaxAttempts(10) - .build(); - ExceptionHandler handler = ExceptionHandler.newBuilder().retryOn(RuntimeException.class).build(); - final int sleepOnAttempt = 8; - final AtomicInteger timesCalled = new AtomicInteger(0); - try { - RetryHelper.runWithRetries(callable(new Runnable() { - @Override public void run() { - timesCalled.incrementAndGet(); - if (timesCalled.get() == sleepOnAttempt) { - fakeClock.advance(1000, TimeUnit.MILLISECONDS); - } - throw new RuntimeException(); - } - }), params, handler, fakeClock); - fail(); - } catch (RetriesExhaustedException expected) { - // verify timesCalled - assertEquals(sleepOnAttempt, timesCalled.get()); - } - } - - @Test - public void testBackoffIsExponential() { - // Total retry period set to 60 seconds so as to not factor into test - RetryParams params = RetryParams.newBuilder() - .setInitialRetryDelayMillis(10) - .setMaxRetryDelayMillis(10_000_000) - .setRetryDelayBackoffFactor(2) - .setTotalRetryPeriodMillis(60_000) - .setRetryMinAttempts(0) - .setRetryMaxAttempts(100) - .build(); - long sleepDuration = RetryHelper.getSleepDuration(params, 1); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 13 && sleepDuration >= 7); - sleepDuration = RetryHelper.getSleepDuration(params, 2); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 25 && sleepDuration >= 15); - sleepDuration = RetryHelper.getSleepDuration(params, 3); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 50 && sleepDuration >= 30); - sleepDuration = RetryHelper.getSleepDuration(params, 4); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 100 && sleepDuration >= 60); - sleepDuration = RetryHelper.getSleepDuration(params, 5); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 200 && sleepDuration >= 120); - sleepDuration = RetryHelper.getSleepDuration(params, 6); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 400 && sleepDuration >= 240); - sleepDuration = RetryHelper.getSleepDuration(params, 7); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 800 && sleepDuration >= 480); - sleepDuration = RetryHelper.getSleepDuration(params, 8); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 1600 && sleepDuration >= 960); - sleepDuration = RetryHelper.getSleepDuration(params, 9); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 3200 && sleepDuration >= 1920); - sleepDuration = RetryHelper.getSleepDuration(params, 10); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 6400 && sleepDuration >= 3840); - sleepDuration = RetryHelper.getSleepDuration(params, 11); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 12800 && sleepDuration >= 7680); - sleepDuration = RetryHelper.getSleepDuration(params, 12); - assertTrue(String.valueOf(sleepDuration), sleepDuration < 25600 && sleepDuration >= 15360); - } - - @Test - public void testNestedUsage() { - assertEquals((1 + 3) * 2, invokeNested(3, 2)); - } - - private int invokeNested(final int level, final int retries) { - if (level < 0) { - return 0; - } - return RetryHelper.runWithRetries(new Callable() { - @Override - public Integer call() throws IOException { - if (RetryHelper.getContext().getAttemptNumber() < retries) { - throw new IOException(); - } - assertEquals(retries, RetryHelper.getContext().getAttemptNumber()); - return invokeNested(level - 1, retries) + RetryHelper.getContext().getAttemptNumber(); - } - }); - } - -} diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java deleted file mode 100644 index 5f822fe7ae..0000000000 --- a/google-cloud-core/src/test/java/com/google/cloud/RetryParamsTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import static com.google.cloud.RetryParams.DEFAULT_INITIAL_RETRY_DELAY_MILLIS; -import static com.google.cloud.RetryParams.DEFAULT_MAX_RETRY_DELAY_MILLIS; -import static com.google.cloud.RetryParams.DEFAULT_RETRY_DELAY_BACKOFF_FACTOR; -import static com.google.cloud.RetryParams.DEFAULT_RETRY_MAX_ATTEMPTS; -import static com.google.cloud.RetryParams.DEFAULT_RETRY_MIN_ATTEMPTS; -import static com.google.cloud.RetryParams.DEFAULT_TOTAL_RETRY_PERIOD_MILLIS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import com.google.cloud.RetryParams.Builder; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.util.Arrays; - -/** - * Tests for {@link RetryParams}. - */ -@RunWith(JUnit4.class) -public class RetryParamsTest { - - @Test - public void testDefaults() { - RetryParams params1 = RetryParams.getDefaultInstance(); - RetryParams params2 = RetryParams.newBuilder().build(); - for (RetryParams params : Arrays.asList(params1, params2)) { - assertEquals(DEFAULT_INITIAL_RETRY_DELAY_MILLIS, params.getInitialRetryDelayMillis()); - assertEquals(DEFAULT_MAX_RETRY_DELAY_MILLIS, params.getMaxRetryDelayMillis()); - assertEquals(DEFAULT_RETRY_DELAY_BACKOFF_FACTOR, params.getRetryDelayBackoffFactor(), 0); - assertEquals(DEFAULT_RETRY_MAX_ATTEMPTS, params.getRetryMaxAttempts()); - assertEquals(DEFAULT_RETRY_MIN_ATTEMPTS, params.getRetryMinAttempts()); - assertEquals(DEFAULT_TOTAL_RETRY_PERIOD_MILLIS, params.getTotalRetryPeriodMillis()); - } - } - - - @Test - public void testSetAndCopy() { - RetryParams.Builder builder = RetryParams.newBuilder(); - builder.setInitialRetryDelayMillis(101); - builder.setMaxRetryDelayMillis(102); - builder.setRetryDelayBackoffFactor(103); - builder.setRetryMinAttempts(107); - builder.setRetryMaxAttempts(108); - builder.setTotalRetryPeriodMillis(109); - RetryParams params1 = builder.build(); - RetryParams params2 = new RetryParams.Builder(params1).build(); - for (RetryParams params : Arrays.asList(params1, params2)) { - assertEquals(101, params.getInitialRetryDelayMillis()); - assertEquals(102, params.getMaxRetryDelayMillis()); - assertEquals(103, params.getRetryDelayBackoffFactor(), 0); - assertEquals(107, params.getRetryMinAttempts()); - assertEquals(108, params.getRetryMaxAttempts()); - assertEquals(109, params.getTotalRetryPeriodMillis()); - } - } - - - @Test - public void testBadSettings() { - RetryParams.Builder builder = RetryParams.newBuilder(); - builder.setInitialRetryDelayMillis(-1); - builder = assertFailure(builder); - builder.setMaxRetryDelayMillis( - RetryParams.getDefaultInstance().getInitialRetryDelayMillis() - 1); - builder = assertFailure(builder); - builder.setRetryDelayBackoffFactor(-1); - builder = assertFailure(builder); - builder.setRetryMinAttempts(-1); - builder = assertFailure(builder); - builder.setRetryMaxAttempts(RetryParams.getDefaultInstance().getRetryMinAttempts() - 1); - builder = assertFailure(builder); - builder.setTotalRetryPeriodMillis(-1); - builder = assertFailure(builder); - // verify that it is OK for min and max to be equal - builder.setRetryMaxAttempts(RetryParams.getDefaultInstance().getRetryMinAttempts()); - builder.setMaxRetryDelayMillis(RetryParams.getDefaultInstance().getInitialRetryDelayMillis()); - builder.build(); - } - - private static Builder assertFailure(Builder builder) { - try { - builder.build(); - fail("Expected IllegalArgumentException"); - } catch (IllegalArgumentException ex) { - // expected - } - return RetryParams.newBuilder(); - } -} diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index d2e2de4f4a..11bdae8b28 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -16,6 +16,7 @@ package com.google.cloud; +import com.google.api.gax.core.RetrySettings; import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor; import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor.ValueType; import com.google.common.collect.ImmutableList; @@ -32,7 +33,7 @@ public class SerializationTest extends BaseSerializationTest { private static final Identity IDENTITY = Identity.allAuthenticatedUsers(); private static final PageImpl PAGE = new PageImpl<>(null, "cursor", ImmutableList.of("string1", "string2")); - private static final RetryParams RETRY_PARAMS = RetryParams.getDefaultInstance(); + private static final RetrySettings RETRY_SETTINGS = ServiceOptions.getDefaultRetrySettings(); private static final Role SOME_ROLE = Role.viewer(); private static final Policy SOME_IAM_POLICY = Policy.newBuilder().build(); private static final WaitForOption CHECKING_PERIOD = @@ -43,10 +44,12 @@ public class SerializationTest extends BaseSerializationTest { MonitoredResourceDescriptor.newBuilder("global") .setLabels(ImmutableList.of(LABEL_DESCRIPTOR)) .build(); - private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.newBuilder("global") - .setLabels(ImmutableMap.of("project_id", "project")) - .build(); - private static final String JSON_KEY = "{\n" + private static final MonitoredResource MONITORED_RESOURCE = + MonitoredResource.newBuilder("global") + .setLabels(ImmutableMap.of("project_id", "project")) + .build(); + private static final String JSON_KEY = + "{\n" + " \"private_key_id\": \"somekeyid\",\n" + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" + "kAgEAAoIBAQC+K2hSuFpAdrJI\\nnCgcDz2M7t7bjdlsadsasad+fvRSW6TjNQZ3p5LLQY1kSZRqBqylRkzteMOyHg" @@ -75,9 +78,19 @@ public class SerializationTest extends BaseSerializationTest { @Override protected Serializable[] serializableObjects() { - return new Serializable[]{BASE_SERVICE_EXCEPTION, EXCEPTION_HANDLER, IDENTITY, PAGE, - RETRY_PARAMS, SOME_ROLE, SOME_IAM_POLICY, CHECKING_PERIOD, LABEL_DESCRIPTOR, - MONITORED_RESOURCE_DESCRIPTOR, MONITORED_RESOURCE}; + return new Serializable[] { + BASE_SERVICE_EXCEPTION, + EXCEPTION_HANDLER, + IDENTITY, + PAGE, + RETRY_SETTINGS, + SOME_ROLE, + SOME_IAM_POLICY, + CHECKING_PERIOD, + LABEL_DESCRIPTOR, + MONITORED_RESOURCE_DESCRIPTOR, + MONITORED_RESOURCE + }; } @Override diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 22c230e8d4..3ef3f21e3c 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.google.api.gax.core.ApiClock; +import com.google.api.gax.core.CurrentMillisClock; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; @@ -38,33 +40,34 @@ public class ServiceOptionsTest { private static final String JSON_KEY = "{\n" - + " \"private_key_id\": \"somekeyid\",\n" - + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" - + "kAgEAAoIBAQC+K2hSuFpAdrJI\\nnCgcDz2M7t7bjdlsadsasad+fvRSW6TjNQZ3p5LLQY1kSZRqBqylRkzteMOyHg" - + "aR\\n0Pmxh3ILCND5men43j3h4eDbrhQBuxfEMalkG92sL+PNQSETY2tnvXryOvmBRwa/\\nQP/9dJfIkIDJ9Fw9N4" - + "Bhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nknddadwkwewcVxHFhcZJO+XWf6ofLUXpRwiTZakGMn8EE1uVa2" - + "LgczOjwWHGi99MFjxSer5m9\\n1tCa3/KEGKiS/YL71JvjwX3mb+cewlkcmweBKZHM2JPTk0ZednFSpVZMtycjkbLa" - + "\\ndYOS8V85AgMBewECggEBAKksaldajfDZDV6nGqbFjMiizAKJolr/M3OQw16K6o3/\\n0S31xIe3sSlgW0+UbYlF" - + "4U8KifhManD1apVSC3csafaspP4RZUHFhtBywLO9pR5c\\nr6S5aLp+gPWFyIp1pfXbWGvc5VY/v9x7ya1VEa6rXvL" - + "sKupSeWAW4tMj3eo/64ge\\nsdaceaLYw52KeBYiT6+vpsnYrEkAHO1fF/LavbLLOFJmFTMxmsNaG0tuiJHgjshB\\" - + "n82DpMCbXG9YcCgI/DbzuIjsdj2JC1cascSP//3PmefWysucBQe7Jryb6NQtASmnv\\nCdDw/0jmZTEjpe4S1lxfHp" - + "lAhHFtdgYTvyYtaLZiVVkCgYEA8eVpof2rceecw/I6\\n5ng1q3Hl2usdWV/4mZMvR0fOemacLLfocX6IYxT1zA1FF" - + "JlbXSRsJMf/Qq39mOR2\\nSpW+hr4jCoHeRVYLgsbggtrevGmILAlNoqCMpGZ6vDmJpq6ECV9olliDvpPgWOP+\\nm" - + "YPDreFBGxWvQrADNbRt2dmGsrsCgYEAyUHqB2wvJHFqdmeBsaacewzV8x9WgmeX\\ngUIi9REwXlGDW0Mz50dxpxcK" - + "CAYn65+7TCnY5O/jmL0VRxU1J2mSWyWTo1C+17L0\\n3fUqjxL1pkefwecxwecvC+gFFYdJ4CQ/MHHXU81Lwl1iWdF" - + "Cd2UoGddYaOF+KNeM\\nHC7cmqra+JsCgYEAlUNywzq8nUg7282E+uICfCB0LfwejuymR93CtsFgb7cRd6ak\\nECR" - + "8FGfCpH8ruWJINllbQfcHVCX47ndLZwqv3oVFKh6pAS/vVI4dpOepP8++7y1u\\ncoOvtreXCX6XqfrWDtKIvv0vjl" - + "HBhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nkndj5uNl5SiuVxHFhcZJO+XWf6ofLUregtevZakGMn8EE1uVa" - + "2AY7eafmoU/nZPT\\n00YB0TBATdCbn/nBSuKDESkhSg9s2GEKQZG5hBmL5uCMfo09z3SfxZIhJdlerreP\\nJ7gSi" - + "dI12N+EZxYd4xIJh/HFDgp7RRO87f+WJkofMQKBgGTnClK1VMaCRbJZPriw\\nEfeFCoOX75MxKwXs6xgrw4W//AYG" - + "GUjDt83lD6AZP6tws7gJ2IwY/qP7+lyhjEqN\\nHtfPZRGFkGZsdaksdlaksd323423d+15/UvrlRSFPNj1tWQmNKk" - + "XyRDW4IG1Oa2p\\nrALStNBx5Y9t0/LQnFI4w3aG\\n-----END PRIVATE KEY-----\\n\",\n" - + " \"client_email\": \"someclientid@developer.gserviceaccount.com\",\n" - + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" - + " \"type\": \"service_account\"\n" - + "}"; + + " \"private_key_id\": \"somekeyid\",\n" + + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" + + "kAgEAAoIBAQC+K2hSuFpAdrJI\\nnCgcDz2M7t7bjdlsadsasad+fvRSW6TjNQZ3p5LLQY1kSZRqBqylRkzteMOyHg" + + "aR\\n0Pmxh3ILCND5men43j3h4eDbrhQBuxfEMalkG92sL+PNQSETY2tnvXryOvmBRwa/\\nQP/9dJfIkIDJ9Fw9N4" + + "Bhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nknddadwkwewcVxHFhcZJO+XWf6ofLUXpRwiTZakGMn8EE1uVa2" + + "LgczOjwWHGi99MFjxSer5m9\\n1tCa3/KEGKiS/YL71JvjwX3mb+cewlkcmweBKZHM2JPTk0ZednFSpVZMtycjkbLa" + + "\\ndYOS8V85AgMBewECggEBAKksaldajfDZDV6nGqbFjMiizAKJolr/M3OQw16K6o3/\\n0S31xIe3sSlgW0+UbYlF" + + "4U8KifhManD1apVSC3csafaspP4RZUHFhtBywLO9pR5c\\nr6S5aLp+gPWFyIp1pfXbWGvc5VY/v9x7ya1VEa6rXvL" + + "sKupSeWAW4tMj3eo/64ge\\nsdaceaLYw52KeBYiT6+vpsnYrEkAHO1fF/LavbLLOFJmFTMxmsNaG0tuiJHgjshB\\" + + "n82DpMCbXG9YcCgI/DbzuIjsdj2JC1cascSP//3PmefWysucBQe7Jryb6NQtASmnv\\nCdDw/0jmZTEjpe4S1lxfHp" + + "lAhHFtdgYTvyYtaLZiVVkCgYEA8eVpof2rceecw/I6\\n5ng1q3Hl2usdWV/4mZMvR0fOemacLLfocX6IYxT1zA1FF" + + "JlbXSRsJMf/Qq39mOR2\\nSpW+hr4jCoHeRVYLgsbggtrevGmILAlNoqCMpGZ6vDmJpq6ECV9olliDvpPgWOP+\\nm" + + "YPDreFBGxWvQrADNbRt2dmGsrsCgYEAyUHqB2wvJHFqdmeBsaacewzV8x9WgmeX\\ngUIi9REwXlGDW0Mz50dxpxcK" + + "CAYn65+7TCnY5O/jmL0VRxU1J2mSWyWTo1C+17L0\\n3fUqjxL1pkefwecxwecvC+gFFYdJ4CQ/MHHXU81Lwl1iWdF" + + "Cd2UoGddYaOF+KNeM\\nHC7cmqra+JsCgYEAlUNywzq8nUg7282E+uICfCB0LfwejuymR93CtsFgb7cRd6ak\\nECR" + + "8FGfCpH8ruWJINllbQfcHVCX47ndLZwqv3oVFKh6pAS/vVI4dpOepP8++7y1u\\ncoOvtreXCX6XqfrWDtKIvv0vjl" + + "HBhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nkndj5uNl5SiuVxHFhcZJO+XWf6ofLUregtevZakGMn8EE1uVa" + + "2AY7eafmoU/nZPT\\n00YB0TBATdCbn/nBSuKDESkhSg9s2GEKQZG5hBmL5uCMfo09z3SfxZIhJdlerreP\\nJ7gSi" + + "dI12N+EZxYd4xIJh/HFDgp7RRO87f+WJkofMQKBgGTnClK1VMaCRbJZPriw\\nEfeFCoOX75MxKwXs6xgrw4W//AYG" + + "GUjDt83lD6AZP6tws7gJ2IwY/qP7+lyhjEqN\\nHtfPZRGFkGZsdaksdlaksd323423d+15/UvrlRSFPNj1tWQmNKk" + + "XyRDW4IG1Oa2p\\nrALStNBx5Y9t0/LQnFI4w3aG\\n-----END PRIVATE KEY-----\\n\",\n" + + " \"client_email\": \"someclientid@developer.gserviceaccount.com\",\n" + + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" + + " \"type\": \"service_account\"\n" + + "}"; private static final InputStream JSON_KEY_STREAM = new ByteArrayInputStream(JSON_KEY.getBytes()); private static GoogleCredentials credentials; + static { try { credentials = GoogleCredentials.fromStream(JSON_KEY_STREAM); @@ -72,14 +75,15 @@ public class ServiceOptionsTest { fail("Couldn't create fake JSON credentials."); } } - private static final Clock TEST_CLOCK = new TestClock(); + + private static final ApiClock TEST_CLOCK = new TestClock(); private static final TestServiceOptions OPTIONS = TestServiceOptions.newBuilder() .setCredentials(credentials) .setClock(TEST_CLOCK) .setHost("host") .setProjectId("project-id") - .setRetryParams(RetryParams.noRetries()) + .setRetrySettings(ServiceOptions.getNoRetrySettings()) .build(); private static final TestServiceOptions OPTIONS_NO_CREDENTIALS = TestServiceOptions.newBuilder() @@ -87,7 +91,7 @@ public class ServiceOptionsTest { .setClock(TEST_CLOCK) .setHost("host") .setProjectId("project-id") - .setRetryParams(RetryParams.noRetries()) + .setRetrySettings(ServiceOptions.getNoRetrySettings()) .build(); private static final TestServiceOptions DEFAULT_OPTIONS = TestServiceOptions.newBuilder().setProjectId("project-id").build(); @@ -96,20 +100,24 @@ public class ServiceOptionsTest { private static final Pattern APPLICATION_NAME_PATTERN = Pattern.compile(LIBRARY_NAME + "(/[0-9]+.[0-9]+.[0-9]+)?"); - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule public ExpectedException thrown = ExpectedException.none(); + + private static class TestClock implements ApiClock { + @Override + public long nanoTime() { + return 123_456_789_000_000L; + } - private static class TestClock extends Clock { @Override - public long millis() { - return 123456789L; + public long millisTime() { + return 123_456_789L; } } private interface TestService extends Service {} - private static class TestServiceImpl - extends BaseService implements TestService { + private static class TestServiceImpl extends BaseService + implements TestService { private TestServiceImpl(TestServiceOptions options) { super(options); } @@ -215,10 +223,11 @@ public void testBuilder() { assertSame(TEST_CLOCK, OPTIONS.getClock()); assertEquals("host", OPTIONS.getHost()); assertEquals("project-id", OPTIONS.getProjectId()); - assertSame(RetryParams.noRetries(), OPTIONS.getRetryParams()); - assertSame(Clock.defaultClock(), DEFAULT_OPTIONS.getClock()); + assertSame(ServiceOptions.getNoRetrySettings(), + OPTIONS.getRetrySettings()); + assertSame(CurrentMillisClock.getDefaultClock(), DEFAULT_OPTIONS.getClock()); assertEquals("https://www.googleapis.com", DEFAULT_OPTIONS.getHost()); - assertSame(RetryParams.getDefaultInstance(), DEFAULT_OPTIONS.getRetryParams()); + assertSame(ServiceOptions.getDefaultRetrySettings(), DEFAULT_OPTIONS.getRetrySettings()); } @Test @@ -227,7 +236,7 @@ public void testBuilderNoCredentials() { assertSame(TEST_CLOCK, OPTIONS_NO_CREDENTIALS.getClock()); assertEquals("host", OPTIONS_NO_CREDENTIALS.getHost()); assertEquals("project-id", OPTIONS_NO_CREDENTIALS.getProjectId()); - assertSame(RetryParams.noRetries(), OPTIONS_NO_CREDENTIALS.getRetryParams()); + assertSame(ServiceOptions.getNoRetrySettings(), OPTIONS_NO_CREDENTIALS.getRetrySettings()); } @Test From 04a9bcccbcc50eb0ab5a1f36fd457076f3cd9af0 Mon Sep 17 00:00:00 2001 From: Vikas Kedia Date: Wed, 22 Mar 2017 11:45:49 -0700 Subject: [PATCH 306/663] Move some classes from spanner to core (#1770) * Moved Date,Timestamp to google-cloud-core Removed ByteArrays and moved the corresponding methods into ByteArray. ByteArray already has a decent toString so removed the toString from ByteArrays. * Undo session pool test changes --- google-cloud-core/pom.xml | 17 ++ .../main/java/com/google/cloud/ByteArray.java | 12 ++ .../src/main/java/com/google/cloud/Date.java | 119 +++++++++++ .../main/java/com/google/cloud/Timestamp.java | 186 ++++++++++++++++++ .../test/java/com/google/cloud/DateTest.java | 76 +++++++ .../java/com/google/cloud/TimestampTest.java | 169 ++++++++++++++++ 6 files changed, 579 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/Date.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/Timestamp.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/DateTest.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 950d5dce9e..d0ea8bec13 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -115,6 +115,11 @@ protobuf-java 3.0.0 + + com.google.protobuf + protobuf-java-util + 3.0.0 + io.grpc grpc-protobuf @@ -153,5 +158,17 @@ + + com.google.truth + truth + 0.30 + test + + + com.google.guava + guava-testlib + 19.0 + test + diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java index b92b0bac29..8b83a1e4b2 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -18,6 +18,7 @@ import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.io.BaseEncoding; import com.google.protobuf.ByteString; import java.io.IOException; @@ -33,6 +34,7 @@ public class ByteArray implements Iterable, Serializable { private static final long serialVersionUID = -1908809133893782840L; + private static final BaseEncoding encoder = BaseEncoding.base64(); private final ByteString byteString; @@ -94,6 +96,11 @@ public final String toStringUtf8() { return byteString.toStringUtf8(); } + /** Converts this byte array to its base64 representation. */ + public final String toBase64() { + return encoder.encode(toByteArray()); + } + /** * Returns the content of this {@code ByteArray} as a read-only {@link ByteBuffer}. */ @@ -162,4 +169,9 @@ public static final ByteArray copyFrom(ByteBuffer bytes) { public static final ByteArray copyFrom(InputStream input) throws IOException { return new ByteArray(ByteString.readFrom(input)); } + + /** Creates a {@code ByteArray} from a base64 representation. */ + public static ByteArray fromBase64(String data) { + return ByteArray.copyFrom(encoder.decode(data)); + } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/Date.java b/google-cloud-core/src/main/java/com/google/cloud/Date.java new file mode 100644 index 0000000000..a11d259df7 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/Date.java @@ -0,0 +1,119 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.common.base.Preconditions; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Represents a Date without time, such as 2017-03-17. Date is timezone independent. + */ +public final class Date implements Comparable { + + // Date format "yyyy-mm-dd" + private static final Pattern FORMAT_REGEXP = Pattern.compile("(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)"); + private final int year; + private final int month; + private final int dayOfMonth; + + private Date(int year, int month, int dayOfMonth) { + Preconditions.checkArgument(year > 0, "Invalid year: " + year); + Preconditions.checkArgument(month > 0 && month <= 12, "Invalid month: " + month); + Preconditions.checkArgument(dayOfMonth > 0 && dayOfMonth <= 31, "Invalid day: " + dayOfMonth); + this.year = year; + this.month = month; + this.dayOfMonth = dayOfMonth; + } + + /** + * Constructs a new Date instance. + * + * @param year must be greater than 0 + * @param month must be between [1,12] + * @param dayOfMonth must be between [1,31] + */ + public static Date fromYearMonthDay(int year, int month, int dayOfMonth) { + return new Date(year, month, dayOfMonth); + } + + /** @param date Data in RFC 3339 date format (yyyy-mm-dd). */ + public static Date parseDate(String date) { + Matcher matcher = FORMAT_REGEXP.matcher(date); + if (!matcher.matches()) { + throw new IllegalArgumentException("Invalid date: " + date); + } + int year = Integer.parseInt(matcher.group(1)); + int month = Integer.parseInt(matcher.group(2)); + int dayOfMonth = Integer.parseInt(matcher.group(3)); + return new Date(year, month, dayOfMonth); + } + + /** Returns the year. */ + public int getYear() { + return year; + } + + /** Returns the month between 1 and 12 inclusive. */ + public int getMonth() { + return month; + } + + /** Returns day of month between 1 and 31 inclusive. */ + public int getDayOfMonth() { + return dayOfMonth; + } + + @Override + public String toString() { + return String.format("%04d-%02d-%02d", year, month, dayOfMonth); + } + + StringBuilder toString(StringBuilder b) { + return b.append(toString()); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Date that = (Date) o; + return year == that.year && month == that.month && dayOfMonth == that.dayOfMonth; + } + + @Override + public int hashCode() { + return Objects.hash(year, month, dayOfMonth); + } + + @Override + public int compareTo(Date other) { + int r = Integer.compare(year, other.year); + if (r == 0) { + r = Integer.compare(month, other.month); + if (r == 0) { + r = Integer.compare(dayOfMonth, other.dayOfMonth); + } + } + return r; + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java new file mode 100644 index 0000000000..aedb802f58 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -0,0 +1,186 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.base.Strings; +import com.google.protobuf.util.Timestamps; +import java.util.Objects; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.joda.time.chrono.GregorianChronology; +import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.ISODateTimeFormat; + +/** + * Represents a timestamp with nanosecond precision. Timestamps cover the range + * [0001-01-01, 9999-12-31]. + * + *

    {@code Timestamp} instances are immutable. + */ +public final class Timestamp implements Comparable { + /** The smallest legal timestamp ("0001-01-01T00:00:00Z"). */ + public static final Timestamp MIN_VALUE = new Timestamp(-62135596800L, 0); + + /** The largest legal timestamp ("9999-12-31T23:59:59Z"). */ + public static final Timestamp MAX_VALUE = + new Timestamp(253402300799L, (int) TimeUnit.SECONDS.toNanos(1) - 1); + + /** Regexp to split timestamps into date-hour-minute-second and fractional second components. */ + private static final Pattern FORMAT_REGEXP = Pattern.compile("([^\\.]*)(\\.\\d{0,9})?Z"); + + private static final long NANOS_PER_SECOND = TimeUnit.SECONDS.toNanos(1); + + private static final DateTimeFormatter format = + ISODateTimeFormat.dateHourMinuteSecond().withChronology(GregorianChronology.getInstanceUTC()); + + private final long seconds; + private final int nanos; + + private Timestamp(long seconds, int nanos) { + this.seconds = seconds; + this.nanos = nanos; + } + + /** + * Creates an instance representing the value of {@code seconds} and {@code nanos} since January + * 1, 1970, 00:00:00 UTC. + * + * @param seconds seconds since January 1, 1970, 00:00:00 UTC. A negative value is the number of + * seconds before January 1, 1970, 00:00:00 UTC. + * @param nanos the fractional seconds component, in the range 0..999999999. + * @throws IllegalArgumentException if the timestamp is outside the representable range + */ + public static Timestamp ofTimeSecondsAndNanos(long seconds, int nanos) { + checkArgument( + Timestamps.isValid(seconds, nanos), "timestamp out of range: %s, %s", seconds, nanos); + return new Timestamp(seconds, nanos); + } + + /** + * Creates an instance representing the value of {@code timestamp}. + * + * @throws IllegalArgumentException if the timestamp is outside the representable range + */ + public static Timestamp of(java.sql.Timestamp timestamp) { + return ofTimeSecondsAndNanos(timestamp.getTime() / 1000, timestamp.getNanos()); + } + + /** + * Returns the number of seconds since January 1, 1970, 00:00:00 UTC. A negative value is the + * number of seconds before January 1, 1970, 00:00:00 UTC. + */ + public long getSeconds() { + return seconds; + } + + /** Returns the fractional seconds component, in nanoseconds. */ + public int getNanos() { + return nanos; + } + + /** Returns a JDBC timestamp initialized to the same point in time as {@code this}. */ + public java.sql.Timestamp toSqlTimestamp() { + java.sql.Timestamp ts = new java.sql.Timestamp(seconds * 1000); + ts.setNanos(nanos); + return ts; + } + + @Override + public int compareTo(Timestamp other) { + int r = Long.compare(seconds, other.seconds); + if (r == 0) { + r = Integer.compare(nanos, other.nanos); + } + return r; + } + + /** + * Creates an instance of Timestamp from {@code com.google.protobuf.Timestamp}. + */ + public static Timestamp fromProto(com.google.protobuf.Timestamp proto) { + return new Timestamp(proto.getSeconds(), proto.getNanos()); + } + + /** + * Returns a {@code com.google.protobuf.Timestamp} initialized to the same point in time as {@code + * this}. + */ + public com.google.protobuf.Timestamp toProto() { + return com.google.protobuf.Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build(); + } + + /** + * Creates a Timestamp instance from the given string. String is in the RFC 3339 format without + * the timezone offset (always ends in "Z"). + */ + public static Timestamp parseTimestamp(String timestamp) { + Matcher matcher = FORMAT_REGEXP.matcher(timestamp); + if (!matcher.matches()) { + throw new IllegalArgumentException("Cannot parse input: " + timestamp); + } + String secondsPart = matcher.group(1); + String nanosPart = matcher.group(2); + long seconds; + seconds = format.parseMillis(secondsPart) / 1000; + int nanos = 0; + if (nanosPart != null) { + String padded = Strings.padEnd(nanosPart.substring(1), 9, '0'); + nanos = Integer.parseInt(padded); + if (nanos >= TimeUnit.SECONDS.toNanos(1)) { + throw new IllegalArgumentException( + "Cannot parse input: " + timestamp + " (nanos out of range)"); + } + } + return ofTimeSecondsAndNanos(seconds, nanos); + } + + StringBuilder toString(StringBuilder b) { + format.printTo(b, seconds * 1000); + if (nanos != 0) { + b.append(String.format(".%09d", nanos)); + } + b.append('Z'); + return b; + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Timestamp that = (Timestamp) o; + return seconds == that.seconds && nanos == that.nanos; + } + + @Override + public int hashCode() { + return Objects.hash(seconds, nanos); + } + + // TODO(user): Consider adding math operations. +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java new file mode 100644 index 0000000000..627b1adc10 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java @@ -0,0 +1,76 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.common.testing.EqualsTester; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link Date}. */ +@RunWith(JUnit4.class) +public class DateTest { + + @Test + public void parseDate() { + Date date = Date.parseDate("2016-09-18"); + assertThat(date.getYear()).isEqualTo(2016); + assertThat(date.getMonth()).isEqualTo(9); + assertThat(date.getDayOfMonth()).isEqualTo(18); + } + + @Test + public void testToString() { + Date date = Date.fromYearMonthDay(10, 9, 5); + assertThat(date.toString()).isEqualTo("0010-09-05"); + date = Date.fromYearMonthDay(2016, 12, 31); + assertThat(date.toString()).isEqualTo("2016-12-31"); + date = Date.fromYearMonthDay(1, 1, 1); + assertThat(date.toString()).isEqualTo("0001-01-01"); + } + + @Test + public void equalAndHashCode() { + Date d1 = Date.fromYearMonthDay(2016, 9, 18); + Date d2 = Date.fromYearMonthDay(2016, 9, 18); + Date d3 = Date.fromYearMonthDay(2016, 9, 19); + EqualsTester tester = new EqualsTester(); + tester.addEqualityGroup(d1, d2); + tester.addEqualityGroup(d3); + } + + @Test + public void validOrdering() { + Date d1 = Date.fromYearMonthDay(2016, 9, 18); + Date d2 = Date.fromYearMonthDay(2016, 9, 19); + Date d3 = Date.fromYearMonthDay(2016, 9, 20); + Date d4 = Date.fromYearMonthDay(2016, 10, 1); + Date d5 = Date.fromYearMonthDay(2017, 1, 1); + assertDescending(d5, d4, d3, d2, d1); + } + + private void assertDescending(Date... dates) { + for (int i = 0; i < dates.length - 1; i++) { + assertThat(dates[i]).isEquivalentAccordingToCompareTo(dates[i]); + for (int j = i + 1; j < dates.length; j++) { + assertThat(dates[i]).isGreaterThan(dates[j]); + } + } + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java new file mode 100644 index 0000000000..0513bc8fea --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java @@ -0,0 +1,169 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.common.testing.EqualsTester; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link com.google.cloud.Timestamp}. */ +@RunWith(JUnit4.class) +public class TimestampTest { + private static final String TEST_TIME_ISO = "2015-10-12T15:14:54Z"; + private static final long TEST_TIME_SECONDS = 1444662894L; + @Rule public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void minValue() { + // MIN_VALUE is before the start of the Gregorian calendar... use magic value. + assertThat(Timestamp.MIN_VALUE.getSeconds()).isEqualTo(-62135596800L); + assertThat(Timestamp.MIN_VALUE.getNanos()).isEqualTo(0); + } + + @Test + public void maxValue() { + TimeZone tz = TimeZone.getTimeZone("UTC"); + GregorianCalendar calendar = new GregorianCalendar(tz); + calendar.set(9999, Calendar.DECEMBER, 31, 23, 59, 59); + java.sql.Timestamp expectedMin = new java.sql.Timestamp(calendar.getTimeInMillis()); + expectedMin.setNanos(999999999); + + assertThat(Timestamp.MAX_VALUE.getSeconds()).isEqualTo(calendar.getTimeInMillis() / 1000L); + assertThat(Timestamp.MAX_VALUE.getNanos()).isEqualTo(999999999); + } + + @Test + public void toFromSqlTimestamp() { + long seconds = TEST_TIME_SECONDS; + int nanos = 500000000; + + java.sql.Timestamp sqlTs = new java.sql.Timestamp(seconds * 1000); + sqlTs.setNanos(nanos); + + Timestamp ts = Timestamp.of(sqlTs); + assertThat(ts.getSeconds()).isEqualTo(seconds); + assertThat(ts.getNanos()).isEqualTo(nanos); + + assertThat(ts.toSqlTimestamp()).isEqualTo(sqlTs); + } + + @Test + public void boundsSecondsMin() { + expectedException.expect(IllegalArgumentException.class); + Timestamp.ofTimeSecondsAndNanos(Timestamp.MIN_VALUE.getSeconds() - 1, 999999999); + } + + @Test + public void boundsSecondsMax() { + expectedException.expect(IllegalArgumentException.class); + Timestamp.ofTimeSecondsAndNanos(Timestamp.MAX_VALUE.getSeconds() + 1, 0); + } + + @Test + public void boundsNanosMin() { + expectedException.expect(IllegalArgumentException.class); + Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, -1); + } + + @Test + public void boundsNanosMax() { + expectedException.expect(IllegalArgumentException.class); + Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 1000000000); + } + + @Test + public void boundsSqlTimestampMin() { + expectedException.expect(IllegalArgumentException.class); + Timestamp.of(new java.sql.Timestamp((Timestamp.MIN_VALUE.getSeconds() - 1) * 1000)); + } + + @Test + public void boundsSqlTimestampMax() { + expectedException.expect(IllegalArgumentException.class); + Timestamp.of(new java.sql.Timestamp((Timestamp.MAX_VALUE.getSeconds() + 1) * 1000)); + } + + @Test + public void equalsAndHashCode() { + EqualsTester tester = new EqualsTester(); + tester.addEqualityGroup( + Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0), + Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0), + Timestamp.of(new java.sql.Timestamp(TEST_TIME_SECONDS * 1000))); + tester.addEqualityGroup(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS + 1, 0)); + tester.addEqualityGroup(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 1)); + tester.testEquals(); + } + + @Test + public void testToString() { + assertThat(Timestamp.MIN_VALUE.toString()).isEqualTo("0001-01-01T00:00:00Z"); + assertThat(Timestamp.MAX_VALUE.toString()).isEqualTo("9999-12-31T23:59:59.999999999Z"); + assertThat(Timestamp.ofTimeSecondsAndNanos(0, 0).toString()).isEqualTo("1970-01-01T00:00:00Z"); + assertThat(Timestamp.ofTimeSecondsAndNanos(0, 100).toString()) + .isEqualTo("1970-01-01T00:00:00.000000100Z"); + assertThat(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0).toString()) + .isEqualTo(TEST_TIME_ISO); + } + + @Test + public void parseTimestamp() { + assertThat(Timestamp.parseTimestamp("0001-01-01T00:00:00Z")).isEqualTo(Timestamp.MIN_VALUE); + assertThat(Timestamp.parseTimestamp("9999-12-31T23:59:59.999999999Z")) + .isEqualTo(Timestamp.MAX_VALUE); + assertThat(Timestamp.parseTimestamp(TEST_TIME_ISO)) + .isEqualTo(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0)); + } + + @Test + public void fromProto() { + com.google.protobuf.Timestamp proto = + com.google.protobuf.Timestamp.newBuilder().setSeconds(1234).setNanos(567).build(); + Timestamp timestamp = Timestamp.fromProto(proto); + assertThat(timestamp.getSeconds()).isEqualTo(1234); + assertThat(timestamp.getNanos()).isEqualTo(567); + } + + @Test + public void comparable() { + assertThat(Timestamp.MIN_VALUE).isLessThan(Timestamp.MAX_VALUE); + assertThat(Timestamp.MAX_VALUE).isGreaterThan(Timestamp.MIN_VALUE); + + assertThat(Timestamp.ofTimeSecondsAndNanos(100, 0)) + .isAtLeast(Timestamp.ofTimeSecondsAndNanos(100, 0)); + assertThat(Timestamp.ofTimeSecondsAndNanos(100, 0)) + .isAtMost(Timestamp.ofTimeSecondsAndNanos(100, 0)); + + assertThat(Timestamp.ofTimeSecondsAndNanos(100, 1000)) + .isLessThan(Timestamp.ofTimeSecondsAndNanos(101, 0)); + assertThat(Timestamp.ofTimeSecondsAndNanos(100, 1000)) + .isAtMost(Timestamp.ofTimeSecondsAndNanos(101, 0)); + + assertThat(Timestamp.ofTimeSecondsAndNanos(101, 0)) + .isGreaterThan(Timestamp.ofTimeSecondsAndNanos(100, 1000)); + assertThat(Timestamp.ofTimeSecondsAndNanos(101, 0)) + .isAtLeast(Timestamp.ofTimeSecondsAndNanos(100, 1000)); + } +} From f2a39f1aafd673348d3ca2782f7d5a8e254b2fd6 Mon Sep 17 00:00:00 2001 From: David Xia Date: Thu, 23 Mar 2017 10:44:00 -0400 Subject: [PATCH 307/663] Fix links in READMEs (#1794) [ci skip] Use Markdown formatting that creates links. --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index c7cfe230a4..ea1b3d922c 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -9,8 +9,8 @@ This module provides common functionality required by service-specific modules o [![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) [![Dependency Status](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969) -- [Homepage] (https://googlecloudplatform.github.io/google-cloud-java/) -- [API Documentation] (https://googlecloudplatform.github.io/google-cloud-java/apidocs/index.html?com/google/cloud/package-summary.html) +- [Homepage](https://googlecloudplatform.github.io/google-cloud-java/) +- [API Documentation](https://googlecloudplatform.github.io/google-cloud-java/apidocs/index.html?com/google/cloud/package-summary.html) Quickstart ---------- @@ -53,7 +53,7 @@ Please note that this project is released with a Contributor Code of Conduct. By Versioning ---------- -This library follows [Semantic Versioning] (http://semver.org/). +This library follows [Semantic Versioning](http://semver.org/). It is currently in major version zero (``0.y.z``), which means that anything may change at any time and the public API should not be considered From 760e8e5149255de2748391cbb8ba0298a0d2f487 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Thu, 23 Mar 2017 12:31:42 -0700 Subject: [PATCH 308/663] Add x-goog-api-client support to HTTP1.1 (#1790) --- .../com/google/cloud/HttpTransportOptions.java | 17 +++++++++++++++++ .../java/com/google/cloud/ServiceOptions.java | 8 ++++---- .../google/cloud/HttpTransportOptionsTest.java | 9 +++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java index 1ef0276faf..970ca555fe 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java @@ -19,6 +19,7 @@ import static com.google.common.base.MoreObjects.firstNonNull; import com.google.api.client.extensions.appengine.http.UrlFetchTransport; +import com.google.api.client.http.HttpHeaders; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; @@ -154,10 +155,26 @@ public void initialize(HttpRequest httpRequest) throws IOException { if (readTimeout >= 0) { httpRequest.setReadTimeout(readTimeout); } + + HttpHeaders headers = httpRequest.getHeaders(); + headers.set("x-goog-api-client", getXGoogApiClientHeader()); } }; } + String getXGoogApiClientHeader() { + return String.format( + "gl-java/%s %s/%s", + getJavaVersion(), + ServiceOptions.getGoogApiClientLibName(), + ServiceOptions.getLibraryVersion()); + } + + private static String getJavaVersion() { + String javaVersion = Runtime.class.getPackage().getImplementationVersion(); + return javaVersion != null ? javaVersion : ""; + } + /** * Returns the timeout in milliseconds to establish a connection. 0 is an infinite timeout, a * negative number is the default value (20000). diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 843f775eca..55f2c08ac4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -525,7 +525,7 @@ public TransportOptions getTransportOptions() { /** * Returns the application's name as a string in the format {@code gcloud-java/[version]}. */ - public String getApplicationName() { + public static String getApplicationName() { return APPLICATION_NAME; } @@ -533,21 +533,21 @@ public String getApplicationName() { /** * Returns the library's name, {@code gcloud-java}, as a string. */ - public String getLibraryName() { + public static String getLibraryName() { return LIBRARY_NAME; } /** * Returns the library's name used by x-goog-api-client header as a string. */ - public String getGoogApiClientLibName() { + public static String getGoogApiClientLibName() { return X_GOOGLE_CLIENT_HEADER_NAME; } /** * Returns the library's version as a string. */ - public String getLibraryVersion() { + public static String getLibraryVersion() { return LIBRARY_VERSION; } diff --git a/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java index f5013181b2..23a2c10a50 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java @@ -23,6 +23,7 @@ import com.google.auth.http.HttpTransportFactory; import com.google.cloud.HttpTransportOptions.DefaultHttpTransportFactory; +import java.util.regex.Pattern; import org.easymock.EasyMock; import org.junit.Test; @@ -60,4 +61,12 @@ public void testBaseHashCode() { assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); } + + @Test + public void testHeader() { + String expectedHeaderPattern = "^gl-java/.* gccl/.*"; + assertTrue(Pattern.compile(expectedHeaderPattern) + .matcher(DEFAULT_OPTIONS.getXGoogApiClientHeader()) + .find()); + } } From bc38be5b6231653db45c88fccf9f6b80203ce00f Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 31 Mar 2017 11:27:31 -0700 Subject: [PATCH 309/663] Release 0.11.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d0ea8bec13..3af09aa304 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.10.1-alpha-SNAPSHOT + 0.11.0-alpha google-cloud-core From 34d96690393ee728cdb4e5b550c2adc3164a1b33 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 31 Mar 2017 11:30:39 -0700 Subject: [PATCH 310/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index ea1b3d922c..028669921c 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.10.0-alpha + 0.11.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.10.0-alpha' +compile 'com.google.cloud:google-cloud-core:0.11.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.10.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.11.0-alpha" ``` Troubleshooting From b843c43540c24d116d7952493cd602b7ba56ba67 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 31 Mar 2017 12:00:01 -0700 Subject: [PATCH 311/663] Update version to 0.11.1-SNAPSHOT (#1843) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3af09aa304..7ad8ab2794 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.11.0-alpha + 0.11.1-alpha-SNAPSHOT google-cloud-core From 636a57973b3426610b1b65fc424450b6ac7ede8e Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 3 Apr 2017 16:35:14 -0700 Subject: [PATCH 312/663] Release 0.11.1 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7ad8ab2794..ab5d45d0b3 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.11.1-alpha-SNAPSHOT + 0.11.1-alpha google-cloud-core From e9f45d766444dc52b03bb8cfa64cde1269072ed3 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 3 Apr 2017 16:38:52 -0700 Subject: [PATCH 313/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 028669921c..8d54a530e9 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.11.0-alpha + 0.11.1-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.11.0-alpha' +compile 'com.google.cloud:google-cloud-core:0.11.1-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.11.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.11.1-alpha" ``` Troubleshooting From 01cc5481e55efeaf58551af2d540bcf2c496600b Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 3 Apr 2017 16:54:35 -0700 Subject: [PATCH 314/663] Update version to 0.11.2-SNAPSHOT (#1852) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index ab5d45d0b3..f80a522c34 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.11.1-alpha + 0.11.2-alpha-SNAPSHOT google-cloud-core From c569f685701f30d3f18dfeaf0613984774c0ca65 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Wed, 5 Apr 2017 02:22:23 -0700 Subject: [PATCH 315/663] Make logging overrides the default channel provider (#1820) --- .../com/google/cloud/GrpcTransportOptions.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java index 0295b00972..b84f03e915 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java @@ -210,23 +210,23 @@ public UnaryCallSettings.Builder getApiCallSettings(RetrySettings retrySettings) } /** - * Returns a channel provider. + * Returns a channel provider from the given default provider. */ - public static ChannelProvider getChannelProvider( - ServiceOptions serviceOptions) { + public static ChannelProvider setUpChannelProvider( + InstantiatingChannelProvider.Builder providerBuilder, ServiceOptions serviceOptions) { HostAndPort hostAndPort = HostAndPort.fromString(serviceOptions.getHost()); - InstantiatingChannelProvider.Builder builder = InstantiatingChannelProvider.newBuilder() - .setServiceAddress(hostAndPort.getHostText()) + providerBuilder.setServiceAddress(hostAndPort.getHostText()) .setPort(hostAndPort.getPort()) - .setClientLibHeader(serviceOptions.getGoogApiClientLibName(), - firstNonNull(serviceOptions.getLibraryVersion(), "")); + .setClientLibHeader(ServiceOptions.getGoogApiClientLibName(), + firstNonNull(ServiceOptions.getLibraryVersion(), "")); Credentials scopedCredentials = serviceOptions.getScopedCredentials(); if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { - builder.setCredentialsProvider(FixedCredentialsProvider.create(scopedCredentials)); + providerBuilder.setCredentialsProvider(FixedCredentialsProvider.create(scopedCredentials)); } - return builder.build(); + return providerBuilder.build(); } + /** * Returns the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value * adjusted according to {@link #getTimeoutMultiplier()}. Default value is 20000. From 9dfd65ddb1a434138704caf3e9681e59bb0d150c Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Wed, 5 Apr 2017 15:02:57 -0700 Subject: [PATCH 316/663] Release 0.11.2 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f80a522c34..a76e07378d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.11.2-alpha-SNAPSHOT + 0.11.2-alpha google-cloud-core From a0180b090fc650b6b1432a1c2b1fb343b047917b Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Wed, 5 Apr 2017 15:13:26 -0700 Subject: [PATCH 317/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 8d54a530e9..5802dcfb0e 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.11.1-alpha + 0.11.2-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.11.1-alpha' +compile 'com.google.cloud:google-cloud-core:0.11.2-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.11.1-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.11.2-alpha" ``` Troubleshooting From 1298aa6dc90ff07272dbb268abe54c2174c10f7e Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Wed, 5 Apr 2017 16:14:54 -0700 Subject: [PATCH 318/663] Update pom.xml version to 0.11.3-SNAPSHOT (#1870) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a76e07378d..4c3ed7b8d4 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.11.2-alpha + 0.11.3-alpha-SNAPSHOT google-cloud-core From de6349b7ddba798f4a941a447446549a661829d1 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 7 Apr 2017 15:29:51 +1000 Subject: [PATCH 319/663] remove last use of setPort/setServiceAddress (#1880) Fixes #1835. --- .../src/main/java/com/google/cloud/GrpcTransportOptions.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java index b84f03e915..f27ace8b01 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java @@ -214,9 +214,7 @@ public UnaryCallSettings.Builder getApiCallSettings(RetrySettings retrySettings) */ public static ChannelProvider setUpChannelProvider( InstantiatingChannelProvider.Builder providerBuilder, ServiceOptions serviceOptions) { - HostAndPort hostAndPort = HostAndPort.fromString(serviceOptions.getHost()); - providerBuilder.setServiceAddress(hostAndPort.getHostText()) - .setPort(hostAndPort.getPort()) + providerBuilder.setEndpoint(serviceOptions.getHost()) .setClientLibHeader(ServiceOptions.getGoogApiClientLibName(), firstNonNull(ServiceOptions.getLibraryVersion(), "")); Credentials scopedCredentials = serviceOptions.getScopedCredentials(); From 3866e3adf5b170b0c5d4ff333a88d1a5e3285063 Mon Sep 17 00:00:00 2001 From: vam Date: Fri, 7 Apr 2017 10:41:21 -0700 Subject: [PATCH 320/663] Release 0.12.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4c3ed7b8d4..b8e4aa6580 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.11.3-alpha-SNAPSHOT + 0.12.0-alpha google-cloud-core From 2a0c17430d75cead7edadd01cf06a05861ae4ade Mon Sep 17 00:00:00 2001 From: vam Date: Fri, 7 Apr 2017 10:44:37 -0700 Subject: [PATCH 321/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 5802dcfb0e..60076c965e 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.11.2-alpha + 0.12.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.11.2-alpha' +compile 'com.google.cloud:google-cloud-core:0.12.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.11.2-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.12.0-alpha" ``` Troubleshooting From 382187f193644acc262b0917f9f0981a4604c3e6 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Fri, 7 Apr 2017 11:43:44 -0700 Subject: [PATCH 322/663] Update version to 0.12.1-SNAPSHOT (#1886) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b8e4aa6580..332beece16 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.12.0-alpha + 0.12.1-alpha-SNAPSHOT google-cloud-core From b99eb1a6c3e1f91a2ec6ee2e803ed2fe7c25dd67 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Tue, 11 Apr 2017 11:40:56 -0700 Subject: [PATCH 323/663] Don't use `UrlFetchTransport` in App Engine Flex environment (#1893) * Don't use `UrlFetchTransport` in App Engine Flex environment https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1492 --- .../src/main/java/com/google/cloud/HttpTransportOptions.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java index 970ca555fe..9308704eb1 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java @@ -50,8 +50,9 @@ public static class DefaultHttpTransportFactory implements HttpTransportFactory @Override public HttpTransport create() { - // Consider App Engine - if (ServiceOptions.getAppEngineAppId() != null) { + // Consider App Engine Standard + if (System.getProperty("com.google.appengine.runtime.version") != null + && System.getenv("GAE_SERVICE") == null) { try { return new UrlFetchTransport(); } catch (Exception ignore) { From 3affedcc523a8b6f2d04c6203a097f0d0f4fc05d Mon Sep 17 00:00:00 2001 From: Ryan Eiger Date: Tue, 11 Apr 2017 13:05:15 -0700 Subject: [PATCH 324/663] Add annotations to specify GCP launch stage (#1889) The Google Cloud Platform launch stage (https://cloud.google.com/terms/launch-stages) is a signifier of the level of access and support that can be expected of a particular feature. These annotations will be used to clearly demarcate features as being in a state other than General Availability to help set user expectations accordingly. --- .../java/com/google/cloud/GcpLaunchStage.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java b/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java new file mode 100644 index 0000000000..af4b951f34 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java @@ -0,0 +1,74 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * A qualifier indicating what level of access and support can be expected of a particular Google + * Cloud Platform feature. The "GeneralAvailability" qualifier is not provided since the vast + * majority of features are in this category. Note that features may be in a later launch stage + * than the client library annotation indicates. + * + *

    See more at the Launch Stages Documentation. + */ +public class GcpLaunchStage { + + /** + * Early Access features are limited to a closed group of testers. To use these features, you must + * sign up in advance and sign a Trusted Tester agreement (which includes confidentiality + * provisions). These features may be unstable, changed in backward-incompatible ways, and are not + * guaranteed to be released. + */ + @Retention(RetentionPolicy.RUNTIME) + public @interface EarlyAccess {} + + /** + * Alpha is a limited availability test for releases before they are cleared for widespread use. + * By Alpha, all significant design issues are resolved and we are in the process of verifying + * functionality. Alpha customers need to apply for access, agree to applicable terms, and have + * their projects whitelisted. Alpha releases don’t have to be feature complete, no SLAs are + * provided, and there are no technical support obligations, but they will be far enough along + * that customers can actually use them in test environments or for limited-use tests -- just like + * they would in normal production cases. + */ + @Retention(RetentionPolicy.RUNTIME) + public @interface Alpha {} + + /** + * Beta is the point at which we are ready to open a release for any customer to use. There are no + * SLA or technical support obligations in a Beta release, and charges may be waived in some + * cases. Products will be complete from a feature perspective, but may have some open outstanding + * issues. Beta releases are suitable for limited production use cases. + */ + @Retention(RetentionPolicy.RUNTIME) + public @interface Beta {} + + /** + * Deprecated features are scheduled to be shut down and removed. For more information, see the + * “Deprecation Policy” section of our Terms of Service + * and the Google Cloud Platform Subject to the Deprecation Policy + * documentation. + */ + @Retention(RetentionPolicy.RUNTIME) + public @interface Deprecated {} + + private GcpLaunchStage() { + // Intentionally left blank. + } +} From 7b37515651558ebf3055328772a22687f377ac35 Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Wed, 12 Apr 2017 09:15:43 -0700 Subject: [PATCH 325/663] Update page (#1894) - Use GAX page interface - Bump GAX version --- .../main/java/com/google/cloud/AsyncPage.java | 53 -------------- .../java/com/google/cloud/AsyncPageImpl.java | 4 +- .../src/main/java/com/google/cloud/Page.java | 70 ------------------- .../main/java/com/google/cloud/PageImpl.java | 17 +++-- .../com/google/cloud/AsyncPageImplTest.java | 7 +- .../java/com/google/cloud/PageImplTest.java | 3 +- 6 files changed, 22 insertions(+), 132 deletions(-) delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/Page.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java deleted file mode 100644 index abc1c36028..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPage.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import com.google.api.gax.core.ApiFuture; - -/** - * Interface for asynchronously consuming Google Cloud paginated results. - * - *

    Use {@code AsyncPage} to iterate through all values (also in next pages): - *

     {@code
    - * AsyncPage page = ...; // get an AsyncPage instance
    - * Iterator iterator = page.iterateAll();
    - * while (iterator.hasNext()) {
    - *   T value = iterator.next();
    - *   // do something with value
    - * }}
    - * - *

    Or handle pagination explicitly: - *

     {@code
    - * AsyncPage page = ...; // get a AsyncPage instance
    - * while (page != null) {
    - *   for (T value : page.getValues()) {
    - *     // do something with value
    - *   }
    - *   page = page.getNextPageAsync().get();
    - * }}
    - * - * @param the value type that the page holds - */ -public interface AsyncPage extends Page { - - - /** - * Returns a {@link ApiFuture} object for the next page. {@link ApiFuture#get()} returns - * {@code null} if the last page has been reached. - */ - ApiFuture> getNextPageAsync(); -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index e2d27d75bc..c119f4f18e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -18,6 +18,8 @@ import com.google.api.gax.core.ApiFuture; import com.google.api.gax.core.ApiFutures; +import com.google.api.gax.core.AsyncPage; +import com.google.api.gax.core.Page; import com.google.common.base.Throwables; import com.google.common.util.concurrent.Uninterruptibles; import java.io.Serializable; @@ -76,7 +78,7 @@ public AsyncPageImpl(NextPageFetcher asyncPageFetcher, String cursor, Iterabl @Override public ApiFuture> getNextPageAsync() { - if (getNextPageCursor() == null || asyncPageFetcher == null) { + if (getNextPageToken() == null || asyncPageFetcher == null) { return ApiFutures.immediateFuture(null); } return asyncPageFetcher.getNextPage(); diff --git a/google-cloud-core/src/main/java/com/google/cloud/Page.java b/google-cloud-core/src/main/java/com/google/cloud/Page.java deleted file mode 100644 index 03cbe566d4..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/Page.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import java.util.Iterator; - -/** - * Interface for Google Cloud paginated results. - * - *

    Use {@code Page} to iterate through all values (also in next pages): - *

     {@code
    - * Page page = ...; // get a Page instance
    - * Iterator iterator = page.iterateAll();
    - * while (iterator.hasNext()) {
    - *   T value = iterator.next();
    - *   // do something with value
    - * }}
    - * - *

    Or handle pagination explicitly: - *

     {@code
    - * Page page = ...; // get a Page instance
    - * while (page != null) {
    - *   for (T value : page.getValues()) {
    - *     // do something with value
    - *   }
    - *   page = page.getNextPage();
    - * }}
    - * - * @param the value type that the page holds - */ -public interface Page { - - - /** - * Returns the values contained in this page. - */ - Iterable getValues(); - - /** - * Returns an iterator for all values, possibly also in the next pages. Once current page's values - * are traversed the iterator fetches next page, if any. - */ - Iterator iterateAll(); - - - /** - * Returns the cursor for the nextPage or {@code null} if no more results. - */ - String getNextPageCursor(); - - - /** - * Returns the next page of results or {@code null} if no more result. - */ - Page getNextPage(); -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java index 37b7fd9dee..ac329aab44 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java @@ -16,6 +16,7 @@ package com.google.cloud; +import com.google.api.gax.core.Page; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableMap; @@ -81,20 +82,28 @@ public PageImpl(NextPageFetcher pageFetcher, String cursor, Iterable resul this.results = results; } - @Override public Iterable getValues() { return results == null ? Collections.emptyList() : results; } @Override - public Iterator iterateAll() { - return new PageIterator<>(this); + public Iterable iterateAll() { + return new Iterable() { + @Override + public Iterator iterator() { + return new PageIterator<>(PageImpl.this); + } + }; } + @Override + public boolean hasNextPage() { + return getNextPageToken() != null && !getNextPageToken().equals(""); + } @Override - public String getNextPageCursor() { + public String getNextPageToken() { return cursor; } diff --git a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java index ea1717583d..a28536c915 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java @@ -20,6 +20,7 @@ import com.google.api.gax.core.ApiFuture; import com.google.api.gax.core.ApiFutures; +import com.google.api.gax.core.AsyncPage; import com.google.common.collect.ImmutableList; import org.junit.Test; @@ -62,7 +63,7 @@ public void testPage() { AsyncPageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1); assertEquals(nextResult, result.getNextPage()); - assertEquals("c", result.getNextPageCursor()); + assertEquals("c", result.getNextPageToken()); assertEquals(VALUES1, result.getValues()); } @@ -73,7 +74,7 @@ public void testPageAsync() throws ExecutionException, InterruptedException { AsyncPageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1); assertEquals(nextResult, result.getNextPageAsync().get()); - assertEquals("c", result.getNextPageCursor()); + assertEquals("c", result.getNextPageToken()); assertEquals(VALUES1, result.getValues()); } @@ -96,7 +97,7 @@ public void testAsyncPageAndIterateAll() throws ExecutionException, InterruptedE AsyncPageImpl.NextPageFetcher fetcher1 = new TestPageFetcher(nextResult1); AsyncPageImpl result = new AsyncPageImpl<>(fetcher1, "c1", VALUES1); assertEquals(nextResult1, result.getNextPageAsync().get()); - assertEquals("c1", result.getNextPageCursor()); + assertEquals("c1", result.getNextPageToken()); assertEquals(VALUES1, result.getValues()); assertEquals(SOME_VALUES, ImmutableList.copyOf(result.getNextPageAsync().get().iterateAll())); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java index fb1d2c209c..a5ffadf4d6 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; +import com.google.api.gax.core.Page; import com.google.common.collect.ImmutableList; import org.junit.Test; @@ -52,7 +53,7 @@ public void testPage() { PageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult); PageImpl result = new PageImpl<>(fetcher, "c", VALUES); assertEquals(nextResult, result.getNextPage()); - assertEquals("c", result.getNextPageCursor()); + assertEquals("c", result.getNextPageToken()); assertEquals(VALUES, result.getValues()); } From 2a7b6219a52345357388ea979adc872d51009026 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Wed, 12 Apr 2017 14:18:08 -0400 Subject: [PATCH 326/663] Make project.properties path independent per API (#1863) - Previously we generate all project.properties files into root which is incorrect - Now the caller API client needs to pass in package path to retrieve the corresponding version - Create project.properties for Veneer-only clients as well --- google-cloud-core/pom.xml | 21 +++++ .../google/cloud/GrpcTransportOptions.java | 2 +- .../google/cloud/HttpTransportOptions.java | 9 +- .../java/com/google/cloud/ServiceOptions.java | 94 ++++++------------- .../cloud/HttpTransportOptionsTest.java | 7 +- .../com/google/cloud/ServiceOptionsTest.java | 12 +-- 6 files changed, 67 insertions(+), 78 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 332beece16..56f40feeeb 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -15,6 +15,7 @@ google-cloud-core + ${project.version} @@ -171,4 +172,24 @@ test + + + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + + generate-resources + + write-project-properties + + + ${project.build.outputDirectory}/com/google/cloud/project.properties + + + + + + diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java index f27ace8b01..8fd8f26bec 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java @@ -216,7 +216,7 @@ public static ChannelProvider setUpChannelProvider( InstantiatingChannelProvider.Builder providerBuilder, ServiceOptions serviceOptions) { providerBuilder.setEndpoint(serviceOptions.getHost()) .setClientLibHeader(ServiceOptions.getGoogApiClientLibName(), - firstNonNull(ServiceOptions.getLibraryVersion(), "")); + firstNonNull(serviceOptions.getLibraryVersion(), "")); Credentials scopedCredentials = serviceOptions.getScopedCredentials(); if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { providerBuilder.setCredentialsProvider(FixedCredentialsProvider.create(scopedCredentials)); diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java index 9308704eb1..a2a99a28d9 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java @@ -139,7 +139,8 @@ public HttpTransportFactory getHttpTransportFactory() { * Returns a request initializer responsible for initializing requests according to service * options. */ - public HttpRequestInitializer getHttpRequestInitializer(ServiceOptions serviceOptions) { + public HttpRequestInitializer getHttpRequestInitializer( + final ServiceOptions serviceOptions) { Credentials scopedCredentials = serviceOptions.getScopedCredentials(); final HttpRequestInitializer delegate = scopedCredentials != null && scopedCredentials != NoCredentials.getInstance() @@ -158,17 +159,17 @@ public void initialize(HttpRequest httpRequest) throws IOException { } HttpHeaders headers = httpRequest.getHeaders(); - headers.set("x-goog-api-client", getXGoogApiClientHeader()); + headers.set("x-goog-api-client", getXGoogApiClientHeader(serviceOptions)); } }; } - String getXGoogApiClientHeader() { + String getXGoogApiClientHeader(ServiceOptions serviceOptions) { return String.format( "gl-java/%s %s/%s", getJavaVersion(), ServiceOptions.getGoogApiClientLibName(), - ServiceOptions.getLibraryVersion()); + serviceOptions.getLibraryVersion()); } private static String getJavaVersion() { diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 55f2c08ac4..e9b262dc32 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -21,20 +21,15 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.nio.charset.StandardCharsets.UTF_8; -import com.google.api.gax.core.CurrentMillisClock; import com.google.api.gax.core.ApiClock; +import com.google.api.gax.core.CurrentMillisClock; +import com.google.api.gax.core.PropertiesProvider; import com.google.api.gax.core.RetrySettings; import com.google.auth.Credentials; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.collect.Iterables; import com.google.common.io.Files; - -import org.joda.time.Duration; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONTokener; - import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -49,17 +44,16 @@ import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.Charset; -import java.util.Enumeration; import java.util.Locale; import java.util.Objects; -import java.util.Properties; import java.util.ServiceLoader; import java.util.Set; -import java.util.jar.Attributes; -import java.util.jar.JarFile; -import java.util.jar.Manifest; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.joda.time.Duration; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONTokener; /** * Abstract class representing service options. @@ -73,17 +67,13 @@ public abstract class ServiceOptions, private static final String DEFAULT_HOST = "https://www.googleapis.com"; private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; - private static final String MANIFEST_ARTIFACT_ID_KEY = "artifactId"; - private static final String MANIFEST_VERSION_KEY = "Implementation-Version"; - private static final String ARTIFACT_ID = "google-cloud-core"; private static final String LIBRARY_NAME = "gcloud-java"; private static final String X_GOOGLE_CLIENT_HEADER_NAME = "gccl"; - private static final String LIBRARY_VERSION = defaultLibraryVersion(); - private static final String APPLICATION_NAME = - LIBRARY_VERSION == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + LIBRARY_VERSION; - private static final String META_FILE_ROOT = "/META-INF/maven/"; - private static final String META_VERSION_KEY = "version"; + private static final String PROPERTIES_VERSION_KEY = "artifact.version"; + private static final String DEFAULT_PACKAGE_PATH = "com/google/cloud"; + private static final String PROPERTIES_FILE = "project.properties"; + private static final RetrySettings DEFAULT_RETRY_SETTINGS = getDefaultRetrySettingsBuilder() .build(); private static final RetrySettings NO_RETRY_SETTINGS = getDefaultRetrySettingsBuilder() @@ -525,8 +515,9 @@ public TransportOptions getTransportOptions() { /** * Returns the application's name as a string in the format {@code gcloud-java/[version]}. */ - public static String getApplicationName() { - return APPLICATION_NAME; + public String getApplicationName() { + String libraryVersion = getLibraryVersion(); + return libraryVersion == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + libraryVersion; } @@ -547,8 +538,17 @@ public static String getGoogApiClientLibName() { /** * Returns the library's version as a string. */ - public static String getLibraryVersion() { - return LIBRARY_VERSION; + public String getLibraryVersion() { + try { + String version = getVersionProperty(getPackagePath()); + if (version == null) { + version = getVersionProperty(DEFAULT_PACKAGE_PATH); + } + return version; + } catch (Exception e) { + // ignore + } + return null; } protected int baseHashCode() { @@ -618,47 +618,13 @@ static T getFromServiceLoader(Class clazz, T defaultInstance) { return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance); } - private static String defaultLibraryVersion() { - String version = getPomVersion(); - if (version == null) { - version = getManifestVersion(); - } - return version; - } - - private static String getPomVersion() { - try { - Properties properties = new Properties(); - String mavenPropertiesPath = META_FILE_ROOT - + ServiceOptions.class.getPackage().getName() + "/" - + ARTIFACT_ID + "/pom.properties"; - InputStream inputStream = ServiceOptions.class.getResourceAsStream(mavenPropertiesPath); - if (inputStream != null) { - properties.load(inputStream); - return properties.getProperty(META_VERSION_KEY, ""); - } - } catch (Exception e) { - // ignore - } - return null; + private String getVersionProperty(String packagePath) { + String projectPropertiesPath = "/" + packagePath + "/" + PROPERTIES_FILE; + return PropertiesProvider.loadProperty( + ServiceOptions.class, projectPropertiesPath, PROPERTIES_VERSION_KEY); } - private static String getManifestVersion() { - String version = null; - try { - Enumeration resources = - ServiceOptions.class.getClassLoader().getResources(JarFile.MANIFEST_NAME); - while (resources.hasMoreElements() && version == null) { - Manifest manifest = new Manifest(resources.nextElement().openStream()); - Attributes manifestAttributes = manifest.getMainAttributes(); - String artifactId = manifestAttributes.getValue(MANIFEST_ARTIFACT_ID_KEY); - if (artifactId != null && artifactId.equals(ARTIFACT_ID)) { - version = manifestAttributes.getValue(MANIFEST_VERSION_KEY); - } - } - } catch (IOException e) { - // ignore - } - return version; + private String getPackagePath() { + return this.getClass().getPackage().getName().replaceAll("\\.", "/"); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java index 23a2c10a50..4d828ea6e7 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java @@ -64,9 +64,12 @@ public void testBaseHashCode() { @Test public void testHeader() { - String expectedHeaderPattern = "^gl-java/.* gccl/.*"; + String expectedHeaderPattern = "^gl-java/.* gccl/0.0.0"; + final ServiceOptions mockOptions = EasyMock.createMock(ServiceOptions.class); + EasyMock.expect(mockOptions.getLibraryVersion()).andReturn("0.0.0"); + EasyMock.replay(mockOptions); assertTrue(Pattern.compile(expectedHeaderPattern) - .matcher(DEFAULT_OPTIONS.getXGoogApiClientHeader()) + .matcher(OPTIONS.getXGoogApiClientHeader(mockOptions)) .find()); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 3ef3f21e3c..38b468d93e 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -26,16 +26,14 @@ import com.google.api.gax.core.CurrentMillisClock; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Set; import java.util.regex.Pattern; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; public class ServiceOptionsTest { private static final String JSON_KEY = @@ -98,7 +96,7 @@ public class ServiceOptionsTest { private static final TestServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); private static final String LIBRARY_NAME = "gcloud-java"; private static final Pattern APPLICATION_NAME_PATTERN = - Pattern.compile(LIBRARY_NAME + "(/[0-9]+.[0-9]+.[0-9]+)?"); + Pattern.compile(LIBRARY_NAME + "/.*"); @Rule public ExpectedException thrown = ExpectedException.none(); @@ -268,7 +266,7 @@ public void testBaseEquals() { @Test public void testLibraryName() { - assertEquals(LIBRARY_NAME, OPTIONS.getLibraryName()); + assertEquals(LIBRARY_NAME, ServiceOptions.getLibraryName()); } @Test From 41a11075c89d269f571edd970e6a2b903bc8c151 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Wed, 12 Apr 2017 15:15:46 -0400 Subject: [PATCH 327/663] Update org.json to latest version (#1904) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 56f40feeeb..9b56891499 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -102,7 +102,7 @@ org.json json - 20151123 + 20160810 compile From be75b1a4fe0e8f02acb12a25ea80bc430a1aa2f1 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Thu, 13 Apr 2017 16:04:45 +1000 Subject: [PATCH 328/663] bump grpc dependency to 1.2.0 (#1902) also move various protobuf-generated dependencies to 0.1.7 update gax version to 0.10.0 --- google-cloud-core/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9b56891499..90d3310f44 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -114,12 +114,12 @@ com.google.protobuf protobuf-java - 3.0.0 + 3.2.0 com.google.protobuf protobuf-java-util - 3.0.0 + 3.2.0 io.grpc @@ -140,7 +140,7 @@ com.google.api.grpc grpc-google-common-protos - 0.1.5 + 0.1.7 io.grpc @@ -151,7 +151,7 @@ com.google.api.grpc grpc-google-iam-v1 - 0.1.5 + 0.1.7 io.grpc From 73a7f246a3727d8eca8dc2033a713620205b4f2b Mon Sep 17 00:00:00 2001 From: Ryan Eiger Date: Fri, 7 Apr 2017 15:11:08 -0700 Subject: [PATCH 329/663] Add Identity Access Management (IAM) to the Storage API (#1812) Adds support for bucket-level IAM (currently in limited alpha). More information about IAM in Google Cloud Storage can be found at https://cloud.google.com/storage/docs/access-control/iam --- google-cloud-core/src/main/java/com/google/cloud/Policy.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Policy.java b/google-cloud-core/src/main/java/com/google/cloud/Policy.java index c8fc044086..0de5cdc965 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Policy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Policy.java @@ -202,7 +202,6 @@ public final Builder removeIdentity(Role role, Identity first, Identity... other return this; } - /** * Sets the policy's etag. * @@ -214,7 +213,7 @@ public final Builder removeIdentity(Role role, Identity first, Identity... other * applied to the same version of the policy. If no etag is provided in the call to * setIamPolicy, then the existing policy is overwritten blindly. */ - protected final Builder setEtag(String etag) { + public final Builder setEtag(String etag) { this.etag = etag; return this; } From 15cd15982715311130d32411b525db3ac1f07e28 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 13 Apr 2017 13:56:16 -0700 Subject: [PATCH 330/663] Formatting and merge fixes --- google-cloud-core/src/main/java/com/google/cloud/Policy.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Policy.java b/google-cloud-core/src/main/java/com/google/cloud/Policy.java index 0de5cdc965..7f918767d5 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Policy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Policy.java @@ -124,7 +124,8 @@ public static class Builder { private String etag; private int version; - protected Builder() {} + protected Builder() { + } protected Builder(Policy policy) { setBindings(policy.bindings); From 2f8537908af366ce62d0f0c1e85a7bd69690a6ce Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 13 Apr 2017 15:42:18 -0700 Subject: [PATCH 331/663] Release 0.13.0 --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 90d3310f44..d1a036354b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.12.1-alpha-SNAPSHOT + 0.13.0-alpha google-cloud-core From 9803b324bc64261ac7c97b71523b9055661ebbb1 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 13 Apr 2017 15:54:03 -0700 Subject: [PATCH 332/663] Updating version in README files. [ci skip] --- google-cloud-core/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 60076c965e..9270479b66 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.12.0-alpha + 0.13.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.12.0-alpha' +compile 'com.google.cloud:google-cloud-core:0.13.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.12.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.13.0-alpha" ``` Troubleshooting From db0ec3bc514525fe0f5deeb44b89921764ca55a8 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 13 Apr 2017 16:26:35 -0700 Subject: [PATCH 333/663] Update version to 0.13.1-SNAPSHOT (#1919) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d1a036354b..cdd802dc45 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pom - 0.13.0-alpha + 0.13.1-alpha-SNAPSHOT google-cloud-core From 41a2a61c3bed85258ec739d4e6c7886e21d8e5ac Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Fri, 14 Apr 2017 17:31:23 -0700 Subject: [PATCH 334/663] Update release scripts to handle 1.x and 0.x versions living together (#1922) * Update release scripts to handle 1.x and 0.x versions living together https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1845 Move and rename testing folder modules so they are consistent with current project naming and structure (so their versions can be updated by same script). --- google-cloud-core/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index cdd802dc45..8681fe0a85 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,6 +2,7 @@ 4.0.0 google-cloud-core + 0.13.1-alpha-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core From 3799a357618c339990c857d7bb92fb35544abdf9 Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Tue, 18 Apr 2017 08:55:26 -0700 Subject: [PATCH 335/663] Changes required for updated api-common (#1927) --- google-cloud-core/pom.xml | 5 +++++ .../src/main/java/com/google/cloud/AsyncPageImpl.java | 4 ++-- .../src/main/java/com/google/cloud/RetryHelper.java | 2 +- .../src/main/java/com/google/cloud/ServiceOptions.java | 4 ++-- .../src/test/java/com/google/cloud/AsyncPageImplTest.java | 4 ++-- .../src/test/java/com/google/cloud/ServiceOptionsTest.java | 4 ++-- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 8681fe0a85..9749ee819d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -138,6 +138,11 @@ + + com.google.api + api-common + ${api-common.version} + com.google.api.grpc grpc-google-common-protos diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index c119f4f18e..d812e126ff 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -16,8 +16,8 @@ package com.google.cloud; -import com.google.api.gax.core.ApiFuture; -import com.google.api.gax.core.ApiFutures; +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; import com.google.api.gax.core.AsyncPage; import com.google.api.gax.core.Page; import com.google.common.base.Throwables; diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index 6d36096bb6..7ee7fb3583 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -16,7 +16,7 @@ package com.google.cloud; -import com.google.api.gax.core.ApiClock; +import com.google.api.core.ApiClock; import com.google.api.gax.core.RetrySettings; import com.google.api.gax.retrying.DirectRetryingExecutor; diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index e9b262dc32..6f3d36e75a 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -21,8 +21,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.nio.charset.StandardCharsets.UTF_8; -import com.google.api.gax.core.ApiClock; -import com.google.api.gax.core.CurrentMillisClock; +import com.google.api.core.ApiClock; +import com.google.api.core.CurrentMillisClock; import com.google.api.gax.core.PropertiesProvider; import com.google.api.gax.core.RetrySettings; import com.google.auth.Credentials; diff --git a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java index a28536c915..021a694a73 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java @@ -18,8 +18,8 @@ import static org.junit.Assert.assertEquals; -import com.google.api.gax.core.ApiFuture; -import com.google.api.gax.core.ApiFutures; +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; import com.google.api.gax.core.AsyncPage; import com.google.common.collect.ImmutableList; diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 38b468d93e..e7f3a45158 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -22,8 +22,8 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.api.gax.core.ApiClock; -import com.google.api.gax.core.CurrentMillisClock; +import com.google.api.core.ApiClock; +import com.google.api.core.CurrentMillisClock; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; import java.io.ByteArrayInputStream; From 4ec99ffb3a02ec335a3d668a56a216f00aead00f Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 18 Apr 2017 09:04:46 -0700 Subject: [PATCH 336/663] Removing timeout settings that are set but never used (#1934) --- .../google/cloud/GrpcTransportOptions.java | 81 +------------------ .../cloud/GrpcTransportOptionsTest.java | 43 ---------- 2 files changed, 2 insertions(+), 122 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java index 8fd8f26bec..81402c9e73 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java @@ -45,9 +45,6 @@ public class GrpcTransportOptions implements TransportOptions { private static final long serialVersionUID = -9049538465533951165L; private final String executorFactoryClassName; - private final int initialTimeout; - private final double timeoutMultiplier; - private final int maxTimeout; private transient ExecutorFactory executorFactory; @@ -118,17 +115,11 @@ public synchronized void release(ScheduledExecutorService executor) { public static class Builder { private ExecutorFactory executorFactory; - private int initialTimeout = 20_000; - private double timeoutMultiplier = 1.5; - private int maxTimeout = 100_000; private Builder() {} private Builder(GrpcTransportOptions options) { executorFactory = options.executorFactory; - initialTimeout = options.initialTimeout; - timeoutMultiplier = options.timeoutMultiplier; - maxTimeout = options.maxTimeout; } public GrpcTransportOptions build() { @@ -145,44 +136,6 @@ public Builder setExecutorFactory(ExecutorFactory exec this.executorFactory = executorFactory; return this; } - - /** - * Sets the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value - * adjusted according to {@link #setTimeoutMultiplier(double)}. Default value is 20000. - * - * @return the builder - * @throws IllegalArgumentException if the provided timeout is < 0 - */ - public Builder setInitialTimeout(int initialTimeout) { - Preconditions.checkArgument(initialTimeout > 0, "Initial timeout must be > 0"); - this.initialTimeout = initialTimeout; - return this; - } - - /** - * Sets the timeout multiplier. This value is used to compute the timeout for a retried RPC. - * Timeout is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. - * - * @return the builder - * @throws IllegalArgumentException if the provided timeout multiplier is < 0 - */ - public Builder setTimeoutMultiplier(double timeoutMultiplier) { - Preconditions.checkArgument(timeoutMultiplier >= 1.0, "Timeout multiplier must be >= 1"); - this.timeoutMultiplier = timeoutMultiplier; - return this; - } - - /** - * Sets the maximum timeout for a RPC call, in milliseconds. Default value is 100000. If - * {@code maxTimeout} is lower than the initial timeout the {@link #setInitialTimeout(int)} - * value is used instead. - * - * @return the builder - */ - public Builder setMaxTimeout(int maxTimeout) { - this.maxTimeout = maxTimeout; - return this; - } } @SuppressWarnings("unchecked") @@ -190,9 +143,6 @@ private GrpcTransportOptions(Builder builder) { executorFactory = firstNonNull(builder.executorFactory, ServiceOptions.getFromServiceLoader(ExecutorFactory.class, DefaultExecutorFactory.INSTANCE)); executorFactoryClassName = executorFactory.getClass().getName(); - initialTimeout = builder.initialTimeout; - timeoutMultiplier = builder.timeoutMultiplier; - maxTimeout = builder.maxTimeout <= initialTimeout ? initialTimeout : builder.maxTimeout; } /** @@ -225,37 +175,13 @@ public static ChannelProvider setUpChannelProvider( } - /** - * Returns the timeout for the initial RPC, in milliseconds. Subsequent calls will use this value - * adjusted according to {@link #getTimeoutMultiplier()}. Default value is 20000. - */ - public int getInitialTimeout() { - return initialTimeout; - } - - /** - * Returns the timeout multiplier. This values is used to compute the timeout for a RPC. Timeout - * is computed as {@code timeoutMultiplier * previousTimeout}. Default value is 1.5. - */ - public double getTimeoutMultiplier() { - return timeoutMultiplier; - } - - /** - * Returns the maximum timeout for a RPC call, in milliseconds. Default value is 100000. - */ - public int getMaxTimeout() { - return maxTimeout; - } - public Builder toBuilder() { return new Builder(this); } @Override public int hashCode() { - return Objects.hash(executorFactoryClassName, initialTimeout, - timeoutMultiplier, maxTimeout); + return Objects.hash(executorFactoryClassName); } @Override @@ -267,10 +193,7 @@ public boolean equals(Object obj) { return false; } GrpcTransportOptions other = (GrpcTransportOptions) obj; - return Objects.equals(executorFactoryClassName, other.executorFactoryClassName) - && Objects.equals(initialTimeout, other.initialTimeout) - && Objects.equals(timeoutMultiplier, other.timeoutMultiplier) - && Objects.equals(maxTimeout, other.maxTimeout); + return Objects.equals(executorFactoryClassName, other.executorFactoryClassName); } private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException { diff --git a/google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java index aafd264611..1bcc54af6a 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java @@ -33,9 +33,6 @@ public class GrpcTransportOptionsTest { private static final ExecutorFactory MOCK_EXECUTOR_FACTORY = EasyMock.createMock(ExecutorFactory.class); private static final GrpcTransportOptions OPTIONS = GrpcTransportOptions.newBuilder() - .setInitialTimeout(1234) - .setTimeoutMultiplier(1.6) - .setMaxTimeout(5678) .setExecutorFactory(MOCK_EXECUTOR_FACTORY) .build(); private static final GrpcTransportOptions DEFAULT_OPTIONS = @@ -44,50 +41,10 @@ public class GrpcTransportOptionsTest { @Test public void testBuilder() { - assertEquals(1234, OPTIONS.getInitialTimeout()); - assertEquals(1.6, OPTIONS.getTimeoutMultiplier(), 0.0); - assertEquals(5678, OPTIONS.getMaxTimeout()); assertSame(MOCK_EXECUTOR_FACTORY, OPTIONS.getExecutorFactory()); - assertEquals(20000, DEFAULT_OPTIONS.getInitialTimeout()); - assertEquals(1.5, DEFAULT_OPTIONS.getTimeoutMultiplier(), 0.0); - assertEquals(100000, DEFAULT_OPTIONS.getMaxTimeout()); assertTrue(DEFAULT_OPTIONS.getExecutorFactory() instanceof DefaultExecutorFactory); } - @Test - public void testBuilderError() { - try { - GrpcTransportOptions.newBuilder().setInitialTimeout(0); - fail("IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - assertEquals("Initial timeout must be > 0", ex.getMessage()); - } - try { - GrpcTransportOptions.newBuilder().setInitialTimeout(-1); - fail("IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - assertEquals("Initial timeout must be > 0", ex.getMessage()); - } - try { - GrpcTransportOptions.newBuilder().setTimeoutMultiplier(0.9); - fail("IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - assertEquals("Timeout multiplier must be >= 1", ex.getMessage()); - } - } - - @Test - public void testBuilderInvalidMaxTimeout() { - GrpcTransportOptions options = GrpcTransportOptions.newBuilder() - .setInitialTimeout(1234) - .setTimeoutMultiplier(1.6) - .setMaxTimeout(123) - .build(); - assertEquals(1234, options.getInitialTimeout()); - assertEquals(1.6, options.getTimeoutMultiplier(), 0.0); - assertEquals(1234, options.getMaxTimeout()); - } - @Test public void testBaseEquals() { assertEquals(OPTIONS, OPTIONS_COPY); From 031e1d83e47ddd180d53a103417934fe4a88a5a6 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 18 Apr 2017 09:57:09 -0700 Subject: [PATCH 337/663] Marking some core types @BetaApi and @InternalApi (#1933) --- .../src/main/java/com/google/cloud/AsyncPageImpl.java | 2 ++ .../src/main/java/com/google/cloud/ByteArray.java | 2 ++ google-cloud-core/src/main/java/com/google/cloud/Date.java | 2 ++ .../src/main/java/com/google/cloud/FieldSelector.java | 2 ++ .../src/main/java/com/google/cloud/GrpcTransportOptions.java | 1 - google-cloud-core/src/main/java/com/google/cloud/PageImpl.java | 3 ++- .../src/main/java/com/google/cloud/WaitForOption.java | 2 ++ .../main/java/com/google/cloud/testing/BaseEmulatorHelper.java | 2 ++ 8 files changed, 14 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index d812e126ff..f72783cf87 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -18,6 +18,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; +import com.google.api.core.InternalApi; import com.google.api.gax.core.AsyncPage; import com.google.api.gax.core.Page; import com.google.common.base.Throwables; @@ -30,6 +31,7 @@ * * @param the value type that the page holds */ +@InternalApi public class AsyncPageImpl extends PageImpl implements AsyncPage { private static final long serialVersionUID = -6009473188630364906L; diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java index 8b83a1e4b2..449e827c41 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -16,6 +16,7 @@ package com.google.cloud; +import com.google.api.core.BetaApi; import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.io.BaseEncoding; @@ -31,6 +32,7 @@ /** * An immutable byte array holder. */ +@BetaApi public class ByteArray implements Iterable, Serializable { private static final long serialVersionUID = -1908809133893782840L; diff --git a/google-cloud-core/src/main/java/com/google/cloud/Date.java b/google-cloud-core/src/main/java/com/google/cloud/Date.java index a11d259df7..9da1bb6631 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Date.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Date.java @@ -16,6 +16,7 @@ package com.google.cloud; +import com.google.api.core.BetaApi; import com.google.common.base.Preconditions; import java.util.Objects; import java.util.regex.Matcher; @@ -24,6 +25,7 @@ /** * Represents a Date without time, such as 2017-03-17. Date is timezone independent. */ +@BetaApi public final class Date implements Comparable { // Date format "yyyy-mm-dd" diff --git a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java index 125a03e212..24706b52e5 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java +++ b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java @@ -16,6 +16,7 @@ package com.google.cloud; +import com.google.api.core.InternalApi; import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.collect.Lists; @@ -42,6 +43,7 @@ public interface FieldSelector { * A helper class used to build composite selectors given a number of fields. This class is not * supposed to be used directly by users. */ + @InternalApi class Helper { private static final String[] EMPTY_FIELDS = {}; diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java index 81402c9e73..15fb9a7311 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java @@ -26,7 +26,6 @@ import com.google.auth.Credentials; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; -import com.google.common.net.HostAndPort; import io.grpc.internal.SharedResourceHolder; import io.grpc.internal.SharedResourceHolder.Resource; import java.io.IOException; diff --git a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java index ac329aab44..e49e1e75a6 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java @@ -16,10 +16,10 @@ package com.google.cloud; +import com.google.api.core.InternalApi; import com.google.api.gax.core.Page; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableMap; - import java.io.Serializable; import java.util.Collections; import java.util.Iterator; @@ -31,6 +31,7 @@ * * @param the value type that the page holds */ +@InternalApi public class PageImpl implements Page, Serializable { private static final long serialVersionUID = 3914827379823557934L; diff --git a/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java b/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java index a84b25bc36..a03b064259 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java +++ b/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; +import com.google.api.core.BetaApi; import com.google.common.base.MoreObjects; import java.io.Serializable; @@ -27,6 +28,7 @@ /** * This class represents options for methods that wait for changes in the status of a resource. */ +@BetaApi public abstract class WaitForOption implements Serializable { private static final long serialVersionUID = 8443451708032349243L; diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index 2b4276068d..0de8675a40 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -16,6 +16,7 @@ package com.google.cloud.testing; +import com.google.api.core.InternalApi; import com.google.cloud.ServiceOptions; import com.google.common.io.CharStreams; import com.google.common.util.concurrent.SettableFuture; @@ -57,6 +58,7 @@ /** * Utility class to start and stop a local service which is used by unit testing. */ +@InternalApi public abstract class BaseEmulatorHelper { private final String emulator; From c4cf6720892074bfaeb294e4e265f8bba50ceeb9 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 18 Apr 2017 13:57:05 -0700 Subject: [PATCH 338/663] Creating an expandable enum type, converting StorageClass (#1937) --- .../java/com/google/cloud/StringEnumType.java | 93 +++++++++++++ .../com/google/cloud/StringEnumValue.java | 61 +++++++++ .../java/com/google/cloud/StringEnumTest.java | 126 ++++++++++++++++++ 3 files changed, 280 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java b/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java new file mode 100644 index 0000000000..f02982a70f --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java @@ -0,0 +1,93 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud; + +import com.google.api.core.ApiFunction; +import com.google.api.core.InternalApi; +import com.google.common.base.Preconditions; +import java.lang.reflect.Array; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * This represents a concept having a known set of acceptable String values, which can expand later + * due to new API features. + */ +@InternalApi +public class StringEnumType { + + private final Class clazz; + private final ApiFunction constructor; + private final Map knownValues = new LinkedHashMap<>(); + + public StringEnumType(Class clazz, ApiFunction constructor) { + this.clazz = Preconditions.checkNotNull(clazz); + this.constructor = Preconditions.checkNotNull(constructor); + } + + /** + * Create a new constant and register it in the known values. + */ + public EnumT createAndRegister(String constant) { + EnumT instance = constructor.apply(constant); + knownValues.put(constant, instance); + return instance; + } + + /** + * Get the enum object for the given String constant, and throw an exception if the constant is + * not recognized. + */ + public EnumT valueOfStrict(String constant) { + EnumT value = knownValues.get(constant); + if (value != null) { + return value; + } else { + throw new IllegalArgumentException( + "Constant \"" + constant + "\" not found for enum \"" + clazz.getName() + "\""); + } + } + + /** + * Get the enum object for the given String constant, and allow unrecognized values. + */ + public EnumT valueOf(String constant) { + EnumT value = knownValues.get(constant); + if (value != null) { + return value; + } else { + return constructor.apply(constant); + } + } + + /** + * Return the known values of this enum type. + */ + public EnumT[] values() { + Collection valueCollection = knownValues.values(); + + @SuppressWarnings("unchecked") + final EnumT[] valueArray = (EnumT[]) Array.newInstance(clazz, valueCollection.size()); + int i = 0; + for (EnumT enumV : valueCollection) { + valueArray[i] = enumV; + i++; + } + + return valueArray; + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java new file mode 100644 index 0000000000..1f9a224723 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java @@ -0,0 +1,61 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud; + +import com.google.api.core.InternalApi; +import com.google.common.base.Preconditions; + +/** + * This represents a specific instance of a concept having a known set of acceptable String values, + * which can expand later due to new API features. Standard Java enums can't be used in such + * a context. + */ +public abstract class StringEnumValue { + private final String constant; + + /** + * Don't create subclasses outside of google-cloud-java. + */ + @InternalApi + protected StringEnumValue(String constant) { + this.constant = Preconditions.checkNotNull(constant); + } + + @Override + public String toString() { + return constant; + } + + @Override + public boolean equals(Object that) { + if (that == null) { + return false; + } + if (this == that) { + return true; + } + if (!(that instanceof StringEnumValue)) { + return false; + } + StringEnumValue thatEnumValue = (StringEnumValue) that; + return this.constant.equals(thatEnumValue.constant); + } + + @Override + public int hashCode() { + return constant.hashCode(); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java new file mode 100644 index 0000000000..aba6178f0b --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java @@ -0,0 +1,126 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.api.core.ApiFunction; +import com.google.common.testing.EqualsTester; +import java.util.Arrays; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class StringEnumTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + public static class Letter extends StringEnumValue { + private Letter(String constant) { + super(constant); + } + + private static final ApiFunction CONSTRUCTOR = + new ApiFunction() { + @Override + public Letter apply(String constant) { + return new Letter(constant); + } + }; + + private static final StringEnumType type = new StringEnumType( + Letter.class, + CONSTRUCTOR); + + public static final Letter A = type.createAndRegister("A"); + public static final Letter B = type.createAndRegister("B"); + public static final Letter C = type.createAndRegister("C"); + + public static Letter valueOfStrict(String constant) { + return type.valueOfStrict(constant); + } + + /** + * Get the StorageClass for the given String constant, and allow unrecognized values. + */ + public static Letter valueOf(String constant) { + return type.valueOf(constant); + } + + /** + * Return the known values for StorageClass. + */ + public static Letter[] values() { + return type.values(); + } + } + + @Test + public void testNullClass() { + expectedException.expect(NullPointerException.class); + new StringEnumType(null, Letter.CONSTRUCTOR); + } + + @Test + public void testNullConstructor() { + expectedException.expect(NullPointerException.class); + new StringEnumType(Letter.class, null); + } + + @Test + public void testEnumInstances() { + assertThat(Letter.A.toString()).isEqualTo("A"); + } + + @Test + public void testValueOf() { + assertThat(Letter.valueOf("A")).isSameAs(Letter.A); + assertThat(Letter.valueOf("B")).isSameAs(Letter.B); + assertThat(Letter.valueOf("C")).isSameAs(Letter.C); + assertThat(Letter.valueOf("NonExistentLetter").toString()).isEqualTo("NonExistentLetter"); + } + + @Test + public void testValueOfStrict() { + assertThat(Letter.valueOfStrict("A")).isSameAs(Letter.A); + assertThat(Letter.valueOfStrict("B")).isSameAs(Letter.B); + assertThat(Letter.valueOfStrict("C")).isSameAs(Letter.C); + } + + @Test + public void testEquals() { + EqualsTester tester = new EqualsTester(); + + tester.addEqualityGroup(Letter.A, Letter.valueOf("A"), Letter.valueOfStrict("A")); + tester.addEqualityGroup(Letter.B, Letter.valueOf("B"), Letter.valueOfStrict("B")); + tester.addEqualityGroup(Letter.C, Letter.valueOf("C"), Letter.valueOfStrict("C")); + tester + .addEqualityGroup(Letter.valueOf("NonExistentLetter"), Letter.valueOf("NonExistentLetter")); + } + + @Test + public void testValueOfStrict_invalid() { + expectedException.expect(IllegalArgumentException.class); + Letter.valueOfStrict("NonExistentLetter"); + } + + @Test + public void testValues() { + assertThat( + Arrays.asList(Letter.values()).containsAll(Arrays.asList(Letter.A, Letter.B, Letter.C))); + } +} From 0beff8396c33af2624a89cb44dccc12826283775 Mon Sep 17 00:00:00 2001 From: neozwu Date: Tue, 18 Apr 2017 14:59:43 -0700 Subject: [PATCH 339/663] retry datastore transactions (#1242) (#1932) * retry datastore transactions (#1242) --- .../src/main/java/com/google/cloud/BaseService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java index 619341bc37..a907bed132 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java @@ -39,7 +39,7 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { public RetryResult beforeEval(Exception exception) { if (exception instanceof BaseServiceException) { boolean retriable = ((BaseServiceException) exception).isRetryable(); - return retriable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.NO_RETRY; + return retriable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.CONTINUE_EVALUATION; } return Interceptor.RetryResult.CONTINUE_EVALUATION; } From d0c625c9a2a4a5a42e4a99b22e139e13c62997ca Mon Sep 17 00:00:00 2001 From: Jisha Abubaker Date: Tue, 18 Apr 2017 17:02:18 -0700 Subject: [PATCH 340/663] Logging refactor of JUL + monitored resource construction (#1847) Adding support for auto-config of JUL with monitored resource construction on Flex, Standard, GCE and GKE. --- .../java/com/google/cloud/MetadataConfig.java | 76 +++++++++++++++++++ .../java/com/google/cloud/ServiceOptions.java | 21 +---- 2 files changed, 79 insertions(+), 18 deletions(-) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java new file mode 100644 index 0000000000..e6f93490f0 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -0,0 +1,76 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * Retrieves Google Cloud project-id and a limited set of instance attributes from Metadata server. + * @see + * https://cloud.google.com/compute/docs/storing-retrieving-metadata + */ +public class MetadataConfig { + + private static final String METADATA_URL = "http://metadata/computeMetadata/v1/"; + + private MetadataConfig() { + } + + public static String getProjectId() { + return getAttribute("project/project-id"); + } + + public static String getZone() { + String zoneId = getAttribute("instance/zone"); + if (zoneId.contains("/")) { + return zoneId.substring(zoneId.lastIndexOf('/') + 1); + } + return zoneId; + } + + public static String getInstanceId() { + return getAttribute("instance/id"); + } + + public static String getClusterName() { + return getAttribute("instance/cluster-name"); + } + + private static String getAttribute(String attributeName) { + try { + URL url = new URL(METADATA_URL + attributeName); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestProperty("Metadata-Flavor", "Google"); + InputStream input = connection.getInputStream(); + if (connection.getResponseCode() == 200) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, UTF_8))) { + return reader.readLine(); + } + } + } catch (IOException ignore) { + // ignore + } + return null; + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 6f3d36e75a..0db8f08c4d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -309,7 +309,7 @@ public static String getDefaultProjectId() { return projectId != null ? projectId : getGoogleCloudProjectId(); } - protected static String getAppEngineAppId() { + public static String getAppEngineAppId() { return System.getProperty("com.google.appengine.application.id"); } @@ -370,23 +370,8 @@ protected static String getGoogleCloudProjectId() { // ignore } } - try { - URL url = new URL("http://metadata/computeMetadata/v1/project/project-id"); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - // TODO replace X-Google-Metadata-Request with: - // connection.setRequestProperty("Metadata-Flavor", "Google"); - connection.setRequestProperty("X-Google-Metadata-Request", "True"); - InputStream input = connection.getInputStream(); - if (connection.getResponseCode() == 200) { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, UTF_8))) { - return reader.readLine(); - } - } - } catch (IOException ignore) { - // ignore - } - // return null if can't determine - return null; + // return project id from metadata config + return MetadataConfig.getProjectId(); } private static boolean isWindows() { From 82e64a6b986554dab1cac4e95cf43bd9574cf5cf Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 18 Apr 2017 17:34:41 -0700 Subject: [PATCH 341/663] Converting all Storage deserialized enum types to StringEnumValue (#1940) --- .../main/java/com/google/cloud/Identity.java | 119 ++++++++++-------- .../java/com/google/cloud/StringEnumType.java | 3 + .../com/google/cloud/StringEnumValue.java | 8 +- .../java/com/google/cloud/IdentityTest.java | 15 +++ .../java/com/google/cloud/StringEnumTest.java | 2 + 5 files changed, 91 insertions(+), 56 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Identity.java b/google-cloud-core/src/main/java/com/google/cloud/Identity.java index 74d55672ef..a548347654 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Identity.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.api.core.ApiFunction; import com.google.common.base.CaseFormat; import java.io.Serializable; @@ -48,52 +49,91 @@ public final class Identity implements Serializable { /** * The types of IAM identities. */ - public enum Type { + public static final class Type extends StringEnumValue { + private static final long serialVersionUID = 3809891273596003916L; + + private Type(String constant) { + super(constant); + } + + private static final ApiFunction CONSTRUCTOR = + new ApiFunction() { + @Override + public Type apply(String constant) { + return new Type(constant); + } + }; + + private static final StringEnumType type = new StringEnumType( + Type.class, + CONSTRUCTOR); /** * Represents anyone who is on the internet; with or without a Google account. */ - ALL_USERS, + public static final Type ALL_USERS = type.createAndRegister("ALL_USERS"); /** * Represents anyone who is authenticated with a Google account or a service account. */ - ALL_AUTHENTICATED_USERS, + public static final Type ALL_AUTHENTICATED_USERS = type.createAndRegister("ALL_AUTHENTICATED_USERS"); /** * Represents a specific Google account. */ - USER, + public static final Type USER = type.createAndRegister("USER"); /** * Represents a service account. */ - SERVICE_ACCOUNT, + public static final Type SERVICE_ACCOUNT = type.createAndRegister("SERVICE_ACCOUNT"); /** * Represents a Google group. */ - GROUP, + public static final Type GROUP = type.createAndRegister("GROUP"); /** * Represents all the users of a Google Apps domain name. */ - DOMAIN, - + public static final Type DOMAIN = type.createAndRegister("DOMAIN"); + /** * Represents owners of a Google Cloud Platform project. */ - PROJECT_OWNER, - + public static final Type PROJECT_OWNER = type.createAndRegister("PROJECT_OWNER"); + /** * Represents editors of a Google Cloud Platform project. */ - PROJECT_EDITOR, - + public static final Type PROJECT_EDITOR = type.createAndRegister("PROJECT_EDITOR"); + /** * Represents viewers of a Google Cloud Platform project. */ - PROJECT_VIEWER + public static final Type PROJECT_VIEWER = type.createAndRegister("PROJECT_VIEWER"); + + /** + * Get the Type for the given String constant, and throw an exception if the constant is + * not recognized. + */ + public static Type valueOfStrict(String constant) { + return type.valueOfStrict(constant); + } + + /** + * Get the Type for the given String constant, and allow unrecognized values. + */ + public static Type valueOf(String constant) { + return type.valueOf(constant); + } + + /** + * Return the known values for Type. + */ + public static Type[] values() { + return type.values(); + } } private Identity(Type type, String value) { @@ -225,27 +265,11 @@ public boolean equals(Object obj) { * {@code Identity} objects to strings for protobuf-generated policies. */ public String strValue() { - switch (type) { - case ALL_USERS: - return "allUsers"; - case ALL_AUTHENTICATED_USERS: - return "allAuthenticatedUsers"; - case USER: - return "user:" + value; - case SERVICE_ACCOUNT: - return "serviceAccount:" + value; - case GROUP: - return "group:" + value; - case DOMAIN: - return "domain:" + value; - case PROJECT_OWNER: - return "projectOwner:" + value; - case PROJECT_EDITOR: - return "projectEditor:" + value; - case PROJECT_VIEWER: - return "projectViewer:" + value; - default: - throw new IllegalStateException("Unexpected identity type: " + type); + String protobufString = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, type.toString()); + if (value == null) { + return protobufString; + } else { + return protobufString + ":" + value; } } @@ -256,27 +280,12 @@ public String strValue() { public static Identity valueOf(String identityStr) { String[] info = identityStr.split(":"); Type type = Type.valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, info[0])); - switch (type) { - case ALL_USERS: - return Identity.allUsers(); - case ALL_AUTHENTICATED_USERS: - return Identity.allAuthenticatedUsers(); - case USER: - return Identity.user(info[1]); - case SERVICE_ACCOUNT: - return Identity.serviceAccount(info[1]); - case GROUP: - return Identity.group(info[1]); - case DOMAIN: - return Identity.domain(info[1]); - case PROJECT_OWNER: - return Identity.projectOwner(info[1]); - case PROJECT_EDITOR: - return Identity.projectEditor(info[1]); - case PROJECT_VIEWER: - return Identity.projectViewer(info[1]); - default: - throw new IllegalStateException("Unexpected identity type " + type); + if (info.length == 1) { + return new Identity(type, null); + } else if (info.length == 2){ + return new Identity(type, info[1]); + } else { + throw new IllegalArgumentException("Illegal identity string: \"" + identityStr + "\""); } } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java b/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java index f02982a70f..5d5e11dbc4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java +++ b/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java @@ -66,6 +66,9 @@ public EnumT valueOfStrict(String constant) { * Get the enum object for the given String constant, and allow unrecognized values. */ public EnumT valueOf(String constant) { + if (constant == null || constant.isEmpty()) { + throw new IllegalArgumentException("Empty enum constants not allowed."); + } EnumT value = knownValues.get(constant); if (value != null) { return value; diff --git a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java index 1f9a224723..613c598104 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java +++ b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java @@ -17,13 +17,15 @@ import com.google.api.core.InternalApi; import com.google.common.base.Preconditions; +import java.io.Serializable; /** * This represents a specific instance of a concept having a known set of acceptable String values, * which can expand later due to new API features. Standard Java enums can't be used in such * a context. */ -public abstract class StringEnumValue { +public abstract class StringEnumValue implements Serializable { + private static final long serialVersionUID = 1501809419544297884L; private final String constant; /** @@ -34,6 +36,10 @@ protected StringEnumValue(String constant) { this.constant = Preconditions.checkNotNull(constant); } + public String name() { + return constant; + } + @Override public String toString() { return constant; diff --git a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java index cf8726a4b6..0063bdb04d 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java @@ -142,6 +142,21 @@ public void testIdentityToAndFromPb() { compareIdentities(PROJECT_VIEWER, Identity.valueOf(PROJECT_VIEWER.strValue())); } + @Test(expected = IllegalArgumentException.class) + public void testValueOfEmpty() { + Identity.valueOf(""); + } + + @Test(expected = IllegalArgumentException.class) + public void testValueOfThreePart() { + Identity.valueOf("a:b:c"); + } + + @Test + public void testUnrecognizedToString() { + assertEquals("a:b", Identity.valueOf("a:b").strValue()); + } + private void compareIdentities(Identity expected, Identity actual) { assertEquals(expected, actual); assertEquals(expected.getType(), actual.getType()); diff --git a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java index aba6178f0b..613f3676cc 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java @@ -30,6 +30,8 @@ public class StringEnumTest { public ExpectedException expectedException = ExpectedException.none(); public static class Letter extends StringEnumValue { + private static final long serialVersionUID = -1717976087182628526L; + private Letter(String constant) { super(constant); } From badd57c1ad1aed1f362d0e583a8a787caef395f5 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 19 Apr 2017 08:06:22 -0700 Subject: [PATCH 342/663] Converting all Datastore deserialized enum types to StringEnumValue (#1941) --- .../src/main/java/com/google/cloud/StringEnumValue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java index 613c598104..54c72bd8fd 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java +++ b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java @@ -53,7 +53,7 @@ public boolean equals(Object that) { if (this == that) { return true; } - if (!(that instanceof StringEnumValue)) { + if (!(getClass().equals(that.getClass()))) { return false; } StringEnumValue thatEnumValue = (StringEnumValue) that; From 55f2f2895e020787675c3b8c0083598b28e080f4 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 19 Apr 2017 08:16:56 -0700 Subject: [PATCH 343/663] Adding dependency convergence (#1943) --- google-cloud-core/pom.xml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9749ee819d..fb7d886636 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -22,12 +22,10 @@ com.google.auth google-auth-library-credentials - ${google.auth.version} com.google.auth google-auth-library-oauth2-http - ${google.auth.version} com.google.guava @@ -38,24 +36,20 @@ com.google.http-client google-http-client - 1.21.0 compile com.google.oauth-client google-oauth-client - 1.21.0 compile com.google.guava guava - 19.0 com.google.api-client google-api-client - 1.21.0 compile @@ -67,7 +61,6 @@ com.google.http-client google-http-client-appengine - 1.21.0 compile @@ -79,7 +72,6 @@ com.google.http-client google-http-client-jackson - 1.21.0 compile @@ -91,13 +83,11 @@ junit junit - 4.12 test joda-time joda-time - 2.9.2 compile @@ -115,12 +105,10 @@ com.google.protobuf protobuf-java - 3.2.0 com.google.protobuf protobuf-java-util - 3.2.0 io.grpc @@ -146,7 +134,6 @@ com.google.api.grpc grpc-google-common-protos - 0.1.7 io.grpc @@ -157,7 +144,6 @@ com.google.api.grpc grpc-google-iam-v1 - 0.1.7 io.grpc From bbcfe5a8da04666cb4db82e4c1de96f96f66415b Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 19 Apr 2017 08:50:31 -0700 Subject: [PATCH 344/663] Removing grpc-all exclusions in pom.xml (#1942) --- google-cloud-core/pom.xml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index fb7d886636..3612233177 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -119,12 +119,6 @@ com.google.api gax ${gax.version} - - - io.grpc - grpc-all - - com.google.api @@ -134,22 +128,10 @@ com.google.api.grpc grpc-google-common-protos - - - io.grpc - grpc-all - - com.google.api.grpc grpc-google-iam-v1 - - - io.grpc - grpc-all - - com.google.truth From 6af44e13dc403cdc25fd0c74967229b4ac6480c8 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Wed, 19 Apr 2017 17:12:57 -0400 Subject: [PATCH 345/663] Replace DateTime with Timestamp (#1947) --- .../main/java/com/google/cloud/Timestamp.java | 39 ++++++++++++++++++- .../java/com/google/cloud/TimestampTest.java | 9 +++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java index aedb802f58..e138343a58 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -20,6 +20,8 @@ import com.google.common.base.Strings; import com.google.protobuf.util.Timestamps; +import java.io.Serializable; +import java.util.Date; import java.util.Objects; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; @@ -34,7 +36,10 @@ * *

    {@code Timestamp} instances are immutable. */ -public final class Timestamp implements Comparable { +public final class Timestamp implements Comparable, Serializable { + + private static final long serialVersionUID = 5152143600571559844L; + /** The smallest legal timestamp ("0001-01-01T00:00:00Z"). */ public static final Timestamp MIN_VALUE = new Timestamp(-62135596800L, 0); @@ -73,6 +78,38 @@ public static Timestamp ofTimeSecondsAndNanos(long seconds, int nanos) { return new Timestamp(seconds, nanos); } + /** + * Creates an instance representing the value of {@code microseconds}. + * + * @throws IllegalArgumentException if the timestamp is outside the representable range + */ + public static Timestamp ofTimeMicroseconds(long microseconds) { + long seconds = TimeUnit.MICROSECONDS.toSeconds(microseconds); + int nanos = (int) TimeUnit.MICROSECONDS.toNanos( + microseconds - TimeUnit.SECONDS.toMicros(seconds)); + checkArgument( + Timestamps.isValid(seconds, nanos), "timestamp out of range: %s, %s", seconds, nanos); + return new Timestamp(seconds, nanos); + } + + /** + * Creates an instance representing the value of {@code Date}. + * + * @throws IllegalArgumentException if the timestamp is outside the representable range + */ + public static Timestamp of(Date date) { + return ofTimeMicroseconds(TimeUnit.MILLISECONDS.toMicros(date.getTime())); + } + + + /** + * Creates an instance with current time. + */ + public static Timestamp now() { + java.sql.Timestamp date = new java.sql.Timestamp(System.currentTimeMillis()); + return of(date); + } + /** * Creates an instance representing the value of {@code timestamp}. * diff --git a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java index 0513bc8fea..a805c06bff 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java @@ -33,6 +33,8 @@ public class TimestampTest { private static final String TEST_TIME_ISO = "2015-10-12T15:14:54Z"; private static final long TEST_TIME_SECONDS = 1444662894L; + private static final long TEST_TIME_MICROSECONDS = 10000100L; + @Rule public ExpectedException expectedException = ExpectedException.none(); @Test @@ -54,6 +56,13 @@ public void maxValue() { assertThat(Timestamp.MAX_VALUE.getNanos()).isEqualTo(999999999); } + @Test + public void ofMicroseconds() { + Timestamp timestamp = Timestamp.ofTimeMicroseconds(TEST_TIME_MICROSECONDS); + assertThat(timestamp.getSeconds()).isEqualTo(TEST_TIME_MICROSECONDS / 1000000L); + assertThat(timestamp.getNanos()).isEqualTo(TEST_TIME_MICROSECONDS % 1000000L * 1000); + } + @Test public void toFromSqlTimestamp() { long seconds = TEST_TIME_SECONDS; From 56c844881d27f417662b7475a53f3ffc64898037 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Wed, 19 Apr 2017 17:13:13 -0400 Subject: [PATCH 346/663] Make SSLHandShakeException retryable (#1938) --- .../src/main/java/com/google/cloud/BaseServiceException.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index 4bebfc9259..0e2c6156c1 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -26,9 +26,11 @@ import java.io.Serializable; import java.net.SocketException; import java.net.SocketTimeoutException; +import java.security.cert.CertificateException; import java.util.Collections; import java.util.Objects; import java.util.Set; +import javax.net.ssl.SSLHandshakeException; /** * Base class for all service exceptions. @@ -203,6 +205,8 @@ protected boolean isRetryable(boolean idempotent, Error error) { protected boolean isRetryable(boolean idempotent, IOException exception) { boolean exceptionIsRetryable = exception instanceof SocketTimeoutException || exception instanceof SocketException + || (exception instanceof SSLHandshakeException + && !(exception.getCause() instanceof CertificateException)) || "insufficient data written".equals(exception.getMessage()); return idempotent && exceptionIsRetryable; } From 7bb00d62324538e61f8532ad94fd9f908a69262a Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Fri, 21 Apr 2017 09:16:16 -0700 Subject: [PATCH 347/663] Remove guava from surface (#1960) --- .../com/google/cloud/BaseWriteChannel.java | 55 ++++++++++++++++--- .../cloud/MonitoredResourceDescriptor.java | 5 +- .../main/java/com/google/cloud/Policy.java | 23 ++++++-- 3 files changed, 66 insertions(+), 17 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index ddc191b1e4..fd8f02d195 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -16,13 +16,13 @@ package com.google.cloud; -import com.google.common.base.MoreObjects; - import java.io.IOException; import java.io.Serializable; import java.nio.ByteBuffer; import java.nio.channels.ClosedChannelException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Objects; /** @@ -295,17 +295,54 @@ public boolean equals(Object obj) { && this.chunkSize == other.chunkSize; } - protected MoreObjects.ToStringHelper toStringHelper() { - return MoreObjects.toStringHelper(this) - .add("entity", entity) - .add("uploadId", uploadId) - .add("position", position) - .add("isOpen", isOpen); + protected static final class ValueHolder { + final String name; + final Object value; + + private ValueHolder(String name, Object value) { + this.name = name; + this.value = value; + } + + public static ValueHolder create(String name, Object value) { + return new ValueHolder(name, value); + } + + @Override + public String toString() { + String result = name + "="; + if (value != null && value.getClass().isArray()) { + Object[] objectArray = new Object[]{value}; + String arrayString = Arrays.deepToString(objectArray); + result += arrayString.substring(1, arrayString.length() - 1); + } else { + result += value; + } + return result; + } + } + + protected List toStringHelper() { + List valueList = new ArrayList<>(); + valueList.add(ValueHolder.create("entity", entity)); + valueList.add(ValueHolder.create("uploadId", uploadId)); + valueList.add(ValueHolder.create("position", String.valueOf(position))); + valueList.add(ValueHolder.create("isOpen", String.valueOf(isOpen))); + return valueList; } @Override public String toString() { - return toStringHelper().toString(); + StringBuilder builder = new StringBuilder(); + builder.append(getClass().getSimpleName()) + .append('{'); + String nextSeparator = ""; + for (ValueHolder valueHolder : toStringHelper()) { + builder.append(nextSeparator).append(valueHolder); + nextSeparator = ", "; + } + builder.append('}'); + return builder.toString(); } } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java index d4529124c8..e7789d31af 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.api.core.ApiFunction; import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.collect.Iterables; @@ -37,9 +38,9 @@ public class MonitoredResourceDescriptor implements Serializable { private static final long serialVersionUID = -3702077512777687441L; - public static final Function FROM_PB_FUNCTION = - new Function() { + new ApiFunction() { @Override public MonitoredResourceDescriptor apply( com.google.api.MonitoredResourceDescriptor pb) { diff --git a/google-cloud-core/src/main/java/com/google/cloud/Policy.java b/google-cloud-core/src/main/java/com/google/cloud/Policy.java index 7f918767d5..ca79936684 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Policy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Policy.java @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.api.core.ApiFunction; import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; @@ -57,15 +58,15 @@ public final class Policy implements Serializable { public abstract static class Marshaller { - protected static final Function IDENTITY_VALUE_OF_FUNCTION = - new Function() { + protected static final ApiFunction IDENTITY_VALUE_OF_FUNCTION = + new ApiFunction() { @Override public Identity apply(String identityPb) { return Identity.valueOf(identityPb); } }; - protected static final Function IDENTITY_STR_VALUE_FUNCTION = - new Function() { + protected static final ApiFunction IDENTITY_STR_VALUE_FUNCTION = + new ApiFunction() { @Override public String apply(Identity identity) { return identity.strValue(); @@ -85,7 +86,12 @@ protected Policy fromPb(com.google.iam.v1.Policy policyPb) { for (com.google.iam.v1.Binding bindingPb : policyPb.getBindingsList()) { bindings.put(Role.of(bindingPb.getRole()), ImmutableSet.copyOf( - Lists.transform(bindingPb.getMembersList(), IDENTITY_VALUE_OF_FUNCTION))); + Lists.transform(bindingPb.getMembersList(), new Function() { + @Override + public Identity apply(String s) { + return IDENTITY_VALUE_OF_FUNCTION.apply(s); + } + }))); } return newBuilder() .setBindings(bindings) @@ -103,7 +109,12 @@ protected com.google.iam.v1.Policy toPb(Policy policy) { com.google.iam.v1.Binding.Builder bindingBuilder = com.google.iam.v1.Binding.newBuilder(); bindingBuilder.setRole(binding.getKey().getValue()); bindingBuilder.addAllMembers( - Lists.transform(new ArrayList<>(binding.getValue()), IDENTITY_STR_VALUE_FUNCTION)); + Lists.transform(new ArrayList<>(binding.getValue()), new Function() { + @Override + public String apply(Identity identity) { + return IDENTITY_STR_VALUE_FUNCTION.apply(identity); + } + })); bindingPbList.add(bindingBuilder.build()); } policyBuilder.addAllBindings(bindingPbList); From 58257cf42f588d47500d05ccdddedb8ae784c2b1 Mon Sep 17 00:00:00 2001 From: Mairbek Khadikov Date: Fri, 21 Apr 2017 11:51:31 -0700 Subject: [PATCH 348/663] Make Cloud Spanner Mutations serializable (#1952) --- google-cloud-core/src/main/java/com/google/cloud/Date.java | 5 ++++- .../src/test/java/com/google/cloud/DateTest.java | 6 ++++++ .../src/test/java/com/google/cloud/TimestampTest.java | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Date.java b/google-cloud-core/src/main/java/com/google/cloud/Date.java index 9da1bb6631..d99c6171b1 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Date.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Date.java @@ -18,6 +18,8 @@ import com.google.api.core.BetaApi; import com.google.common.base.Preconditions; + +import java.io.Serializable; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -26,10 +28,11 @@ * Represents a Date without time, such as 2017-03-17. Date is timezone independent. */ @BetaApi -public final class Date implements Comparable { +public final class Date implements Comparable, Serializable { // Date format "yyyy-mm-dd" private static final Pattern FORMAT_REGEXP = Pattern.compile("(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)"); + private static final long serialVersionUID = 8067099123096783929L; private final int year; private final int month; private final int dayOfMonth; diff --git a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java index 627b1adc10..30a872491a 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java @@ -16,6 +16,7 @@ package com.google.cloud; +import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; import com.google.common.testing.EqualsTester; @@ -65,6 +66,11 @@ public void validOrdering() { assertDescending(d5, d4, d3, d2, d1); } + @Test + public void serialization() { + reserializeAndAssert(Date.fromYearMonthDay(2017, 4, 20)); + } + private void assertDescending(Date... dates) { for (int i = 0; i < dates.length - 1; i++) { assertThat(dates[i]).isEquivalentAccordingToCompareTo(dates[i]); diff --git a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java index a805c06bff..6aaf048937 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java @@ -16,6 +16,7 @@ package com.google.cloud; +import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; import com.google.common.testing.EqualsTester; @@ -175,4 +176,9 @@ public void comparable() { assertThat(Timestamp.ofTimeSecondsAndNanos(101, 0)) .isAtLeast(Timestamp.ofTimeSecondsAndNanos(100, 1000)); } + + @Test + public void serialization() throws Exception { + reserializeAndAssert(Timestamp.parseTimestamp("9999-12-31T23:59:59.999999999Z")); + } } From ee4ea7ca73cc49f19048ad4792a0143280f0acba Mon Sep 17 00:00:00 2001 From: vam Date: Fri, 21 Apr 2017 14:46:17 -0700 Subject: [PATCH 349/663] Release 0.14.0; release 1.0.0-rc1 for google-cloud-core, google-cloud-logging, google-cloud-storage, google-cloud-datastore --- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 9270479b66..18676c4ef8 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 0.13.0-alpha + 1.0.0-rc1 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:0.13.0-alpha' +compile 'com.google.cloud:google-cloud-core:1.0.0-rc1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "0.13.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.0-rc1" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3612233177..f3249ea605 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 0.13.1-alpha-SNAPSHOT + 1.0.0-rc1 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.13.1-alpha-SNAPSHOT + 0.14.0-alpha google-cloud-core From 509ca043377663bf7881be9217ef1beb931a60ff Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Fri, 21 Apr 2017 16:11:59 -0700 Subject: [PATCH 350/663] Bump version to 0.14.1-SNAPSHOT (#1967) --- google-cloud-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f3249ea605..ff15957f8f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.0-rc1 + 1.0.1-rc1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.14.0-alpha + 0.14.1-alpha-SNAPSHOT google-cloud-core From dc86451e16156e21b4093be4790e5213651945a6 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Fri, 21 Apr 2017 17:22:46 -0700 Subject: [PATCH 351/663] Bump RC versions to 1.0.0-rc2-SNAPSHOT (#1969) --- google-cloud-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index ff15957f8f..27860ab674 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.1-rc1-SNAPSHOT + 1.0.0-rc2-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core From e854eacda0b80e08650543760ad445420eea7f62 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 21 Apr 2017 17:54:51 -0700 Subject: [PATCH 352/663] Splitting core into core, core-http, and core-grpc (#1968) --- google-cloud-core-grpc/pom.xml | 92 ++++++ .../cloud/grpc/BaseGrpcServiceException.java | 75 +++++ .../cloud/grpc}/GrpcTransportOptions.java | 14 +- .../grpc/BaseGrpcServiceExceptionTest.java | 106 +++++++ .../cloud/grpc}/GrpcTransportOptionsTest.java | 7 +- google-cloud-core-http/pom.xml | 132 ++++++++ .../cloud/http/BaseHttpServiceException.java | 146 +++++++++ .../cloud/http}/HttpTransportOptions.java | 5 +- .../http/BaseHttpServiceExceptionTest.java | 165 ++++++++++ .../cloud/http}/HttpTransportOptionsTest.java | 5 +- google-cloud-core/pom.xml | 76 +---- .../java/com/google/cloud/AsyncPageImpl.java | 4 +- .../google/cloud/BaseServiceException.java | 297 +++++++++--------- .../main/java/com/google/cloud/PageImpl.java | 2 +- .../java/com/google/cloud/RetryHelper.java | 2 +- .../java/com/google/cloud/ServiceOptions.java | 9 +- .../com/google/cloud/AsyncPageImplTest.java | 2 +- .../cloud/BaseServiceExceptionTest.java | 98 ++---- .../com/google/cloud/BatchResultTest.java | 7 +- .../java/com/google/cloud/PageImplTest.java | 2 +- .../com/google/cloud/SerializationTest.java | 5 +- .../com/google/cloud/ServiceOptionsTest.java | 2 +- 22 files changed, 946 insertions(+), 307 deletions(-) create mode 100644 google-cloud-core-grpc/pom.xml create mode 100644 google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java rename {google-cloud-core/src/main/java/com/google/cloud => google-cloud-core-grpc/src/main/java/com/google/cloud/grpc}/GrpcTransportOptions.java (94%) create mode 100644 google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java rename {google-cloud-core/src/test/java/com/google/cloud => google-cloud-core-grpc/src/test/java/com/google/cloud/grpc}/GrpcTransportOptionsTest.java (92%) create mode 100644 google-cloud-core-http/pom.xml create mode 100644 google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java rename {google-cloud-core/src/main/java/com/google/cloud => google-cloud-core-http/src/main/java/com/google/cloud/http}/HttpTransportOptions.java (97%) create mode 100644 google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java rename {google-cloud-core/src/test/java/com/google/cloud => google-cloud-core-http/src/test/java/com/google/cloud/http}/HttpTransportOptionsTest.java (94%) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml new file mode 100644 index 0000000000..af23786393 --- /dev/null +++ b/google-cloud-core-grpc/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + google-cloud-core-grpc + 1.0.0-rc2-SNAPSHOT + jar + Google Cloud Core gRPC + https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc + + Core gRPC module for the google-cloud. + + + com.google.cloud + google-cloud-pom + 0.14.1-alpha-SNAPSHOT + + + google-cloud-core-grpc + ${project.version} + + + + com.google.cloud + google-cloud-core + ${core.version} + + + com.google.guava + guava + + + junit + junit + test + + + org.easymock + easymock + 3.4 + test + + + com.google.protobuf + protobuf-java + + + com.google.protobuf + protobuf-java-util + + + io.grpc + grpc-protobuf + ${grpc.version} + + + com.google.api + gax-grpc + + + com.google.truth + truth + 0.30 + test + + + com.google.guava + guava-testlib + 19.0 + test + + + + + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + + generate-resources + + write-project-properties + + + ${project.build.outputDirectory}/com/google/cloud/project.properties + + + + + + + diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java new file mode 100644 index 0000000000..fcefe6a8e9 --- /dev/null +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java @@ -0,0 +1,75 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.grpc; + +import com.google.api.client.http.HttpResponseException; +import com.google.api.gax.grpc.ApiException; +import com.google.cloud.BaseServiceException; +import com.google.common.base.MoreObjects; +import java.io.IOException; +import java.util.Collections; + +/** + * Base class for all exceptions from grpc-based services. + */ +public class BaseGrpcServiceException extends BaseServiceException { + + private static final long serialVersionUID = -2685197215731335549L; + + public BaseGrpcServiceException(String message, Throwable cause, int code, boolean retryable) { + super(ExceptionData.newBuilder().setMessage(message).setCause(cause).setCode(code) + .setRetryable(retryable).build()); + } + + public BaseGrpcServiceException(IOException exception, boolean idempotent) { + super(makeExceptionData(exception, idempotent)); + } + + private static ExceptionData makeExceptionData(IOException exception, boolean idempotent) { + int code = UNKNOWN_CODE; + Boolean retryable = null; + if (exception instanceof HttpResponseException) { + // In cases where an exception is an instance of HttpResponseException, + // check the status code to determine whether it's retryable + code = ((HttpResponseException) exception).getStatusCode(); + retryable = BaseServiceException + .isRetryable(code, null, idempotent, Collections.emptySet()); + } + return ExceptionData.newBuilder() + .setMessage(exception.getMessage()) + .setCause(exception) + .setRetryable(MoreObjects + .firstNonNull(retryable, BaseServiceException.isRetryable(idempotent, exception))) + .setCode(code) + .setReason(null) + .setLocation(null) + .setDebugInfo(null) + .build(); + } + + public BaseGrpcServiceException(ApiException apiException) { + super(ExceptionData.newBuilder() + .setMessage(apiException.getMessage()) + .setCause(apiException) + .setRetryable(apiException.isRetryable()) + .setCode(apiException.getStatusCode().value()) + .setReason(apiException.getStatusCode().name()) + .setLocation(null) + .setDebugInfo(null) + .build()); + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java similarity index 94% rename from google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java rename to google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java index 15fb9a7311..14df145317 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcTransportOptions.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java @@ -14,18 +14,20 @@ * limitations under the License. */ -package com.google.cloud; +package com.google.cloud.grpc; import static com.google.common.base.MoreObjects.firstNonNull; +import com.google.api.core.InternalApi; import com.google.api.gax.core.FixedCredentialsProvider; -import com.google.api.gax.core.RetrySettings; import com.google.api.gax.grpc.ChannelProvider; import com.google.api.gax.grpc.InstantiatingChannelProvider; import com.google.api.gax.grpc.UnaryCallSettings; +import com.google.api.gax.retrying.RetrySettings; import com.google.auth.Credentials; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; +import com.google.cloud.NoCredentials; +import com.google.cloud.ServiceOptions; +import com.google.cloud.TransportOptions; import io.grpc.internal.SharedResourceHolder; import io.grpc.internal.SharedResourceHolder.Resource; import java.io.IOException; @@ -92,8 +94,8 @@ public interface ExecutorFactory { void release(T executor); } - @VisibleForTesting - static class DefaultExecutorFactory implements ExecutorFactory { + @InternalApi + public static class DefaultExecutorFactory implements ExecutorFactory { private static final DefaultExecutorFactory INSTANCE = new DefaultExecutorFactory(); diff --git a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java new file mode 100644 index 0000000000..c7ce99bb39 --- /dev/null +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java @@ -0,0 +1,106 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.grpc; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import com.google.api.gax.grpc.ApiException; +import com.google.cloud.BaseServiceException; +import com.google.cloud.RetryHelper; +import io.grpc.Status.Code; +import java.io.IOException; +import java.net.SocketException; +import java.net.SocketTimeoutException; +import org.junit.Test; + +public class BaseGrpcServiceExceptionTest { + + private static final int CODE = 1; + private static final String MESSAGE = "some message"; + private static final boolean NOT_RETRYABLE = false; + private static final boolean IDEMPOTENT = true; + + @Test + public void testBaseServiceException() { + BaseGrpcServiceException serviceException = null; + + IOException exception = new SocketTimeoutException(); + serviceException = new BaseGrpcServiceException(exception, IDEMPOTENT); + assertTrue(serviceException.isRetryable()); + assertNull(serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + assertNull(serviceException.getReason()); + assertNull(serviceException.getLocation()); + assertNull(serviceException.getDebugInfo()); + + exception = new SocketException(); + serviceException = new BaseGrpcServiceException(exception, IDEMPOTENT); + assertTrue(serviceException.isRetryable()); + assertNull(serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + assertNull(serviceException.getReason()); + assertNull(serviceException.getLocation()); + assertNull(serviceException.getDebugInfo()); + + exception = new IOException("insufficient data written"); + serviceException = new BaseGrpcServiceException(exception, IDEMPOTENT); + assertTrue(serviceException.isRetryable()); + assertEquals("insufficient data written", serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + assertNull(serviceException.getReason()); + assertNull(serviceException.getLocation()); + assertNull(serviceException.getDebugInfo()); + + Exception cause = new IllegalArgumentException("bad arg"); + ApiException apiException = new ApiException(MESSAGE, cause, Code.INTERNAL, NOT_RETRYABLE); + serviceException = new BaseGrpcServiceException(apiException); + assertFalse(serviceException.isRetryable()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(apiException, serviceException.getCause()); + assertEquals(Code.INTERNAL.value(), serviceException.getCode()); + assertEquals(Code.INTERNAL.name(), serviceException.getReason()); + assertNull(serviceException.getLocation()); + assertNull(serviceException.getDebugInfo()); + } + + @Test + public void testTranslateAndThrow() throws Exception { + IOException exception = new SocketTimeoutException(); + BaseGrpcServiceException cause = new BaseGrpcServiceException(exception, IDEMPOTENT); + RetryHelper.RetryHelperException exceptionMock = + createMock(RetryHelper.RetryHelperException.class); + expect(exceptionMock.getCause()).andReturn(cause).times(2); + replay(exceptionMock); + try { + BaseServiceException.translate(exceptionMock); + } catch (BaseServiceException ex) { + assertEquals(0, ex.getCode()); + assertNull(ex.getMessage()); + assertTrue(ex.isRetryable()); + } finally { + verify(exceptionMock); + } + } + +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java similarity index 92% rename from google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java rename to google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java index 1bcc54af6a..7aff66b2d6 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/GrpcTransportOptionsTest.java +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java @@ -14,16 +14,15 @@ * limitations under the License. */ -package com.google.cloud; +package com.google.cloud.grpc; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import com.google.cloud.GrpcTransportOptions.DefaultExecutorFactory; -import com.google.cloud.GrpcTransportOptions.ExecutorFactory; +import com.google.cloud.grpc.GrpcTransportOptions.DefaultExecutorFactory; +import com.google.cloud.grpc.GrpcTransportOptions.ExecutorFactory; import java.util.concurrent.ScheduledExecutorService; import org.easymock.EasyMock; import org.junit.Test; diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml new file mode 100644 index 0000000000..a23ea864ef --- /dev/null +++ b/google-cloud-core-http/pom.xml @@ -0,0 +1,132 @@ + + + 4.0.0 + google-cloud-core-http + 1.0.0-rc2-SNAPSHOT + jar + Google Cloud Core HTTP + https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http + + Core http module for the google-cloud. + + + com.google.cloud + google-cloud-pom + 0.14.1-alpha-SNAPSHOT + + + google-cloud-core-http + ${project.version} + + + + com.google.cloud + google-cloud-core + ${core.version} + + + com.google.auth + google-auth-library-credentials + + + com.google.auth + google-auth-library-oauth2-http + + + com.google.guava + guava-jdk5 + + + + + com.google.http-client + google-http-client + compile + + + com.google.oauth-client + google-oauth-client + compile + + + com.google.guava + guava + + + com.google.api-client + google-api-client + compile + + + guava-jdk5 + com.google.guava + + + + + com.google.http-client + google-http-client-appengine + compile + + + guava-jdk5 + com.google.guava + + + + + com.google.http-client + google-http-client-jackson + compile + + + guava-jdk5 + com.google.guava + + + + + junit + junit + test + + + org.easymock + easymock + 3.4 + test + + + com.google.truth + truth + 0.30 + test + + + com.google.guava + guava-testlib + 19.0 + test + + + + + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + + generate-resources + + write-project-properties + + + ${project.build.outputDirectory}/com/google/cloud/project.properties + + + + + + + diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java new file mode 100644 index 0000000000..b1ffa29838 --- /dev/null +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java @@ -0,0 +1,146 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.http; + +import com.google.api.client.googleapis.json.GoogleJsonError; +import com.google.api.client.googleapis.json.GoogleJsonResponseException; +import com.google.api.client.http.HttpResponseException; +import com.google.cloud.BaseServiceException; +import com.google.common.base.MoreObjects; +import java.io.IOException; +import java.util.Set; + +/** + * Base class for all exceptions from http-based services. + */ +public class BaseHttpServiceException extends BaseServiceException { + + private static final long serialVersionUID = -5793034110344127954L; + public static final int UNKNOWN_CODE = 0; + + public BaseHttpServiceException(IOException exception, boolean idempotent, + Set retryableErrors) { + super(makeExceptionData(exception, idempotent, retryableErrors)); + } + + private static ExceptionData makeExceptionData(IOException exception, boolean idempotent, + Set retryableErrors) { + int code = UNKNOWN_CODE; + String reason = null; + String location = null; + String debugInfo = null; + Boolean retryable = null; + if (exception instanceof HttpResponseException) { + if (exception instanceof GoogleJsonResponseException) { + GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails(); + if (jsonError != null) { + BaseServiceException.Error error = new BaseServiceException.Error(jsonError.getCode(), + reason(jsonError)); + code = error.getCode(); + reason = error.getReason(); + retryable = error.isRetryable(idempotent, retryableErrors); + if (reason != null) { + GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0); + location = errorInfo.getLocation(); + debugInfo = (String) errorInfo.get("debugInfo"); + } + } else { + code = ((GoogleJsonResponseException) exception).getStatusCode(); + } + } else { + // In cases where an exception is an instance of HttpResponseException but not + // an instance of GoogleJsonResponseException, check the status code to determine whether it's retryable + code = ((HttpResponseException) exception).getStatusCode(); + retryable = BaseServiceException.isRetryable(code, null, idempotent, retryableErrors); + } + } + return ExceptionData.newBuilder() + .setMessage(message(exception)) + .setCause(exception) + .setRetryable(MoreObjects + .firstNonNull(retryable, BaseServiceException.isRetryable(idempotent, exception))) + .setCode(code) + .setReason(reason) + .setLocation(location) + .setDebugInfo(debugInfo) + .build(); + } + + public BaseHttpServiceException(GoogleJsonError googleJsonError, boolean idempotent, + Set retryableErrors) { + super(makeExceptionData(googleJsonError, idempotent, retryableErrors)); + } + + private static ExceptionData makeExceptionData(GoogleJsonError googleJsonError, boolean idempotent, + Set retryableErrors) { + int code = googleJsonError.getCode(); + String reason = reason(googleJsonError); + + ExceptionData.Builder exceptionData = ExceptionData.newBuilder(); + exceptionData + .setMessage(googleJsonError.getMessage()) + .setCause(null) + .setRetryable(BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors)) + .setCode(code) + .setReason(reason); + if (reason != null) { + GoogleJsonError.ErrorInfo errorInfo = googleJsonError.getErrors().get(0); + exceptionData.setLocation(errorInfo.getLocation()); + exceptionData.setDebugInfo((String) errorInfo.get("debugInfo")); + } else { + exceptionData.setLocation(null); + exceptionData.setDebugInfo(null); + } + return exceptionData.build(); + } + + public BaseHttpServiceException(int code, String message, String reason, boolean idempotent, + Set retryableErrors) { + this(code, message, reason, idempotent, retryableErrors, null); + } + + public BaseHttpServiceException(int code, String message, String reason, boolean idempotent, + Set retryableErrors, Throwable cause) { + super(ExceptionData.newBuilder() + .setMessage(message) + .setCause(cause) + .setRetryable(BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors)) + .setCode(code) + .setReason(reason) + .setLocation(null) + .setDebugInfo(null) + .build()); + } + + private static String reason(GoogleJsonError error) { + if (error.getErrors() != null && !error.getErrors().isEmpty()) { + return error.getErrors().get(0).getReason(); + } + return null; + } + + private static String message(IOException exception) { + if (exception instanceof GoogleJsonResponseException) { + GoogleJsonError details = ((GoogleJsonResponseException) exception).getDetails(); + if (details != null) { + return details.getMessage(); + } + } + return exception.getMessage(); + } + +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java similarity index 97% rename from google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java rename to google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java index a2a99a28d9..1a4f25158e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpTransportOptions.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.cloud; +package com.google.cloud.http; import static com.google.common.base.MoreObjects.firstNonNull; @@ -27,6 +27,9 @@ import com.google.auth.Credentials; import com.google.auth.http.HttpCredentialsAdapter; import com.google.auth.http.HttpTransportFactory; +import com.google.cloud.NoCredentials; +import com.google.cloud.ServiceOptions; +import com.google.cloud.TransportOptions; import java.io.IOException; import java.io.ObjectInputStream; import java.util.Objects; diff --git a/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java new file mode 100644 index 0000000000..0031f32e36 --- /dev/null +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java @@ -0,0 +1,165 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.http; + +import static com.google.cloud.BaseServiceException.UNKNOWN_CODE; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import com.google.api.client.googleapis.json.GoogleJsonError; +import com.google.cloud.BaseServiceException; +import com.google.cloud.RetryHelper; +import com.google.common.collect.ImmutableSet; +import java.io.IOException; +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.util.Collections; +import java.util.Set; +import org.junit.Test; + +public class BaseHttpServiceExceptionTest { + + private static final int CODE = 1; + private static final int CODE_NO_REASON = 2; + private static final String MESSAGE = "some message"; + private static final String REASON = "some reason"; + private static final boolean RETRYABLE = true; + private static final boolean IDEMPOTENT = true; + private static final boolean NOT_IDEMPOTENT = false; + private static final Set EMPTY_RETRYABLE_ERRORS = + Collections.emptySet(); + + private static class CustomServiceException extends BaseHttpServiceException { + + private static final long serialVersionUID = -195251309124875103L; + + public CustomServiceException(int code, String message, String reason, boolean idempotent) { + super(code, message, reason, idempotent, RETRYABLE_ERRORS); + } + + private static final Set RETRYABLE_ERRORS = ImmutableSet + .of(new Error(CODE, REASON), new Error(null, REASON), + new Error(CODE_NO_REASON, null)); + } + + @Test + public void testBaseServiceException() { + BaseServiceException serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, + IDEMPOTENT, EMPTY_RETRYABLE_ERRORS); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertFalse(serviceException.isRetryable()); + assertNull(serviceException.getCause()); + + serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, + EMPTY_RETRYABLE_ERRORS); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertFalse(serviceException.isRetryable()); + assertNull(serviceException.getCause()); + + Exception cause = new RuntimeException(); + serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, + EMPTY_RETRYABLE_ERRORS, cause); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertFalse(serviceException.isRetryable()); + assertEquals(cause, serviceException.getCause()); + + serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, NOT_IDEMPOTENT, + EMPTY_RETRYABLE_ERRORS, cause); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertFalse(serviceException.isRetryable()); + assertEquals(cause, serviceException.getCause()); + + IOException exception = new SocketTimeoutException(); + serviceException = new BaseHttpServiceException(exception, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS); + assertTrue(serviceException.isRetryable()); + assertNull(serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + + exception = new SocketException(); + serviceException = new BaseHttpServiceException(exception, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS); + assertTrue(serviceException.isRetryable()); + assertNull(serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + + exception = new IOException("insufficient data written"); + serviceException = new BaseHttpServiceException(exception, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS); + assertTrue(serviceException.isRetryable()); + assertEquals("insufficient data written", serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + + GoogleJsonError error = new GoogleJsonError(); + error.setCode(CODE); + error.setMessage(MESSAGE); + serviceException = new BaseHttpServiceException(error, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertFalse(serviceException.isRetryable()); + + serviceException = new CustomServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); + assertEquals(CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertEquals(RETRYABLE, serviceException.isRetryable()); + + serviceException = new CustomServiceException(CODE_NO_REASON, MESSAGE, null, IDEMPOTENT); + assertEquals(CODE_NO_REASON, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertNull(serviceException.getReason()); + assertEquals(RETRYABLE, serviceException.isRetryable()); + + serviceException = new CustomServiceException(UNKNOWN_CODE, MESSAGE, REASON, IDEMPOTENT); + assertEquals(UNKNOWN_CODE, serviceException.getCode()); + assertEquals(MESSAGE, serviceException.getMessage()); + assertEquals(REASON, serviceException.getReason()); + assertEquals(RETRYABLE, serviceException.isRetryable()); + } + + @Test + public void testTranslateAndThrow() throws Exception { + BaseServiceException cause = + new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS); + RetryHelper.RetryHelperException exceptionMock = + createMock(RetryHelper.RetryHelperException.class); + expect(exceptionMock.getCause()).andReturn(cause).times(2); + replay(exceptionMock); + try { + BaseServiceException.translate(exceptionMock); + } catch (BaseServiceException ex) { + assertEquals(CODE, ex.getCode()); + assertEquals(MESSAGE, ex.getMessage()); + assertFalse(ex.isRetryable()); + } finally { + verify(exceptionMock); + } + } + + +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java similarity index 94% rename from google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java rename to google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java index 4d828ea6e7..4240aa9172 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/HttpTransportOptionsTest.java +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.cloud; +package com.google.cloud.http; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -22,7 +22,8 @@ import static org.junit.Assert.assertTrue; import com.google.auth.http.HttpTransportFactory; -import com.google.cloud.HttpTransportOptions.DefaultHttpTransportFactory; +import com.google.cloud.ServiceOptions; +import com.google.cloud.http.HttpTransportOptions.DefaultHttpTransportFactory; import java.util.regex.Pattern; import org.easymock.EasyMock; import org.junit.Test; diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 27860ab674..c17f4b0ff1 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -19,67 +19,10 @@ ${project.version} - - com.google.auth - google-auth-library-credentials - - - com.google.auth - google-auth-library-oauth2-http - - - com.google.guava - guava-jdk5 - - - - - com.google.http-client - google-http-client - compile - - - com.google.oauth-client - google-oauth-client - compile - com.google.guava guava - - com.google.api-client - google-api-client - compile - - - guava-jdk5 - com.google.guava - - - - - com.google.http-client - google-http-client-appengine - compile - - - guava-jdk5 - com.google.guava - - - - - com.google.http-client - google-http-client-jackson - compile - - - guava-jdk5 - com.google.guava - - - junit junit @@ -103,28 +46,15 @@ test - com.google.protobuf - protobuf-java - - - com.google.protobuf - protobuf-java-util - - - io.grpc - grpc-protobuf - ${grpc.version} + com.google.api + api-common + ${api-common.version} com.google.api gax ${gax.version} - - com.google.api - api-common - ${api-common.version} - com.google.api.grpc grpc-google-common-protos diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index f72783cf87..8048b9e18f 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -19,8 +19,8 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; import com.google.api.core.InternalApi; -import com.google.api.gax.core.AsyncPage; -import com.google.api.gax.core.Page; +import com.google.api.gax.paging.AsyncPage; +import com.google.api.gax.paging.Page; import com.google.common.base.Throwables; import com.google.common.util.concurrent.Uninterruptibles; import java.io.Serializable; diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index 0e2c6156c1..f7ded9900b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -16,18 +16,13 @@ package com.google.cloud; -import com.google.api.client.googleapis.json.GoogleJsonError; -import com.google.api.client.googleapis.json.GoogleJsonResponseException; -import com.google.api.client.http.HttpResponseException; -import com.google.api.gax.grpc.ApiException; +import com.google.api.core.InternalApi; import com.google.common.base.MoreObjects; - import java.io.IOException; import java.io.Serializable; import java.net.SocketException; import java.net.SocketTimeoutException; import java.security.cert.CertificateException; -import java.util.Collections; import java.util.Objects; import java.util.Set; import javax.net.ssl.SSLHandshakeException; @@ -43,11 +38,131 @@ public class BaseServiceException extends RuntimeException { private final int code; private final boolean retryable; private final String reason; - private final boolean idempotent; private final String location; private final String debugInfo; - protected static final class Error implements Serializable { + @InternalApi + public static final class ExceptionData implements Serializable { + private static final long serialVersionUID = 2222230861338426753L; + + private final String message; + private final Throwable cause; + private final int code; + private final boolean retryable; + private final String reason; + private final String location; + private final String debugInfo; + + private ExceptionData(String message, Throwable cause, int code, boolean retryable, + String reason, String location, String debugInfo) { + this.message = message; + this.cause = cause; + this.code = code; + this.retryable = retryable; + this.reason = reason; + this.location = location; + this.debugInfo = debugInfo; + } + + public String getMessage() { + return message; + } + + public Throwable getCause() { + return cause; + } + + public int getCode() { + return code; + } + + public boolean isRetryable() { + return retryable; + } + + public String getReason() { + return reason; + } + + public String getLocation() { + return location; + } + + public String getDebugInfo() { + return debugInfo; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public static ExceptionData from(int code, String message, String reason, boolean retryable) { + return from(code, message, reason, retryable, null); + } + + public static ExceptionData from(int code, String message, String reason, boolean retryable, + Throwable cause) { + return newBuilder().setCode(code).setMessage(message).setReason(reason) + .setRetryable(retryable).setCause(cause).build(); + } + + @InternalApi + public static final class Builder { + + private String message; + private Throwable cause; + private int code; + private boolean retryable; + private String reason; + private String location; + private String debugInfo; + + private Builder() {} + + public Builder setMessage(String message) { + this.message = message; + return this; + } + + public Builder setCause(Throwable cause) { + this.cause = cause; + return this; + } + + public Builder setCode(int code) { + this.code = code; + return this; + } + + public Builder setRetryable(boolean retryable) { + this.retryable = retryable; + return this; + } + + public Builder setReason(String reason) { + this.reason = reason; + return this; + } + + public Builder setLocation(String location) { + this.location = location; + return this; + } + + public Builder setDebugInfo(String debugInfo) { + this.debugInfo = debugInfo; + return this; + } + + public ExceptionData build() { + return new ExceptionData(message, cause, code, retryable, reason, location, + debugInfo); + } + } + } + + @InternalApi + public static final class Error implements Serializable { private static final long serialVersionUID = -4019600198652965721L; @@ -91,15 +206,9 @@ public String getReason() { return reason; } - boolean isRetryable(boolean idempotent, Set retryableErrors) { - for (Error retryableError : retryableErrors) { - if ((retryableError.getCode() == null || retryableError.getCode().equals(this.getCode())) - && (retryableError.getReason() == null - || retryableError.getReason().equals(this.getReason()))) { - return idempotent || retryableError.isRejected(); - } - } - return false; + @InternalApi + public boolean isRetryable(boolean idempotent, Set retryableErrors) { + return BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors); } @Override @@ -113,104 +222,45 @@ public int hashCode() { } } - public BaseServiceException(IOException exception, boolean idempotent) { - super(message(exception), exception); - int code = UNKNOWN_CODE; - String reason = null; - String location = null; - String debugInfo = null; - Boolean retryable = null; - if (exception instanceof HttpResponseException) { - if (exception instanceof GoogleJsonResponseException) { - GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails(); - if (jsonError != null) { - Error error = new Error(jsonError.getCode(), reason(jsonError)); - code = error.code; - reason = error.reason; - retryable = isRetryable(idempotent, error); - if (reason != null) { - GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0); - location = errorInfo.getLocation(); - debugInfo = (String) errorInfo.get("debugInfo"); - } - } else { - code = ((GoogleJsonResponseException) exception).getStatusCode(); - } - } else { - // In cases where an exception is an instance of HttpResponseException but not - // an instance of GoogleJsonResponseException, check the status code to determine whether it's retryable - code = ((HttpResponseException) exception).getStatusCode(); - retryable = isRetryable(idempotent, new Error(code, null)); - } - } - this.retryable = MoreObjects.firstNonNull(retryable, isRetryable(idempotent, exception)); - this.code = code; - this.reason = reason; - this.idempotent = idempotent; - this.location = location; - this.debugInfo = debugInfo; - } - public BaseServiceException(GoogleJsonError googleJsonError, boolean idempotent) { - super(googleJsonError.getMessage()); - Error error = new Error(googleJsonError.getCode(), reason(googleJsonError)); - this.code = error.code; - this.reason = error.reason; - this.retryable = isRetryable(idempotent, error); - if (this.reason != null) { - GoogleJsonError.ErrorInfo errorInfo = googleJsonError.getErrors().get(0); - this.location = errorInfo.getLocation(); - this.debugInfo = (String) errorInfo.get("debugInfo"); - } else { - this.location = null; - this.debugInfo = null; + @InternalApi + public static boolean isRetryable(Integer code, String reason, boolean idempotent, + Set retryableErrors) { + for (Error retryableError : retryableErrors) { + if ((retryableError.getCode() == null || retryableError.getCode().equals(code)) + && (retryableError.getReason() == null + || retryableError.getReason().equals(reason))) { + return idempotent || retryableError.isRejected(); + } } - this.idempotent = idempotent; + return false; } - public BaseServiceException(int code, String message, String reason, boolean idempotent) { - this(code, message, reason, idempotent, null); - } - - public BaseServiceException(int code, String message, String reason, boolean idempotent, - Throwable cause) { - super(message, cause); - this.code = code; - this.reason = reason; - this.idempotent = idempotent; - this.retryable = isRetryable(idempotent, new Error(code, reason)); - this.location = null; - this.debugInfo = null; - } - - public BaseServiceException(ApiException apiException, boolean idempotent) { - super(apiException.getMessage(), apiException); - this.code = apiException.getStatusCode().value(); - this.reason = apiException.getStatusCode().name(); - this.idempotent = idempotent; - this.retryable = apiException.isRetryable(); - this.location = null; - this.debugInfo = null; - } - - - protected Set getRetryableErrors() { - return Collections.emptySet(); - } - - protected boolean isRetryable(boolean idempotent, Error error) { - return error.isRetryable(idempotent, getRetryableErrors()); - } - - protected boolean isRetryable(boolean idempotent, IOException exception) { + @InternalApi + public static boolean isRetryable(boolean idempotent, IOException exception) { boolean exceptionIsRetryable = exception instanceof SocketTimeoutException || exception instanceof SocketException || (exception instanceof SSLHandshakeException - && !(exception.getCause() instanceof CertificateException)) + && !(exception.getCause() instanceof CertificateException)) || "insufficient data written".equals(exception.getMessage()); return idempotent && exceptionIsRetryable; } + @InternalApi + public static void translate(RetryHelper.RetryHelperException ex) { + if (ex.getCause() instanceof BaseServiceException) { + throw (BaseServiceException) ex.getCause(); + } + } + + public BaseServiceException(ExceptionData exceptionData) { + super(exceptionData.getMessage(), exceptionData.getCause()); + this.code = exceptionData.getCode(); + this.reason = exceptionData.getReason(); + this.retryable = exceptionData.isRetryable(); + this.location = exceptionData.getLocation(); + this.debugInfo = exceptionData.getDebugInfo(); + } /** * Returns the code associated with this exception. @@ -236,14 +286,6 @@ public boolean isRetryable() { } - /** - * Returns {@code true} when the operation that caused this exception had no side effects. - */ - public boolean isIdempotent() { - return idempotent; - } - - /** * Returns the service location where the error causing the exception occurred. Returns {@code * null} if not available. @@ -252,8 +294,8 @@ public String getLocation() { return location; } - - protected String getDebugInfo() { + @InternalApi + public String getDebugInfo() { return debugInfo; } @@ -271,37 +313,12 @@ public boolean equals(Object obj) { && code == other.code && retryable == other.retryable && Objects.equals(reason, other.reason) - && idempotent == other.idempotent && Objects.equals(location, other.location) && Objects.equals(debugInfo, other.debugInfo); } @Override public int hashCode() { - return Objects.hash(getCause(), getMessage(), code, retryable, reason, idempotent, location, - debugInfo); - } - - private static String reason(GoogleJsonError error) { - if (error.getErrors() != null && !error.getErrors().isEmpty()) { - return error.getErrors().get(0).getReason(); - } - return null; - } - - private static String message(IOException exception) { - if (exception instanceof GoogleJsonResponseException) { - GoogleJsonError details = ((GoogleJsonResponseException) exception).getDetails(); - if (details != null) { - return details.getMessage(); - } - } - return exception.getMessage(); - } - - protected static void translate(RetryHelper.RetryHelperException ex) { - if (ex.getCause() instanceof BaseServiceException) { - throw (BaseServiceException) ex.getCause(); - } + return Objects.hash(getCause(), getMessage(), code, retryable, reason, location, debugInfo); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java index e49e1e75a6..b7309aab5d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java @@ -17,7 +17,7 @@ package com.google.cloud; import com.google.api.core.InternalApi; -import com.google.api.gax.core.Page; +import com.google.api.gax.paging.Page; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableMap; import java.io.Serializable; diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index 7ee7fb3583..2e9434a0d2 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -17,7 +17,7 @@ package com.google.cloud; import com.google.api.core.ApiClock; -import com.google.api.gax.core.RetrySettings; +import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.retrying.DirectRetryingExecutor; import com.google.api.gax.retrying.ExponentialRetryAlgorithm; diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 0db8f08c4d..0e20848962 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -23,8 +23,9 @@ import com.google.api.core.ApiClock; import com.google.api.core.CurrentMillisClock; +import com.google.api.core.InternalApi; import com.google.api.gax.core.PropertiesProvider; -import com.google.api.gax.core.RetrySettings; +import com.google.api.gax.retrying.RetrySettings; import com.google.auth.Credentials; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; @@ -558,7 +559,8 @@ private void readObject(ObjectInputStream input) throws IOException, ClassNotFou } @SuppressWarnings("unchecked") - static T newInstance(String className) throws IOException, ClassNotFoundException { + @InternalApi + public static T newInstance(String className) throws IOException, ClassNotFoundException { try { return (T) Class.forName(className).newInstance(); } catch (InstantiationException | IllegalAccessException e) { @@ -599,7 +601,8 @@ protected RetrySettings defaultRetrySettings() { return getDefaultRetrySettings(); } - static T getFromServiceLoader(Class clazz, T defaultInstance) { + @InternalApi + public static T getFromServiceLoader(Class clazz, T defaultInstance) { return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java index 021a694a73..50f19725c8 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java @@ -20,7 +20,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; -import com.google.api.gax.core.AsyncPage; +import com.google.api.gax.paging.AsyncPage; import com.google.common.collect.ImmutableList; import org.junit.Test; diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index 7992f9e803..80476fdb03 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -26,15 +26,10 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import com.google.api.client.googleapis.json.GoogleJsonError; +import com.google.cloud.BaseServiceException.ExceptionData; import com.google.common.collect.ImmutableSet; - -import org.junit.Test; - -import java.io.IOException; -import java.net.SocketException; -import java.net.SocketTimeoutException; import java.util.Set; +import org.junit.Test; /** * Tests for {@link BaseServiceException}. @@ -45,114 +40,84 @@ public class BaseServiceExceptionTest { private static final int CODE_NO_REASON = 2; private static final String MESSAGE = "some message"; private static final String REASON = "some reason"; + private static final boolean NOT_RETRYABLE = false; private static final boolean RETRYABLE = true; private static final boolean IDEMPOTENT = true; + private static final String DEBUG_INFO = "debugInfo"; + private static final String LOCATION = "location"; + private static class CustomServiceException extends BaseServiceException { private static final long serialVersionUID = -195251309124875103L; public CustomServiceException(int code, String message, String reason, boolean idempotent) { - super(code, message, reason, idempotent); + super(ExceptionData.from(code, message, reason, + BaseServiceException.isRetryable(code, reason, idempotent, RETRYABLE_ERRORS))); } - @Override - protected Set getRetryableErrors() { - return ImmutableSet.of(new Error(CODE, REASON), new Error(null, REASON), - new Error(CODE_NO_REASON, null)); - } + private static final Set RETRYABLE_ERRORS = ImmutableSet + .of(new Error(CODE, REASON), + new Error(null, REASON), + new Error(CODE_NO_REASON, null)); } @Test public void testBaseServiceException() { - BaseServiceException serviceException = new BaseServiceException(CODE, MESSAGE, REASON, - IDEMPOTENT); + BaseServiceException serviceException = + new BaseServiceException(ExceptionData.from(CODE, MESSAGE, REASON, NOT_RETRYABLE)); assertEquals(CODE, serviceException.getCode()); assertEquals(MESSAGE, serviceException.getMessage()); assertEquals(REASON, serviceException.getReason()); assertFalse(serviceException.isRetryable()); - assertEquals(IDEMPOTENT, serviceException.isIdempotent()); - assertNull(serviceException.getCause()); - - serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); - assertEquals(CODE, serviceException.getCode()); - assertEquals(MESSAGE, serviceException.getMessage()); - assertEquals(REASON, serviceException.getReason()); - assertFalse(serviceException.isRetryable()); - assertEquals(IDEMPOTENT, serviceException.isIdempotent()); assertNull(serviceException.getCause()); Exception cause = new RuntimeException(); - serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, cause); + serviceException = + new BaseServiceException(ExceptionData.from(CODE, MESSAGE, REASON, NOT_RETRYABLE, cause)); assertEquals(CODE, serviceException.getCode()); assertEquals(MESSAGE, serviceException.getMessage()); assertEquals(REASON, serviceException.getReason()); assertFalse(serviceException.isRetryable()); - assertEquals(IDEMPOTENT, serviceException.isIdempotent()); assertEquals(cause, serviceException.getCause()); - serviceException = new BaseServiceException(CODE, MESSAGE, REASON, false, cause); + serviceException = + new BaseServiceException( + ExceptionData.newBuilder() + .setMessage(MESSAGE).setCause(cause).setCode(CODE) + .setReason(REASON).setRetryable(RETRYABLE).setDebugInfo(DEBUG_INFO) + .setLocation(LOCATION) + .build()); assertEquals(CODE, serviceException.getCode()); assertEquals(MESSAGE, serviceException.getMessage()); assertEquals(REASON, serviceException.getReason()); - assertFalse(serviceException.isRetryable()); - assertFalse(serviceException.isIdempotent()); - assertEquals(cause, serviceException.getCause()); - - IOException exception = new SocketTimeoutException(); - serviceException = new BaseServiceException(exception, true); - assertTrue(serviceException.isRetryable()); - assertTrue(serviceException.isIdempotent()); - assertNull(serviceException.getMessage()); - assertEquals(exception, serviceException.getCause()); - - exception = new SocketException(); - serviceException = new BaseServiceException(exception, true); assertTrue(serviceException.isRetryable()); - assertTrue(serviceException.isIdempotent()); - assertNull(serviceException.getMessage()); - assertEquals(exception, serviceException.getCause()); - - exception = new IOException("insufficient data written"); - serviceException = new BaseServiceException(exception, true); - assertTrue(serviceException.isRetryable()); - assertTrue(serviceException.isIdempotent()); - assertEquals("insufficient data written", serviceException.getMessage()); - assertEquals(exception, serviceException.getCause()); - - GoogleJsonError error = new GoogleJsonError(); - error.setCode(CODE); - error.setMessage(MESSAGE); - serviceException = new BaseServiceException(error, true); - assertEquals(CODE, serviceException.getCode()); - assertEquals(MESSAGE, serviceException.getMessage()); - assertFalse(serviceException.isRetryable()); - assertTrue(serviceException.isIdempotent()); + assertEquals(cause, serviceException.getCause()); + assertEquals(DEBUG_INFO, serviceException.getDebugInfo()); + assertEquals(LOCATION, serviceException.getLocation()); serviceException = new CustomServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); assertEquals(CODE, serviceException.getCode()); assertEquals(MESSAGE, serviceException.getMessage()); assertEquals(REASON, serviceException.getReason()); - assertEquals(RETRYABLE, serviceException.isRetryable()); - assertEquals(IDEMPOTENT, serviceException.isIdempotent()); + assertTrue(serviceException.isRetryable()); serviceException = new CustomServiceException(CODE_NO_REASON, MESSAGE, null, IDEMPOTENT); assertEquals(CODE_NO_REASON, serviceException.getCode()); assertEquals(MESSAGE, serviceException.getMessage()); assertNull(serviceException.getReason()); - assertEquals(RETRYABLE, serviceException.isRetryable()); - assertEquals(IDEMPOTENT, serviceException.isIdempotent()); + assertTrue(serviceException.isRetryable()); serviceException = new CustomServiceException(UNKNOWN_CODE, MESSAGE, REASON, IDEMPOTENT); assertEquals(UNKNOWN_CODE, serviceException.getCode()); assertEquals(MESSAGE, serviceException.getMessage()); assertEquals(REASON, serviceException.getReason()); - assertEquals(RETRYABLE, serviceException.isRetryable()); - assertEquals(IDEMPOTENT, serviceException.isIdempotent()); + assertTrue(serviceException.isRetryable()); } @Test public void testTranslateAndThrow() throws Exception { - BaseServiceException cause = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT); + BaseServiceException cause = + new BaseServiceException(ExceptionData.from(CODE, MESSAGE, REASON, NOT_RETRYABLE)); RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2); @@ -163,7 +128,6 @@ public void testTranslateAndThrow() throws Exception { assertEquals(CODE, ex.getCode()); assertEquals(MESSAGE, ex.getMessage()); assertFalse(ex.isRetryable()); - assertEquals(IDEMPOTENT, ex.isIdempotent()); } finally { verify(exceptionMock); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java b/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java index 8fb26bc8ce..3ce49a8e6f 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.google.cloud.BaseServiceException.ExceptionData; import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; @@ -64,7 +65,8 @@ public void testError() { } catch (NullPointerException exc) { // expected } - BaseServiceException ex = new BaseServiceException(0, "message", "reason", false); + BaseServiceException ex = + new BaseServiceException(ExceptionData.from(0, "message", "reason", false)); result.error(ex); try { result.get(); @@ -76,7 +78,8 @@ public void testError() { @Test public void testNotifyError() { - final BaseServiceException ex = new BaseServiceException(0, "message", "reason", false); + final BaseServiceException ex = + new BaseServiceException(ExceptionData.from(0, "message", "reason", false)); assertFalse(result.completed()); BatchResult.Callback callback = EasyMock.createStrictMock(BatchResult.Callback.class); diff --git a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java index a5ffadf4d6..2193981ae8 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java @@ -18,7 +18,7 @@ import static org.junit.Assert.assertEquals; -import com.google.api.gax.core.Page; +import com.google.api.gax.paging.Page; import com.google.common.collect.ImmutableList; import org.junit.Test; diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 11bdae8b28..11f2dc1eeb 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -16,7 +16,8 @@ package com.google.cloud; -import com.google.api.gax.core.RetrySettings; +import com.google.api.gax.retrying.RetrySettings; +import com.google.cloud.BaseServiceException.ExceptionData; import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor; import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor.ValueType; import com.google.common.collect.ImmutableList; @@ -28,7 +29,7 @@ public class SerializationTest extends BaseSerializationTest { private static final BaseServiceException BASE_SERVICE_EXCEPTION = - new BaseServiceException(42, "message", "reason", true); + new BaseServiceException(ExceptionData.from(42, "message", "reason", false)); private static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.getDefaultInstance(); private static final Identity IDENTITY = Identity.allAuthenticatedUsers(); private static final PageImpl PAGE = diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index e7f3a45158..7abfc8a49b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -186,7 +186,7 @@ public TestServiceRpcFactory getDefaultRpcFactory() { @Override public TransportOptions getDefaultTransportOptions() { - return HttpTransportOptions.newBuilder().build(); + return new TransportOptions() {}; } } From 90109ad609f546745a144ef6bb3db2abe8bf0e04 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 21 Apr 2017 18:50:54 -0700 Subject: [PATCH 353/663] Bumping to 1.0.0-rc2, 0.15.0-beta, 0.15.0-alpha for release (#1971) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index af23786393..32f5f490d8 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.0-rc2-SNAPSHOT + 1.0.0-rc2 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.14.1-alpha-SNAPSHOT + 0.15.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index a23ea864ef..15eb78b1f7 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.0-rc2-SNAPSHOT + 1.0.0-rc2 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.14.1-alpha-SNAPSHOT + 0.15.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 18676c4ef8..2538c4a09e 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.0.0-rc1 + 1.0.0-rc2 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.0.0-rc1' +compile 'com.google.cloud:google-cloud-core:1.0.0-rc2' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.0-rc1" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.0-rc2" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c17f4b0ff1..b51e889f5b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.0-rc2-SNAPSHOT + 1.0.0-rc2 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.14.1-alpha-SNAPSHOT + 0.15.0-alpha google-cloud-core From cf0efa972947361cfa8d28ceff9871bc7950ff32 Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 24 Apr 2017 09:08:02 -0700 Subject: [PATCH 354/663] fix credentials NPE bug (#1961) * fix credentials NPE bug #1565 * use object reference equality for Singleton object * implement equals() method for NoCredentials class --- .../src/main/java/com/google/cloud/NoCredentials.java | 9 ++++++++- .../src/main/java/com/google/cloud/ServiceOptions.java | 4 ---- .../test/java/com/google/cloud/ServiceOptionsTest.java | 4 ++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java b/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java index 3f5cfbdbfc..3172609e25 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java +++ b/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java @@ -17,7 +17,6 @@ package com.google.cloud; import com.google.auth.oauth2.OAuth2Credentials; - import java.io.ObjectStreamException; /** @@ -38,4 +37,12 @@ private Object readResolve() throws ObjectStreamException { public static NoCredentials getInstance() { return INSTANCE; } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof NoCredentials)) { + return false; + } + return this == obj; + } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 0e20848962..01c23cd09c 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -19,7 +19,6 @@ import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import static java.nio.charset.StandardCharsets.UTF_8; import com.google.api.core.ApiClock; import com.google.api.core.CurrentMillisClock; @@ -38,12 +37,9 @@ import java.io.FileReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.Serializable; import java.lang.reflect.Method; -import java.net.HttpURLConnection; -import java.net.URL; import java.nio.charset.Charset; import java.util.Locale; import java.util.Objects; diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 7abfc8a49b..3238a30c8c 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -16,6 +16,7 @@ package com.google.cloud; +import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertSame; @@ -231,6 +232,9 @@ public void testBuilder() { @Test public void testBuilderNoCredentials() { assertEquals(NoCredentials.getInstance(), OPTIONS_NO_CREDENTIALS.getCredentials()); + assertTrue(NoCredentials.getInstance().equals(OPTIONS_NO_CREDENTIALS.getCredentials())); + assertFalse(NoCredentials.getInstance().equals(OPTIONS.getCredentials())); + assertFalse(NoCredentials.getInstance().equals(null)); assertSame(TEST_CLOCK, OPTIONS_NO_CREDENTIALS.getClock()); assertEquals("host", OPTIONS_NO_CREDENTIALS.getHost()); assertEquals("project-id", OPTIONS_NO_CREDENTIALS.getProjectId()); From 0cba10d0aa45f4e3455e452610d756c2dbc39980 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 24 Apr 2017 09:34:57 -0700 Subject: [PATCH 355/663] Bumping to 1.0.0-rc3-SNAPSHOT, 0.15.1-beta-SNAPSHOT, 0.15.1-alpha-SNAPSHOT (#1977) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 32f5f490d8..83b207cdab 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.0-rc2 + 1.0.0-rc3-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.15.0-alpha + 0.15.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 15eb78b1f7..d6d6efcf1a 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.0-rc2 + 1.0.0-rc3-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.15.0-alpha + 0.15.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b51e889f5b..f8122a3cd3 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.0-rc2 + 1.0.0-rc3-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.15.0-alpha + 0.15.1-alpha-SNAPSHOT google-cloud-core From b71262adf90a2a73ae87bf49d38e9fcb4c4ad6bf Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 24 Apr 2017 15:49:12 -0700 Subject: [PATCH 356/663] Reducing visibility of some things, adding @InternalApi (#1979) --- .../google/cloud/grpc/BaseGrpcServiceException.java | 7 +++++-- .../google/cloud/http/BaseHttpServiceException.java | 13 +++++++++---- .../com/google/cloud/http/HttpTransportOptions.java | 3 ++- google-cloud-core/pom.xml | 1 - .../src/main/java/com/google/cloud/BaseService.java | 2 ++ .../java/com/google/cloud/BaseServiceException.java | 3 ++- .../java/com/google/cloud/BaseWriteChannel.java | 4 ++++ .../src/main/java/com/google/cloud/BatchResult.java | 5 +++++ .../src/main/java/com/google/cloud/ByteArray.java | 11 +---------- .../src/main/java/com/google/cloud/Date.java | 2 +- .../java/com/google/cloud/ExceptionHandler.java | 4 +++- .../src/main/java/com/google/cloud/Policy.java | 7 +++++++ .../src/main/java/com/google/cloud/RetryHelper.java | 2 ++ .../main/java/com/google/cloud/ServiceOptions.java | 3 +++ .../main/java/com/google/cloud/StringEnumValue.java | 2 +- .../google/cloud/testing/BaseEmulatorHelper.java | 1 + 16 files changed, 48 insertions(+), 22 deletions(-) diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java index fcefe6a8e9..77473e2089 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java @@ -17,6 +17,7 @@ package com.google.cloud.grpc; import com.google.api.client.http.HttpResponseException; +import com.google.api.core.InternalApi; import com.google.api.gax.grpc.ApiException; import com.google.cloud.BaseServiceException; import com.google.common.base.MoreObjects; @@ -30,12 +31,14 @@ public class BaseGrpcServiceException extends BaseServiceException { private static final long serialVersionUID = -2685197215731335549L; - public BaseGrpcServiceException(String message, Throwable cause, int code, boolean retryable) { + @InternalApi("This class should only be extended within google-cloud-java") + protected BaseGrpcServiceException(String message, Throwable cause, int code, boolean retryable) { super(ExceptionData.newBuilder().setMessage(message).setCause(cause).setCode(code) .setRetryable(retryable).build()); } - public BaseGrpcServiceException(IOException exception, boolean idempotent) { + @InternalApi("This class should only be extended within google-cloud-java") + protected BaseGrpcServiceException(IOException exception, boolean idempotent) { super(makeExceptionData(exception, idempotent)); } diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java index b1ffa29838..ca979c6a7e 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java @@ -19,6 +19,7 @@ import com.google.api.client.googleapis.json.GoogleJsonError; import com.google.api.client.googleapis.json.GoogleJsonResponseException; import com.google.api.client.http.HttpResponseException; +import com.google.api.core.InternalApi; import com.google.cloud.BaseServiceException; import com.google.common.base.MoreObjects; import java.io.IOException; @@ -32,7 +33,8 @@ public class BaseHttpServiceException extends BaseServiceException { private static final long serialVersionUID = -5793034110344127954L; public static final int UNKNOWN_CODE = 0; - public BaseHttpServiceException(IOException exception, boolean idempotent, + @InternalApi("This class should only be extended within google-cloud-java") + protected BaseHttpServiceException(IOException exception, boolean idempotent, Set retryableErrors) { super(makeExceptionData(exception, idempotent, retryableErrors)); } @@ -80,7 +82,8 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id .build(); } - public BaseHttpServiceException(GoogleJsonError googleJsonError, boolean idempotent, + @InternalApi("This class should only be extended within google-cloud-java") + protected BaseHttpServiceException(GoogleJsonError googleJsonError, boolean idempotent, Set retryableErrors) { super(makeExceptionData(googleJsonError, idempotent, retryableErrors)); } @@ -108,12 +111,14 @@ private static ExceptionData makeExceptionData(GoogleJsonError googleJsonError, return exceptionData.build(); } - public BaseHttpServiceException(int code, String message, String reason, boolean idempotent, + @InternalApi("This class should only be extended within google-cloud-java") + protected BaseHttpServiceException(int code, String message, String reason, boolean idempotent, Set retryableErrors) { this(code, message, reason, idempotent, retryableErrors, null); } - public BaseHttpServiceException(int code, String message, String reason, boolean idempotent, + @InternalApi("This class should only be extended within google-cloud-java") + protected BaseHttpServiceException(int code, String message, String reason, boolean idempotent, Set retryableErrors, Throwable cause) { super(ExceptionData.newBuilder() .setMessage(message) diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java index 1a4f25158e..b45874e71b 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java @@ -24,6 +24,7 @@ import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.core.InternalApi; import com.google.auth.Credentials; import com.google.auth.http.HttpCredentialsAdapter; import com.google.auth.http.HttpTransportFactory; @@ -122,7 +123,7 @@ public Builder setReadTimeout(int readTimeout) { } } - protected HttpTransportOptions(Builder builder) { + private HttpTransportOptions(Builder builder) { httpTransportFactory = firstNonNull(builder.httpTransportFactory, ServiceOptions.getFromServiceLoader(HttpTransportFactory.class, DefaultHttpTransportFactory.INSTANCE)); diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f8122a3cd3..5728cfded7 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -48,7 +48,6 @@ com.google.api api-common - ${api-common.version} com.google.api diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java index a907bed132..de05bfb22b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java @@ -16,6 +16,7 @@ package com.google.cloud; +import com.google.api.core.InternalApi; import com.google.cloud.ExceptionHandler.Interceptor; /** @@ -51,6 +52,7 @@ public RetryResult beforeEval(Exception exception) { private final OptionsT options; + @InternalApi("This class should only be extended within google-cloud-java") protected BaseService(OptionsT options) { this.options = options; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index f7ded9900b..d9608991d0 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -253,7 +253,8 @@ public static void translate(RetryHelper.RetryHelperException ex) { } } - public BaseServiceException(ExceptionData exceptionData) { + @InternalApi("This class should only be extended within google-cloud-java") + protected BaseServiceException(ExceptionData exceptionData) { super(exceptionData.getMessage(), exceptionData.getCause()); this.code = exceptionData.getCode(); this.reason = exceptionData.getReason(); diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index fd8f02d195..b5f6394a2f 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -16,6 +16,7 @@ package com.google.cloud; +import com.google.api.core.InternalApi; import java.io.IOException; import java.io.Serializable; import java.nio.ByteBuffer; @@ -107,6 +108,7 @@ public final void setChunkSize(int chunkSize) { this.chunkSize = Math.max(getMinChunkSize(), chunkSize); } + @InternalApi("This class should only be extended within google-cloud-java") protected BaseWriteChannel(ServiceOptionsT options, EntityT entity, String uploadId) { this.options = options; this.entity = entity; @@ -209,6 +211,7 @@ protected abstract static class BaseState< protected final boolean isOpen; protected final int chunkSize; + @InternalApi("This class should only be extended within google-cloud-java") protected BaseState(Builder builder) { this.serviceOptions = builder.serviceOptions; this.entity = builder.entity; @@ -238,6 +241,7 @@ public abstract static class Builder< private boolean isOpen; private int chunkSize; + @InternalApi("This class should only be extended within google-cloud-java") protected Builder(ServiceOptionsT options, EntityT entity, String uploadId) { this.serviceOptions = options; this.entity = entity; diff --git a/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java b/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java index fb78409ea3..93f745efc8 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import com.google.api.core.InternalApi; import java.util.LinkedList; import java.util.List; @@ -36,6 +37,10 @@ public abstract class BatchResult { private E error; private final List> toBeNotified = new LinkedList<>(); + @InternalApi("This class should only be extended within google-cloud-java") + protected BatchResult() { + } + /** * Returns {@code true} if the batch has been completed and the result is available; {@code false} * otherwise. diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java index 449e827c41..37c2e79188 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -40,14 +40,10 @@ public class ByteArray implements Iterable, Serializable { private final ByteString byteString; - protected ByteArray(ByteString byteString) { + ByteArray(ByteString byteString) { this.byteString = byteString; } - protected ByteArray(ByteArray byteArray) { - this.byteString = byteArray.getByteString(); - } - @Override public final Iterator iterator() { return byteString.iterator(); @@ -117,11 +113,6 @@ public final InputStream asInputStream() { return byteString.newInput(); } - - protected ByteString getByteString() { - return byteString; - } - /** * Copies the content of this {@code ByteArray} into an existing {@code ByteBuffer}. * diff --git a/google-cloud-core/src/main/java/com/google/cloud/Date.java b/google-cloud-core/src/main/java/com/google/cloud/Date.java index d99c6171b1..8f43be831e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Date.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Date.java @@ -27,7 +27,7 @@ /** * Represents a Date without time, such as 2017-03-17. Date is timezone independent. */ -@BetaApi +@BetaApi("This is going to be replaced with LocalDate from threetenbp") public final class Date implements Comparable, Serializable { // Date format "yyyy-mm-dd" diff --git a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java index 81703b5612..e412ddfdd0 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.api.core.BetaApi; import com.google.api.gax.retrying.ExceptionRetryAlgorithm; import com.google.api.gax.retrying.TimedAttemptSettings; import com.google.common.annotations.VisibleForTesting; @@ -35,6 +36,7 @@ /** * Exception retry algorithm implementation used by {@link RetryHelper}. */ +@BetaApi public final class ExceptionHandler implements ExceptionRetryAlgorithm, Serializable { private static final long serialVersionUID = -2460707015779532919L; @@ -263,7 +265,7 @@ public boolean accept(Throwable prevThrowable) { @Override public TimedAttemptSettings createNextAttempt(Throwable prevThrowable, TimedAttemptSettings prevSettings) { - // Return null to indicate that this implementaiton does not provide any specific attempt + // Return null to indicate that this implementation does not provide any specific attempt // settings, so by default the TimedRetryAlgorithm options can be used instead. return null; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/Policy.java b/google-cloud-core/src/main/java/com/google/cloud/Policy.java index ca79936684..9c4282d14a 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Policy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Policy.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.core.ApiFunction; +import com.google.api.core.InternalApi; import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; @@ -58,6 +59,10 @@ public final class Policy implements Serializable { public abstract static class Marshaller { + @InternalApi("This class should only be extended within google-cloud-java") + protected Marshaller() { + } + protected static final ApiFunction IDENTITY_VALUE_OF_FUNCTION = new ApiFunction() { @Override @@ -135,9 +140,11 @@ public static class Builder { private String etag; private int version; + @InternalApi("This class should only be extended within google-cloud-java") protected Builder() { } + @InternalApi("This class should only be extended within google-cloud-java") protected Builder(Policy policy) { setBindings(policy.bindings); setEtag(policy.etag); diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index 2e9434a0d2..702356d405 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -17,6 +17,7 @@ package com.google.cloud; import com.google.api.core.ApiClock; +import com.google.api.core.BetaApi; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.retrying.DirectRetryingExecutor; @@ -31,6 +32,7 @@ * RetrySettings}. In case if retrying is unsuccessful, {@link RetryHelperException} will be * thrown. */ +@BetaApi public class RetryHelper { public static V runWithRetries( Callable callable, diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 01c23cd09c..0a17beb651 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -112,8 +112,10 @@ public abstract static class Builder, private ApiClock clock; private TransportOptions transportOptions; + @InternalApi("This class should only be extended within google-cloud-java") protected Builder() {} + @InternalApi("This class should only be extended within google-cloud-java") protected Builder(ServiceOptions options) { projectId = options.projectId; host = options.host; @@ -226,6 +228,7 @@ public B setTransportOptions(TransportOptions transportOptions) { } } + @InternalApi("This class should only be extended within google-cloud-java") protected ServiceOptions(Class> serviceFactoryClass, Class> rpcFactoryClass, Builder builder, diff --git a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java index 54c72bd8fd..f027fda5b3 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java +++ b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java @@ -31,7 +31,7 @@ public abstract class StringEnumValue implements Serializable { /** * Don't create subclasses outside of google-cloud-java. */ - @InternalApi + @InternalApi("This class should only be extended within google-cloud-java") protected StringEnumValue(String constant) { this.constant = Preconditions.checkNotNull(constant); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index 0de8675a40..2bd84a4dc6 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -71,6 +71,7 @@ public abstract class BaseEmulatorHelper { protected static final String DEFAULT_HOST = "localhost"; protected static final int DEFAULT_PORT = 8080; + @InternalApi("This class should only be extended within google-cloud-java") protected BaseEmulatorHelper(String emulator, int port, String projectId) { this.emulator = emulator; this.port = port > 0 ? port : DEFAULT_PORT; From cdd72806a8d5f7c70f6b1c3341e10c7895d17832 Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Mon, 24 Apr 2017 17:07:17 -0700 Subject: [PATCH 357/663] Update proto packages (#1984) --- google-cloud-core/pom.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 5728cfded7..b4cba17681 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -54,13 +54,17 @@ gax ${gax.version} + + com.google.protobuf + protobuf-java-util + com.google.api.grpc - grpc-google-common-protos + proto-google-common-protos com.google.api.grpc - grpc-google-iam-v1 + proto-google-iam-v1 com.google.truth From a6d4cf53b6e8b1ee0cf3efc7e39009a5f1c7ef22 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 25 Apr 2017 02:38:49 -0700 Subject: [PATCH 358/663] Migrating from Joda Duration/Instant to ThreeTenBP (#1985) --- .../java/com/google/cloud/ServiceOptions.java | 12 ++++++------ .../google/cloud/testing/BaseEmulatorHelper.java | 4 ++-- .../cloud/testing/BaseEmulatorHelperTest.java | 16 +++++++--------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 0a17beb651..061e2e8699 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -47,10 +47,10 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.joda.time.Duration; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; +import org.threeten.bp.Duration; /** * Abstract class representing service options. @@ -578,13 +578,13 @@ public static RetrySettings getNoRetrySettings() { private static RetrySettings.Builder getDefaultRetrySettingsBuilder() { return RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(Duration.millis(1000L)) - .setMaxRetryDelay(Duration.millis(32_000L)) + .setInitialRetryDelay(Duration.ofMillis(1000L)) + .setMaxRetryDelay(Duration.ofMillis(32_000L)) .setRetryDelayMultiplier(2.0) - .setTotalTimeout(Duration.millis(50_000L)) - .setInitialRpcTimeout(Duration.millis(50_000L)) + .setTotalTimeout(Duration.ofMillis(50_000L)) + .setInitialRpcTimeout(Duration.ofMillis(50_000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.millis(50_000L)); + .setMaxRpcTimeout(Duration.ofMillis(50_000L)); } protected abstract Set getScopes(); diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index 2bd84a4dc6..c84980700d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -53,7 +53,7 @@ import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import org.joda.time.Duration; +import org.threeten.bp.Duration; /** * Utility class to start and stop a local service which is used by unit testing. @@ -149,7 +149,7 @@ public void run() { waiter.start(); try { - return exitValue.get(timeout.getMillis(), TimeUnit.MILLISECONDS); + return exitValue.get(timeout.toMillis(), TimeUnit.MILLISECONDS); } catch (ExecutionException e) { if (e.getCause() instanceof InterruptedException) { throw (InterruptedException) e.getCause(); diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java index b4b2579f73..b4c334762b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java @@ -20,17 +20,15 @@ import com.google.cloud.ServiceOptions; import com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner; import com.google.common.collect.ImmutableList; - -import org.easymock.EasyMock; -import org.joda.time.Duration; -import org.junit.Test; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.concurrent.TimeoutException; import java.util.logging.Logger; +import org.easymock.EasyMock; +import org.junit.Test; +import org.threeten.bp.Duration; public class BaseEmulatorHelperTest { @@ -88,13 +86,13 @@ public void testEmulatorHelper() throws IOException, InterruptedException, Timeo emulatorRunner.start(); EasyMock.expectLastCall(); EasyMock.expect(emulatorRunner.getProcess()).andReturn(process); - emulatorRunner.waitFor(Duration.standardMinutes(1)); + emulatorRunner.waitFor(Duration.ofMinutes(1)); EasyMock.expectLastCall().andReturn(0); EasyMock.replay(process, emulatorRunner); TestEmulatorHelper helper = new TestEmulatorHelper(ImmutableList.of(emulatorRunner), BLOCK_UNTIL); helper.start(); - helper.stop(Duration.standardMinutes(1)); + helper.stop(Duration.ofMinutes(1)); EasyMock.verify(); } @@ -110,13 +108,13 @@ public void testEmulatorHelperMultipleRunners() throws IOException, InterruptedE secondRunner.start(); EasyMock.expectLastCall(); EasyMock.expect(secondRunner.getProcess()).andReturn(process); - secondRunner.waitFor(Duration.standardMinutes(1)); + secondRunner.waitFor(Duration.ofMinutes(1)); EasyMock.expectLastCall().andReturn(0); EasyMock.replay(process, secondRunner); TestEmulatorHelper helper = new TestEmulatorHelper(ImmutableList.of(firstRunner, secondRunner), BLOCK_UNTIL); helper.start(); - helper.stop(Duration.standardMinutes(1)); + helper.stop(Duration.ofMinutes(1)); EasyMock.verify(); } } From 45705f921b8a6715df91058e596ccfb6709c2302 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 25 Apr 2017 07:09:49 -0700 Subject: [PATCH 359/663] Bumping versions to 1.0.0-rc3, 0.16.0-beta, 0.16.0-alpha for release (#1987) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 83b207cdab..9deb74a160 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.0-rc3-SNAPSHOT + 1.0.0-rc3 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.15.1-alpha-SNAPSHOT + 0.16.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index d6d6efcf1a..e3909e61e7 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.0-rc3-SNAPSHOT + 1.0.0-rc3 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.15.1-alpha-SNAPSHOT + 0.16.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 2538c4a09e..f08c115afc 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.0.0-rc2 + 1.0.0-rc3 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.0.0-rc2' +compile 'com.google.cloud:google-cloud-core:1.0.0-rc3' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.0-rc2" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.0-rc3" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b4cba17681..2f74426821 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.0-rc3-SNAPSHOT + 1.0.0-rc3 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.15.1-alpha-SNAPSHOT + 0.16.0-alpha google-cloud-core From 41b7a2553ae4a05a5463989c6d93a5f416348e49 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 25 Apr 2017 07:58:45 -0700 Subject: [PATCH 360/663] Bumping to next SNAPSHOT versions (#1989) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 9deb74a160..cae5ebfe98 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.0-rc3 + 1.0.0-rc4-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.16.0-alpha + 0.16.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index e3909e61e7..3d88b96fe0 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.0-rc3 + 1.0.0-rc4-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.16.0-alpha + 0.16.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2f74426821..40935cb322 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.0-rc3 + 1.0.0-rc4-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.16.0-alpha + 0.16.1-alpha-SNAPSHOT google-cloud-core From d9e9adc13ba62e8ff7bdb4c96bc3e69e353e2d6b Mon Sep 17 00:00:00 2001 From: neozwu Date: Tue, 25 Apr 2017 13:52:22 -0700 Subject: [PATCH 361/663] make one Tuple class aross all the projects (#1992) --- .../src/main/java/com/google/cloud/Tuple.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/Tuple.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/Tuple.java b/google-cloud-core/src/main/java/com/google/cloud/Tuple.java new file mode 100644 index 0000000000..1536a5d271 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/Tuple.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +public class Tuple { + + private final X x; + private final Y y; + + private Tuple(X x, Y y) { + this.x = x; + this.y = y; + } + + public static Tuple of(X x, Y y) { + return new Tuple<>(x, y); + } + + public X x() { + return x; + } + + public Y y() { + return y; + } +} From 2224c1577658efce79ca37a126dc7e173c16c28d Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 25 Apr 2017 14:10:30 -0700 Subject: [PATCH 362/663] Bumping versions to 1.0.0-rc4, 0.17.0-beta, 0.17.0-alpha for release (#1996) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index cae5ebfe98..4fd4f09393 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.0-rc4-SNAPSHOT + 1.0.0-rc4 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.16.1-alpha-SNAPSHOT + 0.17.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 3d88b96fe0..72c0206318 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.0-rc4-SNAPSHOT + 1.0.0-rc4 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.16.1-alpha-SNAPSHOT + 0.17.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f08c115afc..6236c093b6 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.0.0-rc3 + 1.0.0-rc4 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.0.0-rc3' +compile 'com.google.cloud:google-cloud-core:1.0.0-rc4' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.0-rc3" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.0-rc4" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 40935cb322..9b1aa50b61 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.0-rc4-SNAPSHOT + 1.0.0-rc4 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.16.1-alpha-SNAPSHOT + 0.17.0-alpha google-cloud-core From c0c43f6050cb75d96ee150f8f4d27246bcc78f6f Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 25 Apr 2017 14:42:52 -0700 Subject: [PATCH 363/663] Bumping versions to next snapshot versions (#1997) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4fd4f09393..bc607eb6d6 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.0-rc4 + 1.0.0-rc5-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.0-alpha + 0.17.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 72c0206318..3aff85b297 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.0-rc4 + 1.0.0-rc5-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.0-alpha + 0.17.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9b1aa50b61..838f70b2a6 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.0-rc4 + 1.0.0-rc5-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.0-alpha + 0.17.1-alpha-SNAPSHOT google-cloud-core From d4df62154f8459ef58859368d51e84a688e1a1c0 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Tue, 25 Apr 2017 21:32:33 -0700 Subject: [PATCH 364/663] Fix build setup of project.properties (#2003) - Add project.properties as a resource file - Process the resource file and inject the version information in the building stage In this way only the properties listed in the project.properties will be injected. --- google-cloud-core-grpc/pom.xml | 20 -------------------- google-cloud-core-http/pom.xml | 20 -------------------- google-cloud-core/pom.xml | 34 +++++++++++++++++++++++----------- 3 files changed, 23 insertions(+), 51 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index bc607eb6d6..ae292fbf42 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -69,24 +69,4 @@ test - - - - org.codehaus.mojo - properties-maven-plugin - 1.0-alpha-2 - - - generate-resources - - write-project-properties - - - ${project.build.outputDirectory}/com/google/cloud/project.properties - - - - - - diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 3aff85b297..5273ab3c17 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -109,24 +109,4 @@ test - - - - org.codehaus.mojo - properties-maven-plugin - 1.0-alpha-2 - - - generate-resources - - write-project-properties - - - ${project.build.outputDirectory}/com/google/cloud/project.properties - - - - - - diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 838f70b2a6..878d4ba500 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -80,22 +80,34 @@ + + + ./.. + true + + project.properties + + + - - org.codehaus.mojo - properties-maven-plugin - 1.0-alpha-2 - + + maven-antrun-plugin + 1.4 + - generate-resources - - write-project-properties - + process-resources - ${project.build.outputDirectory}/com/google/cloud/project.properties + + + + + run + - + From 9ab19efae849e4adbbeab4c2dc9fdca8a0772029 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Tue, 25 Apr 2017 22:11:53 -0700 Subject: [PATCH 365/663] Versioning cleanup: (#2002) * Versioning cleanup: - fix versioning script (grpc.version issue) - better version resolution (via dependencyManagement instead of usage of properties defined in parent pom as dependencies version) - should also fix LICENSE resolution by versioneye.com and dependency ci (google-cloud-* moudles should now display correct licenses instead of UKNOWN) - fix link in readmes to versioneye.com (old link points to 0.7.1 which is not getting updated - fix security issue dependency in google-cloud-dns - removed "test" scope in dependencyManagement for various libs (considered bad practice, plus potentially causes an issue with datastore lib) --- google-cloud-core-grpc/pom.xml | 2 -- google-cloud-core-http/pom.xml | 1 - google-cloud-core/README.md | 2 +- google-cloud-core/pom.xml | 1 - 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ae292fbf42..0bdd8c4757 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -22,7 +22,6 @@ com.google.cloud google-cloud-core - ${core.version} com.google.guava @@ -50,7 +49,6 @@ io.grpc grpc-protobuf - ${grpc.version} com.google.api diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5273ab3c17..2d253bf72e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -22,7 +22,6 @@ com.google.cloud google-cloud-core - ${core.version} com.google.auth diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 6236c093b6..35e92de493 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -7,7 +7,7 @@ This module provides common functionality required by service-specific modules o [![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/google-cloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/google-cloud-java?branch=master) [![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg) [![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) -[![Dependency Status](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969) +[![Dependency Status](https://www.versioneye.com/user/projects/58fe4c8d6ac171426c414772/badge.svg?style=flat)](https://www.versioneye.com/user/projects/58fe4c8d6ac171426c414772) - [Homepage](https://googlecloudplatform.github.io/google-cloud-java/) - [API Documentation](https://googlecloudplatform.github.io/google-cloud-java/apidocs/index.html?com/google/cloud/package-summary.html) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 878d4ba500..d76229427d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -52,7 +52,6 @@ com.google.api gax - ${gax.version} com.google.protobuf From 2a86bfe5fd59c476748bd9d32eb9a378fd9b5fbc Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 25 Apr 2017 22:57:57 -0700 Subject: [PATCH 366/663] Bumping versions to 1.0.0, 0.17.1-beta, 0.17.1-alpha for release (#2004) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0bdd8c4757..dde5cf3286 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.0-rc5-SNAPSHOT + 1.0.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.1-alpha-SNAPSHOT + 0.17.1-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 2d253bf72e..ef59e12c22 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.0-rc5-SNAPSHOT + 1.0.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.1-alpha-SNAPSHOT + 0.17.1-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 35e92de493..b2d67f8c88 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.0.0-rc4 + 1.0.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.0.0-rc4' +compile 'com.google.cloud:google-cloud-core:1.0.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.0-rc4" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d76229427d..38fcb5bd44 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.0-rc5-SNAPSHOT + 1.0.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.1-alpha-SNAPSHOT + 0.17.1-alpha google-cloud-core From cc440792942b21686b376486ab234b79d32d4fa2 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 26 Apr 2017 09:01:51 -0700 Subject: [PATCH 367/663] Bumping to next snapshot versions (#2006) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index dde5cf3286..f47005357c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.0 + 1.0.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.1-alpha + 0.17.2-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index ef59e12c22..396545c51d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.0 + 1.0.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.1-alpha + 0.17.2-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 38fcb5bd44..bc03705bda 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.0 + 1.0.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.1-alpha + 0.17.2-alpha-SNAPSHOT google-cloud-core From 1c5dee974c18db44209e67e436438a94097ef7d6 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 4 May 2017 15:59:16 -0700 Subject: [PATCH 368/663] Bumping versions to 1.0.1, 0.17.2-beta, 0.17.2-alpha for release (#2035) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index f47005357c..839fe60e2a 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.1-SNAPSHOT + 1.0.1 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.2-alpha-SNAPSHOT + 0.17.2-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 396545c51d..3af9d7f455 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.1-SNAPSHOT + 1.0.1 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.2-alpha-SNAPSHOT + 0.17.2-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index b2d67f8c88..d9325b73f8 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.0.0 + 1.0.1 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.0.0' +compile 'com.google.cloud:google-cloud-core:1.0.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.1" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index bc03705bda..a7acc35106 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.1-SNAPSHOT + 1.0.1 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.2-alpha-SNAPSHOT + 0.17.2-alpha google-cloud-core From 8d13d264990fc195b77277fafec3ae955cbfa160 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 4 May 2017 16:18:36 -0700 Subject: [PATCH 369/663] Bumping to next snapshot versions (#2036) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 839fe60e2a..130b30a355 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.1 + 1.0.2-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.2-alpha + 0.17.3-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 3af9d7f455..1ca528d2e4 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.1 + 1.0.2-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.2-alpha + 0.17.3-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a7acc35106..841262f280 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.1 + 1.0.2-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.2-alpha + 0.17.3-alpha-SNAPSHOT google-cloud-core From 056824803815ab891889b3d57f488bcce137969c Mon Sep 17 00:00:00 2001 From: Vikas Kedia Date: Fri, 12 May 2017 14:02:50 -0700 Subject: [PATCH 370/663] Change Timestamp to not use jodatime classes for parsing/formatting (#2059) --- .../main/java/com/google/cloud/Timestamp.java | 59 +++++-------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java index e138343a58..bbad6abc64 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -18,21 +18,20 @@ import static com.google.common.base.Preconditions.checkArgument; -import com.google.common.base.Strings; import com.google.protobuf.util.Timestamps; import java.io.Serializable; import java.util.Date; import java.util.Objects; import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.joda.time.chrono.GregorianChronology; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; +import org.threeten.bp.Instant; +import org.threeten.bp.LocalDateTime; +import org.threeten.bp.ZoneOffset; +import org.threeten.bp.chrono.IsoChronology; +import org.threeten.bp.format.DateTimeFormatter; /** - * Represents a timestamp with nanosecond precision. Timestamps cover the range - * [0001-01-01, 9999-12-31]. + * Represents a timestamp with nanosecond precision. Timestamps cover the range [0001-01-01, + * 9999-12-31]. * *

    {@code Timestamp} instances are immutable. */ @@ -47,13 +46,8 @@ public final class Timestamp implements Comparable, Serializable { public static final Timestamp MAX_VALUE = new Timestamp(253402300799L, (int) TimeUnit.SECONDS.toNanos(1) - 1); - /** Regexp to split timestamps into date-hour-minute-second and fractional second components. */ - private static final Pattern FORMAT_REGEXP = Pattern.compile("([^\\.]*)(\\.\\d{0,9})?Z"); - - private static final long NANOS_PER_SECOND = TimeUnit.SECONDS.toNanos(1); - private static final DateTimeFormatter format = - ISODateTimeFormat.dateHourMinuteSecond().withChronology(GregorianChronology.getInstanceUTC()); + DateTimeFormatter.ISO_LOCAL_DATE_TIME.withChronology(IsoChronology.INSTANCE); private final long seconds; private final int nanos; @@ -85,8 +79,8 @@ public static Timestamp ofTimeSecondsAndNanos(long seconds, int nanos) { */ public static Timestamp ofTimeMicroseconds(long microseconds) { long seconds = TimeUnit.MICROSECONDS.toSeconds(microseconds); - int nanos = (int) TimeUnit.MICROSECONDS.toNanos( - microseconds - TimeUnit.SECONDS.toMicros(seconds)); + int nanos = + (int) TimeUnit.MICROSECONDS.toNanos(microseconds - TimeUnit.SECONDS.toMicros(seconds)); checkArgument( Timestamps.isValid(seconds, nanos), "timestamp out of range: %s, %s", seconds, nanos); return new Timestamp(seconds, nanos); @@ -101,10 +95,7 @@ public static Timestamp of(Date date) { return ofTimeMicroseconds(TimeUnit.MILLISECONDS.toMicros(date.getTime())); } - - /** - * Creates an instance with current time. - */ + /** Creates an instance with current time. */ public static Timestamp now() { java.sql.Timestamp date = new java.sql.Timestamp(System.currentTimeMillis()); return of(date); @@ -148,9 +139,7 @@ public int compareTo(Timestamp other) { return r; } - /** - * Creates an instance of Timestamp from {@code com.google.protobuf.Timestamp}. - */ + /** Creates an instance of Timestamp from {@code com.google.protobuf.Timestamp}. */ public static Timestamp fromProto(com.google.protobuf.Timestamp proto) { return new Timestamp(proto.getSeconds(), proto.getNanos()); } @@ -168,28 +157,12 @@ public com.google.protobuf.Timestamp toProto() { * the timezone offset (always ends in "Z"). */ public static Timestamp parseTimestamp(String timestamp) { - Matcher matcher = FORMAT_REGEXP.matcher(timestamp); - if (!matcher.matches()) { - throw new IllegalArgumentException("Cannot parse input: " + timestamp); - } - String secondsPart = matcher.group(1); - String nanosPart = matcher.group(2); - long seconds; - seconds = format.parseMillis(secondsPart) / 1000; - int nanos = 0; - if (nanosPart != null) { - String padded = Strings.padEnd(nanosPart.substring(1), 9, '0'); - nanos = Integer.parseInt(padded); - if (nanos >= TimeUnit.SECONDS.toNanos(1)) { - throw new IllegalArgumentException( - "Cannot parse input: " + timestamp + " (nanos out of range)"); - } - } - return ofTimeSecondsAndNanos(seconds, nanos); + Instant instant = Instant.parse(timestamp); + return ofTimeSecondsAndNanos(instant.getEpochSecond(), instant.getNano()); } - StringBuilder toString(StringBuilder b) { - format.printTo(b, seconds * 1000); + private StringBuilder toString(StringBuilder b) { + format.formatTo(LocalDateTime.ofEpochSecond(seconds, 0, ZoneOffset.UTC), b); if (nanos != 0) { b.append(String.format(".%09d", nanos)); } From f143216ff4b528fa0d8fc6521ee5695879346c71 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 18 May 2017 09:27:40 -0700 Subject: [PATCH 371/663] Bumping versions to 1.0.2, 0.18.0-beta, 0.18.0-alpha for release (#2069) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 130b30a355..3082339fa4 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.2-SNAPSHOT + 1.0.2 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.3-alpha-SNAPSHOT + 0.18.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 1ca528d2e4..92603bc868 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.2-SNAPSHOT + 1.0.2 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.3-alpha-SNAPSHOT + 0.18.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index d9325b73f8..5ee3b79131 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.0.1 + 1.0.2 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.0.1' +compile 'com.google.cloud:google-cloud-core:1.0.2' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.1" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.2" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 841262f280..320488a35b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.2-SNAPSHOT + 1.0.2 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.17.3-alpha-SNAPSHOT + 0.18.0-alpha google-cloud-core From 0f09cf2cfca08924242d7053f74d9247c5817ee5 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 18 May 2017 10:06:10 -0700 Subject: [PATCH 372/663] Bumping to next snapshot versions (#2070) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 3082339fa4..264299e777 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.2 + 1.0.3-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.18.0-alpha + 0.18.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 92603bc868..8075ec392e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.2 + 1.0.3-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.18.0-alpha + 0.18.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 320488a35b..2fac8096fb 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.2 + 1.0.3-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.18.0-alpha + 0.18.1-alpha-SNAPSHOT google-cloud-core From f5e3c4521bd5c4654f6ceb37f1d22bc543ddde57 Mon Sep 17 00:00:00 2001 From: Thomas Coffee Date: Tue, 6 Jun 2017 07:32:54 -0700 Subject: [PATCH 373/663] Release 0.19.0 (#2114) * Bump dependency versions for gax and auth * Release 0.19.0 --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 264299e777..ba54382abc 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.0.3-SNAPSHOT + 1.1.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.18.1-alpha-SNAPSHOT + 0.19.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 8075ec392e..14eca64da1 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.0.3-SNAPSHOT + 1.1.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.18.1-alpha-SNAPSHOT + 0.19.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 5ee3b79131..5e21e0e27a 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.0.2 + 1.1.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.0.2' +compile 'com.google.cloud:google-cloud-core:1.1.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.0.2" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.1.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2fac8096fb..f23925c629 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.0.3-SNAPSHOT + 1.1.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.18.1-alpha-SNAPSHOT + 0.19.0-alpha google-cloud-core From b19555d59da63e0e4e080436522f286d844599da Mon Sep 17 00:00:00 2001 From: Thomas Coffee Date: Tue, 6 Jun 2017 09:52:35 -0700 Subject: [PATCH 374/663] Bump to next snapshot versions (#2119) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ba54382abc..42db13c03c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.1.0 + 1.1.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.19.0-alpha + 0.19.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 14eca64da1..123a417248 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.1.0 + 1.1.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.19.0-alpha + 0.19.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f23925c629..aa181b0028 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.1.0 + 1.1.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.19.0-alpha + 0.19.1-alpha-SNAPSHOT google-cloud-core From 0479996ba52d38b7b5e3b5986538de1358a71bda Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Wed, 7 Jun 2017 05:34:20 +1000 Subject: [PATCH 375/663] regenerate from toolkit (#2116) --- .../com/google/cloud/grpc/GrpcTransportOptions.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java index 14df145317..43271ce5fc 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java @@ -20,6 +20,8 @@ import com.google.api.core.InternalApi; import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.grpc.ChannelProvider; import com.google.api.gax.grpc.InstantiatingChannelProvider; import com.google.api.gax.grpc.UnaryCallSettings; @@ -175,6 +177,14 @@ public static ChannelProvider setUpChannelProvider( return providerBuilder.build(); } + public static CredentialsProvider setUpCredentialsProvider(ServiceOptions serviceOptions) { + Credentials scopedCredentials = serviceOptions.getScopedCredentials(); + if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { + return FixedCredentialsProvider.create(scopedCredentials); + } + return new NoCredentialsProvider(); + } + public Builder toBuilder() { return new Builder(this); From 531640c98400d863f4d6e848c3ea0dad352e7446 Mon Sep 17 00:00:00 2001 From: Thomas Coffee Date: Fri, 9 Jun 2017 12:57:57 -0700 Subject: [PATCH 376/663] Add getter docs for service objects (#2129) Fixes #2115. --- .../src/main/java/com/google/cloud/ServiceOptions.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 061e2e8699..3bc0ff66da 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -420,6 +420,10 @@ protected static String getServiceAccountProjectId() { } + /** + * Returns a Service object for the current service. For instance, when using Google Cloud + * Storage, it returns a {@link com.google.cloud.storage.Storage} object. + */ @SuppressWarnings("unchecked") public ServiceT getService() { if (service == null) { @@ -429,6 +433,10 @@ public ServiceT getService() { } + /** + * Returns a Service RPC object for the current service. For instance, when using Google Cloud + * Storage, it returns a {@link com.google.cloud.storage.spi.StorageRpc} object. + */ @SuppressWarnings("unchecked") public ServiceRpc getRpc() { if (rpc == null) { From 46213cac407fc25bc1ca9556b9b1eedd7650ad2c Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 9 Jun 2017 16:44:53 -0700 Subject: [PATCH 377/663] Removing .spi from generated package names (#2135) --- .../src/main/java/com/google/cloud/ServiceOptions.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 3bc0ff66da..d17103fb0b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -422,7 +422,7 @@ protected static String getServiceAccountProjectId() { /** * Returns a Service object for the current service. For instance, when using Google Cloud - * Storage, it returns a {@link com.google.cloud.storage.Storage} object. + * Storage, it returns a Storage object. */ @SuppressWarnings("unchecked") public ServiceT getService() { @@ -435,7 +435,7 @@ public ServiceT getService() { /** * Returns a Service RPC object for the current service. For instance, when using Google Cloud - * Storage, it returns a {@link com.google.cloud.storage.spi.StorageRpc} object. + * Storage, it returns a StorageRpc object. */ @SuppressWarnings("unchecked") public ServiceRpc getRpc() { From cbb7ccd3a436122150db84e3ec3c3b2c13510ddb Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 15 Jun 2017 08:43:38 -0700 Subject: [PATCH 378/663] Bumping versions to 1.2.0, 0.20.0-beta, 0.20.0-alpha for release --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 42db13c03c..7f309bcff8 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.1.1-SNAPSHOT + 1.2.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.19.1-alpha-SNAPSHOT + 0.20.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 123a417248..dfad508aa0 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.1.1-SNAPSHOT + 1.2.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.19.1-alpha-SNAPSHOT + 0.20.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 5e21e0e27a..86ba4cd250 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.1.0 + 1.2.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.1.0' +compile 'com.google.cloud:google-cloud-core:1.2.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.1.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.2.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index aa181b0028..39b8a8c3fb 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.1.1-SNAPSHOT + 1.2.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.19.1-alpha-SNAPSHOT + 0.20.0-alpha google-cloud-core From d2c455fc3f130ab3ec81fc32939f338c500327b5 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 15 Jun 2017 11:07:58 -0700 Subject: [PATCH 379/663] Bumping to snapshot versions (#2154) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 7f309bcff8..5c3a1996e0 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.2.0 + 1.2.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.0-alpha + 0.20.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index dfad508aa0..a54bf9e76e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.2.0 + 1.2.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.0-alpha + 0.20.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 39b8a8c3fb..d062e93683 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.2.0 + 1.2.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.0-alpha + 0.20.1-alpha-SNAPSHOT google-cloud-core From 720e20917ff52f6e67fb27dc15e2ad4e6db7ae0c Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Wed, 21 Jun 2017 09:17:56 -0700 Subject: [PATCH 380/663] Add support for new LRO implementation (#2164) https://github.com/googleapis/gax-java/issues/147 https://github.com/googleapis/gax-java/issues/146 --- .../com/google/cloud/ExceptionHandler.java | 8 +-- .../java/com/google/cloud/RetryHelper.java | 11 ++-- .../google/cloud/ExceptionHandlerTest.java | 50 +++++++++---------- 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java index e412ddfdd0..70d6cd49bb 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java @@ -19,7 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.core.BetaApi; -import com.google.api.gax.retrying.ExceptionRetryAlgorithm; +import com.google.api.gax.retrying.ResultRetryAlgorithm; import com.google.api.gax.retrying.TimedAttemptSettings; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -37,7 +37,7 @@ * Exception retry algorithm implementation used by {@link RetryHelper}. */ @BetaApi -public final class ExceptionHandler implements ExceptionRetryAlgorithm, Serializable { +public final class ExceptionHandler implements ResultRetryAlgorithm, Serializable { private static final long serialVersionUID = -2460707015779532919L; @@ -238,7 +238,7 @@ void verifyCaller(Callable callable) { } @Override - public boolean accept(Throwable prevThrowable) { + public boolean shouldRetry(Throwable prevThrowable, Object prevResponse) { if(!(prevThrowable instanceof Exception)) { return false; } @@ -263,7 +263,7 @@ public boolean accept(Throwable prevThrowable) { } @Override - public TimedAttemptSettings createNextAttempt(Throwable prevThrowable, + public TimedAttemptSettings createNextAttempt(Throwable prevThrowable, Object prevResponse, TimedAttemptSettings prevSettings) { // Return null to indicate that this implementation does not provide any specific attempt // settings, so by default the TimedRetryAlgorithm options can be used instead. diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index 702356d405..edeeed5e84 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -18,6 +18,7 @@ import com.google.api.core.ApiClock; import com.google.api.core.BetaApi; +import com.google.api.gax.retrying.ResultRetryAlgorithm; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.retrying.DirectRetryingExecutor; @@ -37,12 +38,16 @@ public class RetryHelper { public static V runWithRetries( Callable callable, RetrySettings retrySettings, - ExceptionHandler exceptionRetryAlgorithm, + ResultRetryAlgorithm resultRetryAlgorithm, ApiClock clock) throws RetryHelperException { try { - RetryAlgorithm retryAlgorithm = - new RetryAlgorithm(exceptionRetryAlgorithm, new ExponentialRetryAlgorithm(retrySettings, clock)); + // Suppressing should be ok as a workaraund. Current and only ResultRetryAlgorithm + // implementation does not use response at all, so ignoring its type is ok. + @SuppressWarnings("unchecked") + RetryAlgorithm retryAlgorithm = + new RetryAlgorithm<>((ResultRetryAlgorithm) resultRetryAlgorithm, + new ExponentialRetryAlgorithm(retrySettings, clock)); RetryingExecutor executor = new DirectRetryingExecutor<>(retryAlgorithm); RetryingFuture retryingFuture = executor.createFuture(callable); diff --git a/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java index c78f7773d3..0a704fccf1 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java @@ -117,9 +117,9 @@ private static void assertInvalidCallable(Callable callable, ExceptionHan @Test public void testShouldTry() { ExceptionHandler handler = ExceptionHandler.newBuilder().retryOn(IOException.class).build(); - assertTrue(handler.accept(new IOException())); - assertTrue(handler.accept(new ClosedByInterruptException())); - assertFalse(handler.accept(new RuntimeException())); + assertTrue(handler.shouldRetry(new IOException(), null)); + assertTrue(handler.shouldRetry(new ClosedByInterruptException(), null)); + assertFalse(handler.shouldRetry(new RuntimeException(), null)); ExceptionHandler.Builder builder = ExceptionHandler.newBuilder() .retryOn(IOException.class, NullPointerException.class) @@ -127,11 +127,11 @@ public void testShouldTry() { InterruptedException.class); handler = builder.build(); - assertTrue(handler.accept(new IOException())); - assertFalse(handler.accept(new ClosedByInterruptException())); - assertFalse(handler.accept(new InterruptedException())); - assertFalse(handler.accept(new RuntimeException())); - assertTrue(handler.accept(new NullPointerException())); + assertTrue(handler.shouldRetry(new IOException(), null)); + assertFalse(handler.shouldRetry(new ClosedByInterruptException(), null)); + assertFalse(handler.shouldRetry(new InterruptedException(), null)); + assertFalse(handler.shouldRetry(new RuntimeException(), null)); + assertTrue(handler.shouldRetry(new NullPointerException(), null)); final AtomicReference before = new AtomicReference<>(RetryResult.NO_RETRY); @SuppressWarnings("serial") @@ -150,25 +150,25 @@ public RetryResult beforeEval(Exception exception) { builder.addInterceptors(interceptor); handler = builder.build(); - assertFalse(handler.accept(new IOException())); - assertFalse(handler.accept(new ClosedByInterruptException())); - assertFalse(handler.accept(new InterruptedException())); - assertFalse(handler.accept(new RuntimeException())); - assertFalse(handler.accept(new NullPointerException())); + assertFalse(handler.shouldRetry(new IOException(), null)); + assertFalse(handler.shouldRetry(new ClosedByInterruptException(), null)); + assertFalse(handler.shouldRetry(new InterruptedException(), null)); + assertFalse(handler.shouldRetry(new RuntimeException(), null)); + assertFalse(handler.shouldRetry(new NullPointerException(), null)); before.set(RetryResult.RETRY); - assertTrue(handler.accept(new IOException())); - assertTrue(handler.accept(new ClosedByInterruptException())); - assertTrue(handler.accept(new InterruptedException())); - assertTrue(handler.accept(new RuntimeException())); - assertTrue(handler.accept(new NullPointerException())); + assertTrue(handler.shouldRetry(new IOException(), null)); + assertTrue(handler.shouldRetry(new ClosedByInterruptException(), null)); + assertTrue(handler.shouldRetry(new InterruptedException(), null)); + assertTrue(handler.shouldRetry(new RuntimeException(), null)); + assertTrue(handler.shouldRetry(new NullPointerException(), null)); before.set(RetryResult.CONTINUE_EVALUATION); - assertFalse(handler.accept(new IOException())); - assertTrue(handler.accept(new ClosedByInterruptException())); - assertTrue(handler.accept(new InterruptedException())); - assertTrue(handler.accept(new RuntimeException())); - assertFalse(handler.accept(new NullPointerException())); + assertFalse(handler.shouldRetry(new IOException(), null)); + assertTrue(handler.shouldRetry(new ClosedByInterruptException(), null)); + assertTrue(handler.shouldRetry(new InterruptedException(), null)); + assertTrue(handler.shouldRetry(new RuntimeException(), null)); + assertFalse(handler.shouldRetry(new NullPointerException(), null)); } @Test @@ -190,7 +190,7 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build(); thrown.expect(NullPointerException.class); - handler.accept(new Exception()); + handler.shouldRetry(new Exception(), null); } @Test @@ -212,6 +212,6 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build(); thrown.expect(NullPointerException.class); - handler.accept(new Exception()); + handler.shouldRetry(new Exception(), null); } } From 84e3b588156e18395ce9af1403906be80f929ddc Mon Sep 17 00:00:00 2001 From: Thomas Coffee Date: Thu, 22 Jun 2017 15:51:15 -0700 Subject: [PATCH 381/663] WIP: override API key with service account credentials (#2151) * WIP: override API key with service account credentials Addresses #1405. Currently does not address case of conflict between explicitly passed API key and default service account credentials. Currently no integration tests use API keys. * Establish precedence of auth methods including API key Use following order of precedence for authentication, avoiding conflicts: 1. explicitly set credentials 2. explicitly set API key 3. Application Default Credentials (e.g., through GOOGLE_APPLICATION_CREDENTIALS) 4. default API key (through GOOGLE_API_KEY) * Test call with API key --- .../src/main/java/com/google/cloud/ServiceOptions.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index d17103fb0b..7200ea3dd2 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -61,6 +61,8 @@ public abstract class ServiceOptions, OptionsT extends ServiceOptions> implements Serializable { + public static final String CREDENTIAL_ENV_NAME = "GOOGLE_APPLICATION_CREDENTIALS"; + private static final String DEFAULT_HOST = "https://www.googleapis.com"; private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; @@ -84,7 +86,7 @@ public abstract class ServiceOptions, private final String serviceRpcFactoryClassName; private final String serviceFactoryClassName; private final ApiClock clock; - private final Credentials credentials; + protected Credentials credentials; private final TransportOptions transportOptions; private transient ServiceRpcFactory serviceRpcFactory; @@ -105,7 +107,7 @@ public abstract static class Builder, private String projectId; private String host; - private Credentials credentials; + protected Credentials credentials; private RetrySettings retrySettings; private ServiceFactory serviceFactory; private ServiceRpcFactory serviceRpcFactory; @@ -407,7 +409,7 @@ protected static String getAppEngineProjectId() { protected static String getServiceAccountProjectId() { String project = null; - String credentialsPath = System.getenv("GOOGLE_APPLICATION_CREDENTIALS"); + String credentialsPath = System.getenv(CREDENTIAL_ENV_NAME); if (credentialsPath != null) { try (InputStream credentialsStream = new FileInputStream(credentialsPath)) { JSONObject json = new JSONObject(new JSONTokener(credentialsStream)); From 78c41e6df4b7751da84987635754fdae717946f7 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Fri, 23 Jun 2017 14:40:35 -0700 Subject: [PATCH 382/663] Fixing spanner headers consistency issue. (#2180) * Fixing spanner headers consistency issue. Previously spanner client was sending (example valuess): user-agent: google-cloud-java/0.20.0-beta grpc-java-netty/1.2.0 x-goog-api-client: google-cloud-java/0.20.0-beta After the changes (example values): user-agent: grpc-java-netty/1.2.0, x-goog-api-client: gl-java/1.8.0_112-google-v7 gccl/0.20.1-beta-SNAPSHOT gax/1.4.0 grpc/1.2.0 --- .../cloud/grpc/GrpcTransportOptions.java | 23 ++++++++++++++++ .../cloud/grpc/GrpcTransportOptionsTest.java | 9 +++++++ .../cloud/http/HttpTransportOptions.java | 27 +++++++++++-------- .../cloud/http/HttpTransportOptionsTest.java | 8 ++---- .../com/google/cloud/TransportOptions.java | 1 - 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java index 43271ce5fc..3fa76cdf6e 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java @@ -21,8 +21,10 @@ import com.google.api.core.InternalApi; import com.google.api.gax.core.FixedCredentialsProvider; import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.core.GaxProperties; import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.grpc.ChannelProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.InstantiatingChannelProvider; import com.google.api.gax.grpc.UnaryCallSettings; import com.google.api.gax.retrying.RetrySettings; @@ -34,6 +36,7 @@ import io.grpc.internal.SharedResourceHolder.Resource; import java.io.IOException; import java.io.ObjectInputStream; +import java.util.Locale; import java.util.Objects; import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledExecutorService; @@ -71,6 +74,26 @@ public void close(ScheduledExecutorService instance) { } }; + /** + * Returns a string value for x-goog-api-client HTTP header. The header is used to report version + * of the client and its protocol-specific dependencies. + * + * For internal use. + * + * @param libraryVersion version of the google-cloud-java library + * @return value of x-goog-api-client HTTP header, which should be provided with each request + */ + @InternalApi + public String getXGoogApiClientHeader(String libraryVersion) { + return String.format(Locale.US, + "gl-java/%s %s/%s gax/%s grpc/%s", + firstNonNull(Runtime.class.getPackage().getImplementationVersion(), ""), + ServiceOptions.getGoogApiClientLibName(), + libraryVersion, + GaxProperties.getGaxVersion(), + GaxGrpcProperties.getGrpcVersion()); + } + /** * An interface for {@link ExecutorService} factories. Implementations of this interface can be * used to provide an user-defined executor to execute requests. Any implementation of this diff --git a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java index 7aff66b2d6..10454bf9d2 100644 --- a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java @@ -24,6 +24,7 @@ import com.google.cloud.grpc.GrpcTransportOptions.DefaultExecutorFactory; import com.google.cloud.grpc.GrpcTransportOptions.ExecutorFactory; import java.util.concurrent.ScheduledExecutorService; +import java.util.regex.Pattern; import org.easymock.EasyMock; import org.junit.Test; @@ -70,4 +71,12 @@ public void testDefaultExecutorFactory() { ScheduledExecutorService executorService = executorFactory.get(); assertSame(executorService, executorFactory.get()); } + + @Test + public void testHeader() { + String expectedHeaderPattern = "^gl-java/.+ gccl/0.0.0+ gax/.+ grpc/.+"; + assertTrue(Pattern.compile(expectedHeaderPattern) + .matcher(OPTIONS.getXGoogApiClientHeader("0.0.0")) + .find()); + } } diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java index b45874e71b..48c68ac854 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java @@ -24,7 +24,6 @@ import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; -import com.google.api.core.InternalApi; import com.google.auth.Credentials; import com.google.auth.http.HttpCredentialsAdapter; import com.google.auth.http.HttpTransportFactory; @@ -33,6 +32,7 @@ import com.google.cloud.TransportOptions; import java.io.IOException; import java.io.ObjectInputStream; +import java.util.Locale; import java.util.Objects; /** @@ -163,22 +163,27 @@ public void initialize(HttpRequest httpRequest) throws IOException { } HttpHeaders headers = httpRequest.getHeaders(); - headers.set("x-goog-api-client", getXGoogApiClientHeader(serviceOptions)); + headers.set( + "x-goog-api-client", getXGoogApiClientHeader(serviceOptions.getLibraryVersion())); } }; } - String getXGoogApiClientHeader(ServiceOptions serviceOptions) { - return String.format( + /** + * Returns a string value for x-goog-api-client HTTP header. The header is used to report version + * of the client and its protocol-specific dependencies. + * + * For internal use. + * + * @param libraryVersion version of the google-cloud-java library + * @return value of x-goog-api-client HTTP header, which should be provided with each request + */ + String getXGoogApiClientHeader(String libraryVersion) { + return String.format(Locale.US, "gl-java/%s %s/%s", - getJavaVersion(), + firstNonNull(Runtime.class.getPackage().getImplementationVersion(), ""), ServiceOptions.getGoogApiClientLibName(), - serviceOptions.getLibraryVersion()); - } - - private static String getJavaVersion() { - String javaVersion = Runtime.class.getPackage().getImplementationVersion(); - return javaVersion != null ? javaVersion : ""; + libraryVersion); } /** diff --git a/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java index 4240aa9172..960dfc1f0e 100644 --- a/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue; import com.google.auth.http.HttpTransportFactory; -import com.google.cloud.ServiceOptions; import com.google.cloud.http.HttpTransportOptions.DefaultHttpTransportFactory; import java.util.regex.Pattern; import org.easymock.EasyMock; @@ -65,12 +64,9 @@ public void testBaseHashCode() { @Test public void testHeader() { - String expectedHeaderPattern = "^gl-java/.* gccl/0.0.0"; - final ServiceOptions mockOptions = EasyMock.createMock(ServiceOptions.class); - EasyMock.expect(mockOptions.getLibraryVersion()).andReturn("0.0.0"); - EasyMock.replay(mockOptions); + String expectedHeaderPattern = "^gl-java/.+ gccl/0.0.0"; assertTrue(Pattern.compile(expectedHeaderPattern) - .matcher(OPTIONS.getXGoogApiClientHeader(mockOptions)) + .matcher(OPTIONS.getXGoogApiClientHeader("0.0.0")) .find()); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java index 6048db0515..84a6001f3d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java @@ -21,5 +21,4 @@ * An abstraction for transport-specific options, e.g. for http1.1 vs grpc. */ public interface TransportOptions extends Serializable { - } From 8de68374f9742d793a2cf7b4f15a635c645cd3d3 Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 26 Jun 2017 10:47:22 -0700 Subject: [PATCH 383/663] add platform information (#2183) *add platform information for transport options *add logic to distinguish GAE standard java 7 and 8 on both DevServer and Prod * Mark InternalApi * add private ctor * add comment for leading whitespace --- .../cloud/http/HttpTransportOptions.java | 4 +- .../com/google/cloud/PlatformInformation.java | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java index 48c68ac854..8acd08d800 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java @@ -28,6 +28,7 @@ import com.google.auth.http.HttpCredentialsAdapter; import com.google.auth.http.HttpTransportFactory; import com.google.cloud.NoCredentials; +import com.google.cloud.PlatformInformation; import com.google.cloud.ServiceOptions; import com.google.cloud.TransportOptions; import java.io.IOException; @@ -55,8 +56,7 @@ public static class DefaultHttpTransportFactory implements HttpTransportFactory @Override public HttpTransport create() { // Consider App Engine Standard - if (System.getProperty("com.google.appengine.runtime.version") != null - && System.getenv("GAE_SERVICE") == null) { + if (PlatformInformation.isOnGAEStandard7()) { try { return new UrlFetchTransport(); } catch (Exception ignore) { diff --git a/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java b/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java new file mode 100644 index 0000000000..272fda0293 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java @@ -0,0 +1,54 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.api.core.InternalApi; + +@InternalApi("This class should only be used within google-cloud-java") +public final class PlatformInformation { + public static final String SPECIFICATION_VERSION = + System.getProperty("java.specification.version"); + public static final String GAE_RUNTIME_VERSION = + System.getProperty("com.google.appengine.runtime.version"); + public static final String RUNTIME_JETTY_LOGGER = + System.getProperty("org.eclipse.jetty.util.log.class"); + public static final String JETTY_LOGGER_ON_GAE8_PROD = + "com.google.apphosting.runtime.jetty9.JettyLogger"; + public static final String JETTY_LOGGER_ON_GAE8_DEVSERVER = + " com.google.appengine.development.jetty9.JettyLogger"; //note the leading space + + private PlatformInformation() {} + + public static boolean isOnGAE() { + return GAE_RUNTIME_VERSION != null; + } + + public static boolean isOnGAEStandard7() { + //edge case: when a Java 7 GAE app is deployed to DevServer running on J8, SPECIFICATION_VERSION will be "1.8", + //but RUNTIME_JETTY_LOGGER is unset + return isOnGAE() && SPECIFICATION_VERSION.equals("1.7") + || isOnGAE() && RUNTIME_JETTY_LOGGER == null; + } + + public static boolean isOnGAEStandard8() { + return isOnGAE() + && !SPECIFICATION_VERSION.equals("1.7") + && RUNTIME_JETTY_LOGGER != null + && (RUNTIME_JETTY_LOGGER.equals(JETTY_LOGGER_ON_GAE8_DEVSERVER) + || RUNTIME_JETTY_LOGGER.equals(JETTY_LOGGER_ON_GAE8_PROD)); + } +} From 670b492e293fd7ca8c03fc466116ca1f1a6e84d8 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Tue, 27 Jun 2017 11:54:28 +1000 Subject: [PATCH 384/663] use grpc 1.4.0 (#2171) requires https://github.com/googleapis/googleapis/pull/384 and https://github.com/googleapis/gax-java/pull/332 bump guava version to 20.0 bump tcnative version to 2.0.3.Final as required by the new grpc version. --- google-cloud-core-grpc/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 5c3a1996e0..b173fb49f3 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -50,6 +50,10 @@ io.grpc grpc-protobuf + + io.grpc + grpc-context + com.google.api gax-grpc From 383649130f02b1cdeae2c04e01d92bc9659873ca Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Tue, 27 Jun 2017 14:13:43 +1000 Subject: [PATCH 385/663] Release 0.20.1 (#2189) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index b173fb49f3..4a570fb623 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.2.1-SNAPSHOT + 1.2.1 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.1-alpha-SNAPSHOT + 0.20.1-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index a54bf9e76e..4372503e40 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.2.1-SNAPSHOT + 1.2.1 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.1-alpha-SNAPSHOT + 0.20.1-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 86ba4cd250..16157791a4 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.2.0 + 1.2.1 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.2.0' +compile 'com.google.cloud:google-cloud-core:1.2.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.2.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.2.1" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d062e93683..b56fdfda0b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.2.1-SNAPSHOT + 1.2.1 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.1-alpha-SNAPSHOT + 0.20.1-alpha google-cloud-core From dac68542000133e34956244bc3e1e68d0906b557 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Wed, 28 Jun 2017 01:17:20 +1000 Subject: [PATCH 386/663] bump version to 0.20.2-alpha for development (#2190) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4a570fb623..0cdf6a2c1c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.2.1 + 1.2.2-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.1-alpha + 0.20.2-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 4372503e40..56fb706e99 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.2.1 + 1.2.2-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.1-alpha + 0.20.2-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b56fdfda0b..1f36f022de 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.2.1 + 1.2.2-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.1-alpha + 0.20.2-alpha-SNAPSHOT google-cloud-core From bff366a245b29f05e680a313928d82dfac828dc5 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi Date: Wed, 12 Jul 2017 21:18:44 +0000 Subject: [PATCH 387/663] Make guava dependency consistent (guava=20.0, guava-testlib=20.0). (#2233) --- google-cloud-core-grpc/pom.xml | 1 - google-cloud-core-http/pom.xml | 1 - google-cloud-core/pom.xml | 1 - 3 files changed, 3 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0cdf6a2c1c..cc6ca254ab 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -67,7 +67,6 @@ com.google.guava guava-testlib - 19.0 test diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 56fb706e99..ef2d19874f 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -104,7 +104,6 @@ com.google.guava guava-testlib - 19.0 test diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1f36f022de..a5803199b7 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -74,7 +74,6 @@ com.google.guava guava-testlib - 19.0 test From 4085a502d22882dd47ed312e5a75be2bb8dcb4c2 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Sat, 15 Jul 2017 12:33:18 +1000 Subject: [PATCH 388/663] cache library version (#2238) so we don't need to read environment properties every call. Fixes #2234. This is not the approach proposed in the issue. As implemented in this PR, we will read the property once for every client instantiation, not once ever. Still, this should be fast enough, and we won't need to maintain double-check-locking mechanism. --- .../main/java/com/google/cloud/http/HttpTransportOptions.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java index 8acd08d800..6c096e4083 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java @@ -149,6 +149,7 @@ public HttpRequestInitializer getHttpRequestInitializer( final HttpRequestInitializer delegate = scopedCredentials != null && scopedCredentials != NoCredentials.getInstance() ? new HttpCredentialsAdapter(scopedCredentials) : null; + final String xGoogHeader = getXGoogApiClientHeader(serviceOptions.getLibraryVersion()); return new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { @@ -163,8 +164,7 @@ public void initialize(HttpRequest httpRequest) throws IOException { } HttpHeaders headers = httpRequest.getHeaders(); - headers.set( - "x-goog-api-client", getXGoogApiClientHeader(serviceOptions.getLibraryVersion())); + headers.set("x-goog-api-client", xGoogHeader); } }; } From ef97b603fcd5d5ae8a2dd476da036f240929c876 Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 17 Jul 2017 15:27:38 -0700 Subject: [PATCH 389/663] Release 0.20.2 (#2244) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index cc6ca254ab..48fb73a563 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.2.2-SNAPSHOT + 1.2.2 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.2-alpha-SNAPSHOT + 0.20.2-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index ef2d19874f..3ec0201315 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.2.2-SNAPSHOT + 1.2.2 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.2-alpha-SNAPSHOT + 0.20.2-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 16157791a4..34183653bf 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.2.1 + 1.2.2 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.2.1' +compile 'com.google.cloud:google-cloud-core:1.2.2' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.2.1" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.2.2" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a5803199b7..bad7743988 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.2.2-SNAPSHOT + 1.2.2 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.2-alpha-SNAPSHOT + 0.20.2-alpha google-cloud-core From 4f1bd72fd98975a6537b1619d46ba8713ef29f29 Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 17 Jul 2017 15:55:47 -0700 Subject: [PATCH 390/663] bump version to 0.20.3-alpha for development (#2245) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 48fb73a563..3c99da89c4 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.2.2 + 1.2.3-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.2-alpha + 0.20.3-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 3ec0201315..d06f706c51 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.2.2 + 1.2.3-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.2-alpha + 0.20.3-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index bad7743988..a418d8e8ef 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.2.2 + 1.2.3-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.2-alpha + 0.20.3-alpha-SNAPSHOT google-cloud-core From 93656f803ca81a48878401a4cf9852c8e9032ea3 Mon Sep 17 00:00:00 2001 From: Thomas Coffee Date: Wed, 19 Jul 2017 14:36:58 -0700 Subject: [PATCH 391/663] Release 0.20.3 (#2261) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 3c99da89c4..f867cc98b8 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.2.3-SNAPSHOT + 1.2.3 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.3-alpha-SNAPSHOT + 0.20.3-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index d06f706c51..b2017abc95 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.2.3-SNAPSHOT + 1.2.3 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.3-alpha-SNAPSHOT + 0.20.3-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 34183653bf..9419410105 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.2.2 + 1.2.3 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.2.2' +compile 'com.google.cloud:google-cloud-core:1.2.3' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.2.2" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.2.3" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a418d8e8ef..96d9ab9232 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.2.3-SNAPSHOT + 1.2.3 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.3-alpha-SNAPSHOT + 0.20.3-alpha google-cloud-core From 769da2f422fe9b3eb4777746b0499c89b58cbc3d Mon Sep 17 00:00:00 2001 From: Thomas Coffee Date: Wed, 19 Jul 2017 16:09:02 -0700 Subject: [PATCH 392/663] Bump to next snapshot versions (#2262) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index f867cc98b8..850dc557c2 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.2.3 + 1.2.4-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.3-alpha + 0.20.4-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index b2017abc95..4d50a773a0 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.2.3 + 1.2.4-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.3-alpha + 0.20.4-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 96d9ab9232..1939a3c7bd 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.2.3 + 1.2.4-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.3-alpha + 0.20.4-alpha-SNAPSHOT google-cloud-core From 0ac1bda5968b82962d3dfb8bb168216ae5dda2e7 Mon Sep 17 00:00:00 2001 From: neozwu Date: Wed, 19 Jul 2017 20:19:24 -0700 Subject: [PATCH 393/663] use objenesis 2.6 (#2252) fix #2172 --- google-cloud-core-grpc/pom.xml | 6 +++++- google-cloud-core-http/pom.xml | 6 +++++- google-cloud-core/pom.xml | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 850dc557c2..6ffe0d67fd 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -35,7 +35,11 @@ org.easymock easymock - 3.4 + test + + + org.objenesis + objenesis test diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 4d50a773a0..d278363f15 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -92,7 +92,11 @@ org.easymock easymock - 3.4 + test + + + org.objenesis + objenesis test diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1939a3c7bd..b16d04a72e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -42,7 +42,11 @@ org.easymock easymock - 3.4 + test + + + org.objenesis + objenesis test From 66168f85330c91d92c90a887d055f9698199da13 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 20 Jul 2017 12:07:28 -0700 Subject: [PATCH 394/663] Refactoring to allow multiple transports in GAPIC clients (#2156) --- .../google/cloud/grpc/BaseGrpcServiceException.java | 8 ++++---- .../com/google/cloud/grpc/GrpcTransportOptions.java | 11 ++++------- .../cloud/grpc/BaseGrpcServiceExceptionTest.java | 5 +++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java index 77473e2089..6db03e7b0c 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java @@ -18,7 +18,7 @@ import com.google.api.client.http.HttpResponseException; import com.google.api.core.InternalApi; -import com.google.api.gax.grpc.ApiException; +import com.google.api.gax.grpc.GrpcApiException; import com.google.cloud.BaseServiceException; import com.google.common.base.MoreObjects; import java.io.IOException; @@ -64,13 +64,13 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id .build(); } - public BaseGrpcServiceException(ApiException apiException) { + public BaseGrpcServiceException(GrpcApiException apiException) { super(ExceptionData.newBuilder() .setMessage(apiException.getMessage()) .setCause(apiException) .setRetryable(apiException.isRetryable()) - .setCode(apiException.getStatusCode().value()) - .setReason(apiException.getStatusCode().name()) + .setCode(apiException.getStatusCode().getCode().value()) + .setReason(apiException.getStatusCode().getCode().name()) .setLocation(null) .setDebugInfo(null) .build()); diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java index 3fa76cdf6e..f256be1d9b 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java @@ -19,15 +19,15 @@ import static com.google.common.base.MoreObjects.firstNonNull; import com.google.api.core.InternalApi; -import com.google.api.gax.core.FixedCredentialsProvider; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.FixedCredentialsProvider; import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.grpc.ChannelProvider; import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.InstantiatingChannelProvider; -import com.google.api.gax.grpc.UnaryCallSettings; import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.UnaryCallSettings; import com.google.auth.Credentials; import com.google.cloud.NoCredentials; import com.google.cloud.ServiceOptions; @@ -181,8 +181,9 @@ public ExecutorFactory getExecutorFactory() { /** * Returns a builder for API call settings. */ + @Deprecated public UnaryCallSettings.Builder getApiCallSettings(RetrySettings retrySettings) { - return UnaryCallSettings.newBuilder().setRetrySettingsBuilder(retrySettings.toBuilder()); + return UnaryCallSettings.newUnaryCallSettingsBuilder().setRetrySettings(retrySettings); } /** @@ -193,10 +194,6 @@ public static ChannelProvider setUpChannelProvider( providerBuilder.setEndpoint(serviceOptions.getHost()) .setClientLibHeader(ServiceOptions.getGoogApiClientLibName(), firstNonNull(serviceOptions.getLibraryVersion(), "")); - Credentials scopedCredentials = serviceOptions.getScopedCredentials(); - if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { - providerBuilder.setCredentialsProvider(FixedCredentialsProvider.create(scopedCredentials)); - } return providerBuilder.build(); } diff --git a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java index c7ce99bb39..ec9b051c00 100644 --- a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import com.google.api.gax.grpc.ApiException; +import com.google.api.gax.grpc.GrpcApiException; import com.google.cloud.BaseServiceException; import com.google.cloud.RetryHelper; import io.grpc.Status.Code; @@ -73,7 +73,8 @@ public void testBaseServiceException() { assertNull(serviceException.getDebugInfo()); Exception cause = new IllegalArgumentException("bad arg"); - ApiException apiException = new ApiException(MESSAGE, cause, Code.INTERNAL, NOT_RETRYABLE); + GrpcApiException apiException = + new GrpcApiException(MESSAGE, cause, Code.INTERNAL, NOT_RETRYABLE); serviceException = new BaseGrpcServiceException(apiException); assertFalse(serviceException.isRetryable()); assertEquals(MESSAGE, serviceException.getMessage()); From 5b3f8c5b36e807e4074135ed2cbdc68593646744 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 27 Jul 2017 13:54:21 -0700 Subject: [PATCH 395/663] Fixing dependency problems for consumers of google-cloud-java (#2284) * Fixing the problem of maven choosing the wrong auth dependency by adding it explicitly as a dependency in google-cloud-core-grpc. * Adding `` to make sure we're always using the latest version of everything * Updated some versions that were not the latest (which I found from adding requireUpperBoundDeps) * Adding some special pom files which depend on a couple google-cloud-java artifacts to make sure that they don't see failures when using requireUpperBoundDeps. The auth dependency issue for error-reporting in particular doesn't show up inside google-cloud-errorreporting itself, only for a consumer of it. --- google-cloud-core-grpc/pom.xml | 21 +++++++++++++++++++++ google-cloud-core-http/pom.xml | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 6ffe0d67fd..6eb9827fd8 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -19,6 +19,15 @@ ${project.version} + + io.netty + netty-tcnative-boringssl-static + 2.0.3.Final + + + com.google.auth + google-auth-library-credentials + com.google.cloud google-cloud-core @@ -58,6 +67,18 @@ io.grpc grpc-context + + io.grpc + grpc-netty + + + io.grpc + grpc-stub + + + io.grpc + grpc-auth + com.google.api gax-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index d278363f15..ab80b271fb 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -84,6 +84,17 @@ + + com.google.http-client + google-http-client-jackson2 + compile + + + guava-jdk5 + com.google.guava + + + junit junit From 99e18a2f9f3223582c1760e28f426a045913b994 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 27 Jul 2017 15:52:25 -0700 Subject: [PATCH 396/663] Adding @BetaApi to particular exception constructors (#2286) --- .../java/com/google/cloud/grpc/BaseGrpcServiceException.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java index 6db03e7b0c..4f50fe330d 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java @@ -17,6 +17,7 @@ package com.google.cloud.grpc; import com.google.api.client.http.HttpResponseException; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.api.gax.grpc.GrpcApiException; import com.google.cloud.BaseServiceException; @@ -64,6 +65,7 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id .build(); } + @BetaApi public BaseGrpcServiceException(GrpcApiException apiException) { super(ExceptionData.newBuilder() .setMessage(apiException.getMessage()) From 08c07fba7c41a08aa540ebbf7368803c3ce8bc39 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 27 Jul 2017 15:30:58 -0700 Subject: [PATCH 397/663] Release 1.3.0, 0.21.0-beta, 0.21.0-alpha --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 6eb9827fd8..d93e9bb5c7 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.2.4-SNAPSHOT + 1.3.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.4-alpha-SNAPSHOT + 0.21.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index ab80b271fb..f19b891996 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.2.4-SNAPSHOT + 1.3.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.4-alpha-SNAPSHOT + 0.21.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 9419410105..e5c94362f0 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.2.3 + 1.3.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.2.3' +compile 'com.google.cloud:google-cloud-core:1.3.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.2.3" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.3.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b16d04a72e..dd929d89f5 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.2.4-SNAPSHOT + 1.3.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.20.4-alpha-SNAPSHOT + 0.21.0-alpha google-cloud-core From 2d4cff63770d22be8c314b9b6c204bf30319a039 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 27 Jul 2017 20:42:29 -0700 Subject: [PATCH 398/663] Bumping to next snapshot versions (#2288) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d93e9bb5c7..fd8eb1165e 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.3.0 + 1.3.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.0-alpha + 0.21.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index f19b891996..924887b258 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.3.0 + 1.3.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.0-alpha + 0.21.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index dd929d89f5..5aae527e72 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.3.0 + 1.3.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.0-alpha + 0.21.1-alpha-SNAPSHOT google-cloud-core From 6d57bae141f12cb7a3d080568c45bdc7c9edd7d1 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Mon, 31 Jul 2017 13:21:48 -0700 Subject: [PATCH 399/663] Release 0.21.1 (#2293) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index fd8eb1165e..382d0ae881 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.3.1-SNAPSHOT + 1.3.1 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.1-alpha-SNAPSHOT + 0.21.1-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 924887b258..c42d402f55 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.3.1-SNAPSHOT + 1.3.1 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.1-alpha-SNAPSHOT + 0.21.1-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index e5c94362f0..dfb87e986b 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.3.0 + 1.3.1 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.3.0' +compile 'com.google.cloud:google-cloud-core:1.3.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.3.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.3.1" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 5aae527e72..60c0b88418 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.3.1-SNAPSHOT + 1.3.1 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.1-alpha-SNAPSHOT + 0.21.1-alpha google-cloud-core From 5d306e5680b834c293262ebb28781ad72a13db64 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Mon, 31 Jul 2017 14:34:50 -0700 Subject: [PATCH 400/663] Bump to SNAPSHOT version (#2294) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 382d0ae881..5f14731d7a 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.3.1 + 1.3.2-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.1-alpha + 0.21.2-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index c42d402f55..7033e2da36 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.3.1 + 1.3.2-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.1-alpha + 0.21.2-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 60c0b88418..6b93314ff2 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.3.1 + 1.3.2-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.1-alpha + 0.21.2-alpha-SNAPSHOT google-cloud-core From c029b2d36df0170ad5a52b34b527a92d37d88d6a Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Thu, 10 Aug 2017 17:29:03 -0700 Subject: [PATCH 401/663] Fix response code retrying logic for HTTP responses with "Content-Type" other than "application/json". (#2329) --- .../java/com/google/cloud/http/BaseHttpServiceException.java | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java index ca979c6a7e..bc79026185 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java @@ -62,6 +62,7 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id } } else { code = ((GoogleJsonResponseException) exception).getStatusCode(); + retryable = BaseServiceException.isRetryable(code, null, idempotent, retryableErrors); } } else { // In cases where an exception is an instance of HttpResponseException but not From 6085888980a31ba02404951258236dc7e4179c07 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 21 Aug 2017 14:19:43 -0700 Subject: [PATCH 402/663] Release 1.4.0, 0.22.0-beta, 0.22.0-alpha --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 5f14731d7a..1b122f06b2 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.3.2-SNAPSHOT + 1.4.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.2-alpha-SNAPSHOT + 0.22.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 7033e2da36..ab9dde9851 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.3.2-SNAPSHOT + 1.4.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.2-alpha-SNAPSHOT + 0.22.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index dfb87e986b..6104ee3808 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.3.1 + 1.4.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.3.1' +compile 'com.google.cloud:google-cloud-core:1.4.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.3.1" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.4.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6b93314ff2..1f835d8d98 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.3.2-SNAPSHOT + 1.4.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.21.2-alpha-SNAPSHOT + 0.22.0-alpha google-cloud-core From 85913e3acb50ad4b5aa31e54ff1b40ee8ede821a Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 21 Aug 2017 16:05:53 -0700 Subject: [PATCH 403/663] Bumping to next snapshot versions (#2366) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 1b122f06b2..0241de9ac9 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.4.0 + 1.4.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.22.0-alpha + 0.22.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index ab9dde9851..d2e7c3de0a 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.4.0 + 1.4.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.22.0-alpha + 0.22.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1f835d8d98..9b2f86aa50 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.4.0 + 1.4.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.22.0-alpha + 0.22.1-alpha-SNAPSHOT google-cloud-core From a8e7964151b04d9be67309d03ce846f61b6628a8 Mon Sep 17 00:00:00 2001 From: neozwu Date: Tue, 22 Aug 2017 11:57:37 -0700 Subject: [PATCH 404/663] fetch project id on app engine platforms (#2304) * fetch project id on app engine platforms * resolve dependency conflict * reorder the sequence of fetching projectId * use appId to infer projectId for GAE J7 * remove appengine API reflection --- google-cloud-core/pom.xml | 16 ++++ .../java/com/google/cloud/ServiceOptions.java | 73 +++++++++++++------ 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9b2f86aa50..b7c826ba3c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -39,6 +39,22 @@ 20160810 compile + + com.google.http-client + google-http-client + + + com.google.code.findbugs + jsr305 + + + + + + com.google.code.findbugs + jsr305 + 3.0.0 + org.easymock easymock diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 7200ea3dd2..37fb4f4242 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -20,6 +20,13 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.api.client.http.GenericUrl; +import com.google.api.client.http.HttpHeaders; +import com.google.api.client.http.HttpRequest; +import com.google.api.client.http.HttpRequestFactory; +import com.google.api.client.http.HttpResponse; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.core.ApiClock; import com.google.api.core.CurrentMillisClock; import com.google.api.core.InternalApi; @@ -39,7 +46,6 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.io.Serializable; -import java.lang.reflect.Method; import java.nio.charset.Charset; import java.util.Locale; import java.util.Objects; @@ -381,30 +387,51 @@ private static boolean isWindows() { } protected static String getAppEngineProjectId() { - try { - Class factoryClass = - Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory"); - Class serviceClass = - Class.forName("com.google.appengine.api.appidentity.AppIdentityService"); - Method method = factoryClass.getMethod("getAppIdentityService"); - Object appIdentityService = method.invoke(null); - method = serviceClass.getMethod("getServiceAccountName"); - String serviceAccountName = (String) method.invoke(appIdentityService); - int indexOfAtSign = serviceAccountName.indexOf('@'); - return serviceAccountName.substring(0, indexOfAtSign); - } catch (ClassNotFoundException exception) { - if (System.getProperty("com.google.appengine.runtime.version") != null) { - // Could not resolve appengine classes under GAE environment. - throw new RuntimeException("Google App Engine runtime detected " - + "(the environment variable \"com.google.appengine.runtime.version\" is set), " - + "but unable to resolve appengine-sdk classes. " - + "For more details see " - + "https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/APPENGINE.md"); + String projectId = null; + if (PlatformInformation.isOnGAEStandard7()) { + projectId = getAppEngineProjectIdFromAppId(); + } else { + //for GAE flex and standard Java 8 environment + projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); + if (projectId == null) { + projectId = System.getenv("GCLOUD_PROJECT"); + } + if (projectId == null) { + projectId = getAppEngineProjectIdFromAppId(); + } + if (projectId == null) { + try { + projectId = getAppEngineProjectIdFromMetadataServer(); + } catch (IOException ignore) { + projectId = null; + } } - return null; - } catch (Exception ignore) { - return null; } + return projectId; + } + + protected static String getAppEngineProjectIdFromAppId() { + String projectId = getAppEngineAppId(); + if (projectId != null && projectId.contains(":")) { + int colonIndex = projectId.indexOf(":"); + projectId = projectId.substring(colonIndex + 1); + } + return projectId; + } + + private static String getAppEngineProjectIdFromMetadataServer() throws IOException { + String metadata = "http://metadata.google.internal"; + String projectIdURL = "/computeMetadata/v1/project/project-id"; + GenericUrl url = new GenericUrl(metadata + projectIdURL); + + HttpTransport netHttpTransport = new NetHttpTransport(); + HttpRequestFactory requestFactory = netHttpTransport.createRequestFactory(); + HttpRequest request = requestFactory.buildGetRequest(url) + .setConnectTimeout(500) + .setReadTimeout(500) + .setHeaders(new HttpHeaders().set("Metadata-Flavor", "Google")); + HttpResponse response = request.execute(); + return response.parseAsString(); } protected static String getServiceAccountProjectId() { From 6225073228628032d9c471e15d4b850861a56554 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Mon, 11 Sep 2017 12:51:23 -0700 Subject: [PATCH 405/663] Update to GAX 1.7.0 and 0.24.0 (#2420) --- .../com/google/cloud/grpc/BaseGrpcServiceException.java | 9 +++++---- .../google/cloud/grpc/BaseGrpcServiceExceptionTest.java | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java index 4f50fe330d..50d9176196 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java @@ -19,7 +19,8 @@ import com.google.api.client.http.HttpResponseException; import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; -import com.google.api.gax.grpc.GrpcApiException; +import com.google.api.gax.grpc.GrpcStatusCode; +import com.google.api.gax.rpc.ApiException; import com.google.cloud.BaseServiceException; import com.google.common.base.MoreObjects; import java.io.IOException; @@ -66,13 +67,13 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id } @BetaApi - public BaseGrpcServiceException(GrpcApiException apiException) { + public BaseGrpcServiceException(ApiException apiException) { super(ExceptionData.newBuilder() .setMessage(apiException.getMessage()) .setCause(apiException) .setRetryable(apiException.isRetryable()) - .setCode(apiException.getStatusCode().getCode().value()) - .setReason(apiException.getStatusCode().getCode().name()) + .setCode(((GrpcStatusCode) apiException.getStatusCode()).getCode().value()) + .setReason(((GrpcStatusCode) apiException.getStatusCode()).getCode().name()) .setLocation(null) .setDebugInfo(null) .build()); diff --git a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java index ec9b051c00..e35a3a6208 100644 --- a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java @@ -25,7 +25,9 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import com.google.api.gax.grpc.GrpcApiException; +import com.google.api.gax.grpc.GrpcStatusCode; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.InternalException; import com.google.cloud.BaseServiceException; import com.google.cloud.RetryHelper; import io.grpc.Status.Code; @@ -73,8 +75,8 @@ public void testBaseServiceException() { assertNull(serviceException.getDebugInfo()); Exception cause = new IllegalArgumentException("bad arg"); - GrpcApiException apiException = - new GrpcApiException(MESSAGE, cause, Code.INTERNAL, NOT_RETRYABLE); + InternalException apiException = + new InternalException(MESSAGE, cause, GrpcStatusCode.of(Code.INTERNAL), NOT_RETRYABLE); serviceException = new BaseGrpcServiceException(apiException); assertFalse(serviceException.isRetryable()); assertEquals(MESSAGE, serviceException.getMessage()); From 82a51ad80beeacbfc46e86971b25e5d578e38deb Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Mon, 11 Sep 2017 16:55:38 -0700 Subject: [PATCH 406/663] Bump up versions for release (#2430) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0241de9ac9..3ce018d2cb 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.4.1-SNAPSHOT + 1.5.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.22.1-alpha-SNAPSHOT + 0.23.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index d2e7c3de0a..7fe73fd8f8 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.4.1-SNAPSHOT + 1.5.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.22.1-alpha-SNAPSHOT + 0.23.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 6104ee3808..f2a7ff6511 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.4.0 + 1.5.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.4.0' +compile 'com.google.cloud:google-cloud-core:1.5.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.4.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.5.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b7c826ba3c..dd1d61c717 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.4.1-SNAPSHOT + 1.5.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.22.1-alpha-SNAPSHOT + 0.23.0-alpha google-cloud-core From 56deb5c96114d9edd13a9ef90069ce3a67a79e80 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Tue, 12 Sep 2017 10:07:17 -0700 Subject: [PATCH 407/663] Bump tp SNAPSHOT version (#2431) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 3ce018d2cb..80c2375a8d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.5.0 + 1.5.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.0-alpha + 0.23.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 7fe73fd8f8..8ce718f041 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.5.0 + 1.5.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.0-alpha + 0.23.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index dd1d61c717..6a540929f1 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.5.0 + 1.5.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.0-alpha + 0.23.1-alpha-SNAPSHOT google-cloud-core From ced56d719fa4e02970a8f5d01bd5aab96ca29ea3 Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Wed, 13 Sep 2017 08:15:43 -0700 Subject: [PATCH 408/663] Bump versions for release (#2436) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 80c2375a8d..19da73dad4 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.5.1-SNAPSHOT + 1.5.1 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.1-alpha-SNAPSHOT + 0.23.1-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 8ce718f041..829c257164 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.5.1-SNAPSHOT + 1.5.1 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.1-alpha-SNAPSHOT + 0.23.1-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f2a7ff6511..38b6cc94b8 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.5.0 + 1.5.1 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.5.0' +compile 'com.google.cloud:google-cloud-core:1.5.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.5.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.5.1" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6a540929f1..f328da3593 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.5.1-SNAPSHOT + 1.5.1 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.1-alpha-SNAPSHOT + 0.23.1-alpha google-cloud-core From 572c472d410d63af3196e614d753572b9fab246b Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Wed, 13 Sep 2017 09:59:38 -0700 Subject: [PATCH 409/663] Bump to snapshot version (#2437) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 19da73dad4..47cc1729e2 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.5.1 + 1.5.2-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.1-alpha + 0.23.2-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 829c257164..c7ee476628 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.5.1 + 1.5.2-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.1-alpha + 0.23.2-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f328da3593..51360db7ba 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.5.1 + 1.5.2-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.1-alpha + 0.23.2-alpha-SNAPSHOT google-cloud-core From d4c2a25718afda9434d959c6f2ac2f303d103b9d Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 18 Sep 2017 15:26:34 -0700 Subject: [PATCH 410/663] bump versions for release (#2449) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 47cc1729e2..0dda491579 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.5.2-SNAPSHOT + 1.6.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.2-alpha-SNAPSHOT + 0.24.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index c7ee476628..eb02d56a95 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.5.2-SNAPSHOT + 1.6.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.2-alpha-SNAPSHOT + 0.24.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 38b6cc94b8..6c8ca9b43c 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.5.1 + 1.6.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.5.1' +compile 'com.google.cloud:google-cloud-core:1.6.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.5.1" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.6.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 51360db7ba..068137a69d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.5.2-SNAPSHOT + 1.6.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.23.2-alpha-SNAPSHOT + 0.24.0-alpha google-cloud-core From eba89f0e9c1cb5900f7c5923bd81ccfe0566813c Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 18 Sep 2017 16:18:01 -0700 Subject: [PATCH 411/663] bump versions for development (#2450) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0dda491579..486c61e5ed 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.6.0 + 1.6.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.24.0-alpha + 0.24.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index eb02d56a95..5570e7b1cb 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.6.0 + 1.6.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.24.0-alpha + 0.24.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 068137a69d..afa3c415b2 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.6.0 + 1.6.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.24.0-alpha + 0.24.1-alpha-SNAPSHOT google-cloud-core From 7978b207e82e5dbcf0ce16356823ba024d23409e Mon Sep 17 00:00:00 2001 From: Neo Wu Date: Mon, 2 Oct 2017 19:33:20 -0700 Subject: [PATCH 412/663] Release 0.25.0 --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 486c61e5ed..b4ed90f0bf 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.6.1-SNAPSHOT + 1.7.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.24.1-alpha-SNAPSHOT + 0.25.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5570e7b1cb..9191fe161b 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.6.1-SNAPSHOT + 1.7.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.24.1-alpha-SNAPSHOT + 0.25.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 6c8ca9b43c..f1b74a71cc 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.6.0 + 1.7.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.6.0' +compile 'com.google.cloud:google-cloud-core:1.7.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.6.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.7.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index afa3c415b2..1230866d99 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.6.1-SNAPSHOT + 1.7.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.24.1-alpha-SNAPSHOT + 0.25.0-alpha google-cloud-core From b4351947e247f39cbb0261d0b0b9810ab726f887 Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 2 Oct 2017 22:12:16 -0700 Subject: [PATCH 413/663] bump version for development (#2474) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index b4ed90f0bf..dac7153053 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.7.0 + 1.7.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.25.0-alpha + 0.25.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 9191fe161b..9f63c79b57 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.7.0 + 1.7.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.25.0-alpha + 0.25.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1230866d99..5646d46f74 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.7.0 + 1.7.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.25.0-alpha + 0.25.1-alpha-SNAPSHOT google-cloud-core From 0d7263571e0427dde3a17a0eed19aaab30a90a5e Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Tue, 3 Oct 2017 14:59:54 -0700 Subject: [PATCH 414/663] Implement missing features and fix found bugs for BigQuery Client Library (#2446) 0) Access query results row cells by name. Now `row.get(1)` and `get("firstColumnName")` are supported (currently supported only for results returned by `BigQuery.query()` and not supported by results returned `BigQuery.listTableData()` because there is no schema and it would require additional request to the server to get schema (but still can be added in the future easily with cost of an extra network call)). Same syntax is supported for record-type fields (i.e. nested fields can be accessed by name too). 1) Refactor `BigQuery.query()` to use `jobs.insert/jobs.getQueryResults` combination instead of `jobs.query`. `QueryRequest` class was removed, now `query()` method directly accepts `QueryJobConfiguration` instead. The remaining properties of removed `QueryRequest` class now are passed in a form of `QueryOption` vararg argument. `QueryOption` combines query and waiting options (waiting options are necessary because query() is now waiting for query to complete). 2) Make `BigQuery.query()` call synchronous (waits for query completion before return result), with jittered exponential backoff for polling (based on `gax.retrying` package) 3) Add client side job id generation (`JobId.of()`) 4) Replace `WaitForOption` with `RetryOption` (based on `RetrySettings` and is consistent with the rest of the codebase). This affected compute and spanner clients too. 5) Rewrite `Job.wait()` to use jittered exponentiall backoff polling (based on`gax.retrying` package). Polling is performed differently depending on the type of job: for query jobs on each poll `getQueryResults()` is called, for all other job types `getJob()` is used instead. 6) Use standard SQL as default for all queries 7) Fix wrong query results iteration samples code used all over the place in documentation. 8) Various smaller changes/refactorings --- google-cloud-core-grpc/pom.xml | 1 - google-cloud-core-http/pom.xml | 1 - google-cloud-core/pom.xml | 1 - .../google/cloud/BaseServiceException.java | 8 + .../java/com/google/cloud/RetryHelper.java | 34 ++- .../java/com/google/cloud/RetryOption.java | 150 ++++++++++++ .../java/com/google/cloud/WaitForOption.java | 230 ------------------ .../com/google/cloud/RetryOptionTest.java | 135 ++++++++++ .../com/google/cloud/SerializationTest.java | 6 +- .../com/google/cloud/WaitForOptionTest.java | 118 --------- 10 files changed, 321 insertions(+), 363 deletions(-) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/RetryOption.java delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java create mode 100644 google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java delete mode 100644 google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index dac7153053..d3c1aee690 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -86,7 +86,6 @@ com.google.truth truth - 0.30 test diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 9f63c79b57..71446ffad7 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -113,7 +113,6 @@ com.google.truth truth - 0.30 test diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 5646d46f74..f89bb1e002 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -88,7 +88,6 @@ com.google.truth truth - 0.30 test diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index d9608991d0..10625dd1c0 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -25,6 +25,7 @@ import java.security.cert.CertificateException; import java.util.Objects; import java.util.Set; +import java.util.concurrent.ExecutionException; import javax.net.ssl.SSLHandshakeException; /** @@ -253,6 +254,13 @@ public static void translate(RetryHelper.RetryHelperException ex) { } } + @InternalApi + public static void translate(ExecutionException ex) { + if (ex.getCause() instanceof BaseServiceException) { + throw (BaseServiceException) ex.getCause(); + } + } + @InternalApi("This class should only be extended within google-cloud-java") protected BaseServiceException(ExceptionData exceptionData) { super(exceptionData.getMessage(), exceptionData.getCause()); diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index edeeed5e84..34505f6d7c 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -18,6 +18,7 @@ import com.google.api.core.ApiClock; import com.google.api.core.BetaApi; +import com.google.api.gax.retrying.ExponentialPollAlgorithm; import com.google.api.gax.retrying.ResultRetryAlgorithm; import com.google.api.gax.retrying.RetrySettings; @@ -26,12 +27,13 @@ import com.google.api.gax.retrying.RetryAlgorithm; import com.google.api.gax.retrying.RetryingExecutor; import com.google.api.gax.retrying.RetryingFuture; +import com.google.api.gax.retrying.TimedRetryAlgorithm; import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; /** * Utility class for retrying operations. For more details about the parameters, see {@link - * RetrySettings}. In case if retrying is unsuccessful, {@link RetryHelperException} will be - * thrown. + * RetrySettings}. In case if retrying is unsuccessful, {@link RetryHelperException} will be thrown. */ @BetaApi public class RetryHelper { @@ -45,18 +47,32 @@ public static V runWithRetries( // Suppressing should be ok as a workaraund. Current and only ResultRetryAlgorithm // implementation does not use response at all, so ignoring its type is ok. @SuppressWarnings("unchecked") - RetryAlgorithm retryAlgorithm = - new RetryAlgorithm<>((ResultRetryAlgorithm) resultRetryAlgorithm, - new ExponentialRetryAlgorithm(retrySettings, clock)); + ResultRetryAlgorithm algorithm = (ResultRetryAlgorithm) resultRetryAlgorithm; + return run(callable, new ExponentialRetryAlgorithm(retrySettings, clock), algorithm); + } catch (Exception e) { + //TODO: remove RetryHelperException, throw InterruptedException or ExecutionException#getCause() explicitly + throw new RetryHelperException(e.getCause()); + } + } + + public static V poll( + Callable callable, + RetrySettings pollSettings, + ResultRetryAlgorithm resultPollAlgorithm, + ApiClock clock) throws ExecutionException, InterruptedException { + return run(callable, new ExponentialPollAlgorithm(pollSettings, clock), resultPollAlgorithm); + } + + private static V run( + Callable callable, + TimedRetryAlgorithm timedAlgorithm, + ResultRetryAlgorithm resultAlgorithm) throws ExecutionException, InterruptedException { + RetryAlgorithm retryAlgorithm = new RetryAlgorithm<>(resultAlgorithm, timedAlgorithm); RetryingExecutor executor = new DirectRetryingExecutor<>(retryAlgorithm); RetryingFuture retryingFuture = executor.createFuture(callable); executor.submit(retryingFuture); - return retryingFuture.get(); - } catch (Exception e) { - throw new RetryHelperException(e.getCause()); - } } public static class RetryHelperException extends RuntimeException { diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java b/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java new file mode 100644 index 0000000000..09bfa4b5de --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java @@ -0,0 +1,150 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.api.core.BetaApi; +import java.io.Serializable; +import org.threeten.bp.Duration; +import com.google.api.gax.retrying.RetrySettings; + +/** + * This class represents an options wrapper around the {@link RetrySettings} class and is an + * alternative way of initializing it. The retry options are usually provided in a form of varargs + * for methods that wait for changes in the status of a resource, do poll operations or retry on + * failures. + */ +@BetaApi +public class RetryOption implements Serializable { + + private static final long serialVersionUID = 3622837212525370224L; + + private enum OptionType { + TOTAL_TIMEOUT, + INITIAL_RETRY_DELAY, + RETRY_DELAY_MULTIPLIER, + MAX_RETRY_DELAY, + MAX_ATTEMPTS, + JITTERED + } + + private final OptionType type; + private final Object value; + + private RetryOption(OptionType type, Object value) { + this.type = checkNotNull(type); + this.value = checkNotNull(value); + } + + /** See {@link RetrySettings#getTotalTimeout()}. */ + public static RetryOption totalTimeout(Duration totalTimeout) { + return new RetryOption(OptionType.TOTAL_TIMEOUT, totalTimeout); + } + + /** See {@link RetrySettings#getInitialRetryDelay()}. */ + public static RetryOption initialRetryDelay(Duration initialRetryDelay) { + return new RetryOption(OptionType.INITIAL_RETRY_DELAY, initialRetryDelay); + } + + /** See {@link RetrySettings#getRetryDelayMultiplier()}. */ + public static RetryOption retryDelayMultiplier(double retryDelayMultiplier) { + return new RetryOption(OptionType.RETRY_DELAY_MULTIPLIER, retryDelayMultiplier); + } + + /** See {@link RetrySettings#getMaxRetryDelay()}. */ + public static RetryOption maxRetryDelay(Duration maxRetryDelay) { + return new RetryOption(OptionType.MAX_RETRY_DELAY, maxRetryDelay); + } + + /** See {@link RetrySettings#getMaxAttempts()}. */ + public static RetryOption maxAttempts(int maxAttempts) { + return new RetryOption(OptionType.MAX_ATTEMPTS, maxAttempts); + } + + /** See {@link RetrySettings#isJittered()} ()}. */ + public static RetryOption jittered(boolean jittered) { + return new RetryOption(OptionType.JITTERED, jittered); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + RetryOption that = (RetryOption) o; + + if (type != that.type) { + return false; + } + return value.equals(that.value); + } + + @Override + public int hashCode() { + int result = type.hashCode(); + result = 31 * result + value.hashCode(); + return result; + } + + /** + * Creates a new {@code RetrySettings} instance, merging provided settings and multiple {@code + * RetryOptions}, each of which represents a single property in {@code RetrySettings}. It is an + * alternative way of initializing {@link RetrySettings} instances. + * + * @param settings retry settings + * @param options zero or more Retry + * @return new {@code RetrySettings} instance, which is a result of merging {@code options} into + * {@code settings}, i.e. each element in {@code options}, if present, overrides corresponding + * property in {@code settings} + */ + public static RetrySettings mergeToSettings(RetrySettings settings, RetryOption... options) { + if (options.length <= 0) { + return settings; + } + RetrySettings.Builder builder = settings.toBuilder(); + for (RetryOption option : options) { + switch (option.type) { + case TOTAL_TIMEOUT: + builder.setTotalTimeout((Duration) option.value); + break; + case INITIAL_RETRY_DELAY: + builder.setInitialRetryDelay((Duration) option.value); + break; + case RETRY_DELAY_MULTIPLIER: + builder.setRetryDelayMultiplier((Double) option.value); + break; + case MAX_RETRY_DELAY: + builder.setMaxRetryDelay((Duration) option.value); + break; + case MAX_ATTEMPTS: + builder.setMaxAttempts((Integer) option.value); + break; + case JITTERED: + builder.setJittered((Boolean) option.value); + break; + default: + throw new IllegalArgumentException("Unknown option type: " + option.type); + } + } + return builder.build(); + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java b/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java deleted file mode 100644 index a03b064259..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/WaitForOption.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.api.core.BetaApi; -import com.google.common.base.MoreObjects; - -import java.io.Serializable; -import java.util.Objects; -import java.util.concurrent.TimeUnit; - -/** - * This class represents options for methods that wait for changes in the status of a resource. - */ -@BetaApi -public abstract class WaitForOption implements Serializable { - - private static final long serialVersionUID = 8443451708032349243L; - - private final OptionType optionType; - - enum OptionType { - CHECKING_PERIOD, - TIMEOUT - } - - private WaitForOption(OptionType optionType) { - this.optionType = optionType; - } - - /** - * This class represents an option to set how frequently the resource status should be checked. - * Objects of this class keep the actual period and related time unit for the checking period. - */ - public static final class CheckingPeriod extends WaitForOption { - - private static final long serialVersionUID = -2481062893220539210L; - private static final CheckingPeriod DEFAULT = new CheckingPeriod(500, TimeUnit.MILLISECONDS); - - private final long period; - private final TimeUnit unit; - - private CheckingPeriod(long period, TimeUnit unit) { - super(OptionType.CHECKING_PERIOD); - this.period = period; - this.unit = unit; - } - - - /** - * Returns the checking period. - */ - public long getPeriod() { - return period; - } - - - /** - * Returns the time unit for {@link #getPeriod()}. - */ - public TimeUnit getUnit() { - return unit; - } - - /** - * Blocks the current thread for the amount of time specified by this object. - * - * @throws InterruptedException if the current thread was interrupted - */ - public void sleep() throws InterruptedException { - unit.sleep(period); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj == null || !(obj instanceof CheckingPeriod)) { - return false; - } - CheckingPeriod other = (CheckingPeriod) obj; - return baseEquals(other) - && Objects.equals(period, other.period) - && Objects.equals(unit, other.unit); - } - - @Override - public int hashCode() { - return Objects.hash(baseHashCode(), period, unit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("period", period) - .add("unit", unit) - .toString(); - } - - /** - * Returns the {@code CheckingPeriod} option specified in {@code options}. If no - * {@code CheckingPeriod} could be found among {@code options}, the default checking period (500 - * milliseconds) is used. - */ - public static CheckingPeriod getOrDefault(WaitForOption... options) { - return getOrDefaultInternal(OptionType.CHECKING_PERIOD, DEFAULT, options); - } - } - - /** - * This class represents an option to set the maximum time to wait for the resource's status to - * reach the desired state. - */ - public static final class Timeout extends WaitForOption { - - private static final long serialVersionUID = -7120401111985321932L; - private static final Timeout DEFAULT = new Timeout(-1); - - private final long timeoutMillis; - - private Timeout(long timeoutMillis) { - super(OptionType.TIMEOUT); - this.timeoutMillis = timeoutMillis; - } - - - /** - * Returns the timeout in milliseconds. - */ - public long getTimeoutMillis() { - return timeoutMillis; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj == null || !(obj instanceof Timeout)) { - return false; - } - Timeout other = (Timeout) obj; - return baseEquals(other) && Objects.equals(timeoutMillis, other.timeoutMillis); - } - - @Override - public int hashCode() { - return Objects.hash(baseHashCode(), timeoutMillis); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("timeoutMillis", timeoutMillis) - .toString(); - } - - /** - * Returns the {@code Timeout} option specified in {@code options}. If no {@code Timeout} could - * be found among {@code options}, no timeout will be used. - */ - public static Timeout getOrDefault(WaitForOption... options) { - return getOrDefaultInternal(OptionType.TIMEOUT, DEFAULT, options); - } - } - - OptionType getOptionType() { - return optionType; - } - - final boolean baseEquals(WaitForOption option) { - return Objects.equals(option.optionType, option.optionType); - } - - final int baseHashCode() { - return Objects.hash(optionType); - } - - @SuppressWarnings("unchecked") - private static T getOrDefaultInternal(OptionType optionType, - T defaultValue, WaitForOption... options) { - T foundOption = null; - for (WaitForOption option : options) { - if (option.optionType.equals(optionType)) { - checkArgument(foundOption == null, "Duplicate option %s", option); - foundOption = (T) option; - } - } - return foundOption != null ? foundOption : defaultValue; - } - - /** - * Returns an option to set how frequently the resource status should be checked. - * - * @param checkEvery the checking period - * @param unit the time unit of the checking period - */ - public static CheckingPeriod checkEvery(long checkEvery, TimeUnit unit) { - checkArgument(checkEvery >= 0, "checkEvery must be >= 0"); - return new CheckingPeriod(checkEvery, unit); - } - - /** - * Returns an option to set the maximum time to wait. - * - * @param timeout the maximum time to wait, expressed in {@code unit} - * @param unit the time unit of the timeout - */ - public static Timeout timeout(long timeout, TimeUnit unit) { - checkArgument(timeout >= 0, "timeout must be >= 0"); - return new Timeout(unit.toMillis(timeout)); - } -} diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java new file mode 100644 index 0000000000..26daff4113 --- /dev/null +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java @@ -0,0 +1,135 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import com.google.api.gax.retrying.RetrySettings; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import org.threeten.bp.Duration; + +public class RetryOptionTest { + @Rule public ExpectedException thrown = ExpectedException.none(); + + private static final RetryOption TOTAL_TIMEOUT = + RetryOption.totalTimeout(Duration.ofMillis(420L)); + private static final RetryOption INITIAL_RETRY_DELAY = + RetryOption.initialRetryDelay(Duration.ofMillis(42L)); + private static final RetryOption RETRY_DELAY_MULTIPLIER = RetryOption.retryDelayMultiplier(1.5); + private static final RetryOption MAX_RETRY_DELAY = + RetryOption.maxRetryDelay(Duration.ofMillis(100)); + private static final RetryOption MAX_ATTEMPTS = RetryOption.maxAttempts(100); + private static final RetryOption JITTERED = RetryOption.jittered(false); + + private static final RetrySettings retrySettings = + RetrySettings.newBuilder() + .setTotalTimeout(Duration.ofMillis(420L)) + .setInitialRetryDelay(Duration.ofMillis(42L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(100)) + .setMaxAttempts(100) + .setJittered(false) + .build(); + + @Test + public void testEqualsAndHashCode() { + assertEquals(TOTAL_TIMEOUT, TOTAL_TIMEOUT); + assertEquals(INITIAL_RETRY_DELAY, INITIAL_RETRY_DELAY); + assertEquals(RETRY_DELAY_MULTIPLIER, RETRY_DELAY_MULTIPLIER); + assertEquals(MAX_RETRY_DELAY, MAX_RETRY_DELAY); + assertEquals(MAX_ATTEMPTS, MAX_ATTEMPTS); + assertEquals(JITTERED, JITTERED); + + assertNotEquals(TOTAL_TIMEOUT, JITTERED); + assertNotEquals(INITIAL_RETRY_DELAY, TOTAL_TIMEOUT); + assertNotEquals(RETRY_DELAY_MULTIPLIER, INITIAL_RETRY_DELAY); + assertNotEquals(MAX_RETRY_DELAY, RETRY_DELAY_MULTIPLIER); + assertNotEquals(MAX_ATTEMPTS, MAX_RETRY_DELAY); + assertNotEquals(JITTERED, MAX_ATTEMPTS); + + RetryOption totalTimeout = RetryOption.totalTimeout(Duration.ofMillis(420L)); + RetryOption initialRetryDelay = RetryOption.initialRetryDelay(Duration.ofMillis(42L)); + RetryOption retryDelayMultiplier = RetryOption.retryDelayMultiplier(1.5); + RetryOption maxRetryDelay = RetryOption.maxRetryDelay(Duration.ofMillis(100)); + RetryOption maxAttempts = RetryOption.maxAttempts(100); + RetryOption jittered = RetryOption.jittered(false); + + assertEquals(TOTAL_TIMEOUT, totalTimeout); + assertEquals(INITIAL_RETRY_DELAY, initialRetryDelay); + assertEquals(RETRY_DELAY_MULTIPLIER, retryDelayMultiplier); + assertEquals(MAX_RETRY_DELAY, maxRetryDelay); + assertEquals(MAX_ATTEMPTS, maxAttempts); + assertEquals(JITTERED, jittered); + + assertEquals(TOTAL_TIMEOUT.hashCode(), totalTimeout.hashCode()); + assertEquals(INITIAL_RETRY_DELAY.hashCode(), initialRetryDelay.hashCode()); + assertEquals(RETRY_DELAY_MULTIPLIER.hashCode(), retryDelayMultiplier.hashCode()); + assertEquals(MAX_RETRY_DELAY.hashCode(), maxRetryDelay.hashCode()); + assertEquals(MAX_ATTEMPTS.hashCode(), maxAttempts.hashCode()); + assertEquals(JITTERED.hashCode(), jittered.hashCode()); + } + + @Test + public void testMergeToSettings() { + RetrySettings defRetrySettings = RetrySettings.newBuilder().build(); + + assertEquals(defRetrySettings, RetryOption.mergeToSettings(defRetrySettings)); + + RetrySettings mergedRetrySettings = + RetryOption.mergeToSettings( + defRetrySettings, + TOTAL_TIMEOUT, + INITIAL_RETRY_DELAY, + RETRY_DELAY_MULTIPLIER, + MAX_RETRY_DELAY, + MAX_ATTEMPTS, + JITTERED); + assertEquals(retrySettings, mergedRetrySettings); + + defRetrySettings = + defRetrySettings.toBuilder().setTotalTimeout(Duration.ofMillis(420L)).build(); + mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, TOTAL_TIMEOUT); + assertEquals(defRetrySettings, mergedRetrySettings); + + defRetrySettings = + defRetrySettings.toBuilder().setMaxRetryDelay(Duration.ofMillis(100)).build(); + mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, MAX_RETRY_DELAY); + assertEquals(defRetrySettings, mergedRetrySettings); + + defRetrySettings = + defRetrySettings.toBuilder().setInitialRetryDelay(Duration.ofMillis(42L)).build(); + mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, INITIAL_RETRY_DELAY); + assertEquals(defRetrySettings, mergedRetrySettings); + + defRetrySettings = defRetrySettings.toBuilder().setRetryDelayMultiplier(1.5).build(); + mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, RETRY_DELAY_MULTIPLIER); + assertEquals(defRetrySettings, mergedRetrySettings); + + + defRetrySettings = defRetrySettings.toBuilder().setMaxAttempts(100).build(); + mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, MAX_ATTEMPTS); + assertEquals(defRetrySettings, mergedRetrySettings); + + defRetrySettings = defRetrySettings.toBuilder().setJittered(false).build(); + mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, JITTERED); + assertEquals(defRetrySettings, mergedRetrySettings); + } +} diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 11f2dc1eeb..c76a7f9dc2 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -24,7 +24,7 @@ import com.google.common.collect.ImmutableMap; import java.io.Serializable; -import java.util.concurrent.TimeUnit; +import org.threeten.bp.Duration; public class SerializationTest extends BaseSerializationTest { @@ -37,8 +37,8 @@ public class SerializationTest extends BaseSerializationTest { private static final RetrySettings RETRY_SETTINGS = ServiceOptions.getDefaultRetrySettings(); private static final Role SOME_ROLE = Role.viewer(); private static final Policy SOME_IAM_POLICY = Policy.newBuilder().build(); - private static final WaitForOption CHECKING_PERIOD = - WaitForOption.checkEvery(42, TimeUnit.SECONDS); + private static final RetryOption CHECKING_PERIOD = + RetryOption.initialRetryDelay(Duration.ofSeconds(42)); private static final LabelDescriptor LABEL_DESCRIPTOR = new LabelDescriptor("project_id", ValueType.STRING, "The project id"); private static final MonitoredResourceDescriptor MONITORED_RESOURCE_DESCRIPTOR = diff --git a/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java deleted file mode 100644 index dffc160beb..0000000000 --- a/google-cloud-core/src/test/java/com/google/cloud/WaitForOptionTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -import com.google.cloud.WaitForOption.CheckingPeriod; -import com.google.cloud.WaitForOption.OptionType; -import com.google.cloud.WaitForOption.Timeout; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import java.util.concurrent.TimeUnit; - -public class WaitForOptionTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final CheckingPeriod CHECKING_PERIOD_OPTION = - WaitForOption.checkEvery(42, TimeUnit.MILLISECONDS); - private static final Timeout TIMEOUT_OPTION = WaitForOption.timeout(43, TimeUnit.MILLISECONDS); - - @Test - public void testCheckEvery() { - assertEquals(OptionType.CHECKING_PERIOD, CHECKING_PERIOD_OPTION.getOptionType()); - assertEquals(42, CHECKING_PERIOD_OPTION.getPeriod()); - assertEquals(TimeUnit.MILLISECONDS, CHECKING_PERIOD_OPTION.getUnit()); - } - - - @Test - public void testCheckEvery_InvalidPeriod() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("checkEvery must be >= 0"); - WaitForOption.checkEvery(-1, TimeUnit.MILLISECONDS); - } - - - @Test - public void testTimeout_InvalidTimeout() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("timeout must be >= 0"); - WaitForOption.timeout(-1, TimeUnit.MILLISECONDS); - } - - @Test - public void testEqualsAndHashCode() { - assertEquals(CHECKING_PERIOD_OPTION, CHECKING_PERIOD_OPTION); - assertEquals(TIMEOUT_OPTION, TIMEOUT_OPTION); - assertEquals(CHECKING_PERIOD_OPTION.hashCode(), CHECKING_PERIOD_OPTION.hashCode()); - assertEquals(TIMEOUT_OPTION.hashCode(), TIMEOUT_OPTION.hashCode()); - WaitForOption checkingPeriodOption = WaitForOption.checkEvery(42, TimeUnit.MILLISECONDS); - assertEquals(CHECKING_PERIOD_OPTION, checkingPeriodOption); - assertEquals(CHECKING_PERIOD_OPTION.hashCode(), checkingPeriodOption.hashCode()); - WaitForOption timeoutOption = WaitForOption.timeout(43, TimeUnit.MILLISECONDS); - assertEquals(TIMEOUT_OPTION, timeoutOption); - assertEquals(TIMEOUT_OPTION.hashCode(), timeoutOption.hashCode()); - assertNotEquals(CHECKING_PERIOD_OPTION, TIMEOUT_OPTION); - assertNotEquals(CHECKING_PERIOD_OPTION.hashCode(), TIMEOUT_OPTION.hashCode()); - checkingPeriodOption = WaitForOption.checkEvery(43, TimeUnit.MILLISECONDS); - assertNotEquals(CHECKING_PERIOD_OPTION, checkingPeriodOption); - assertNotEquals(CHECKING_PERIOD_OPTION.hashCode(), checkingPeriodOption.hashCode()); - checkingPeriodOption = WaitForOption.checkEvery(42, TimeUnit.SECONDS); - assertNotEquals(CHECKING_PERIOD_OPTION, checkingPeriodOption); - assertNotEquals(CHECKING_PERIOD_OPTION.hashCode(), checkingPeriodOption.hashCode()); - timeoutOption = WaitForOption.timeout(42, TimeUnit.MILLISECONDS); - assertNotEquals(TIMEOUT_OPTION, timeoutOption); - assertNotEquals(TIMEOUT_OPTION.hashCode(), timeoutOption.hashCode()); - timeoutOption = WaitForOption.timeout(43, TimeUnit.SECONDS); - assertNotEquals(TIMEOUT_OPTION, timeoutOption); - assertNotEquals(TIMEOUT_OPTION.hashCode(), timeoutOption.hashCode()); - } - - @Test - public void testGetOrDefault() { - assertEquals(CHECKING_PERIOD_OPTION, - CheckingPeriod.getOrDefault(CHECKING_PERIOD_OPTION, TIMEOUT_OPTION)); - assertEquals(TIMEOUT_OPTION, - Timeout.getOrDefault(CHECKING_PERIOD_OPTION, TIMEOUT_OPTION)); - CheckingPeriod checkingPeriod = CheckingPeriod.getOrDefault(TIMEOUT_OPTION); - assertEquals(500, checkingPeriod.getPeriod()); - assertEquals(TimeUnit.MILLISECONDS, checkingPeriod.getUnit()); - Timeout timeout = Timeout.getOrDefault(CHECKING_PERIOD_OPTION); - assertEquals(-1, timeout.getTimeoutMillis()); - } - - @Test - public void testCheckingPeriodGetOrDefault_DuplicateOption() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage(String.format("Duplicate option %s", CHECKING_PERIOD_OPTION)); - CheckingPeriod.getOrDefault(CHECKING_PERIOD_OPTION, CHECKING_PERIOD_OPTION); - } - - @Test - public void testTimeoutGetOrDefault_DuplicateOption() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage(String.format("Duplicate option %s", TIMEOUT_OPTION)); - Timeout.getOrDefault(TIMEOUT_OPTION, TIMEOUT_OPTION); - } -} From dc4ee67758e4045056f35abc57c7dc0294cee88c Mon Sep 17 00:00:00 2001 From: neozwu Date: Fri, 13 Oct 2017 20:39:10 -0700 Subject: [PATCH 415/663] release 0.26.0 (#2523) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d3c1aee690..2730aec347 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.7.1-SNAPSHOT + 1.8.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.25.1-alpha-SNAPSHOT + 0.26.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 71446ffad7..61551d525d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.7.1-SNAPSHOT + 1.8.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.25.1-alpha-SNAPSHOT + 0.26.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f1b74a71cc..39fe80c345 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.7.0 + 1.8.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.7.0' +compile 'com.google.cloud:google-cloud-core:1.8.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.7.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.8.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f89bb1e002..423c4f7949 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.7.1-SNAPSHOT + 1.8.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.25.1-alpha-SNAPSHOT + 0.26.0-alpha google-cloud-core From ce7a9d356aaca567add8c76d8167ced4514bdff0 Mon Sep 17 00:00:00 2001 From: neozwu Date: Fri, 13 Oct 2017 20:50:29 -0700 Subject: [PATCH 416/663] bump version for development (#2524) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 2730aec347..6732f8212b 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.8.0 + 1.8.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.26.0-alpha + 0.26.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 61551d525d..1c4786c126 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.8.0 + 1.8.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.26.0-alpha + 0.26.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 423c4f7949..59121724be 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.8.0 + 1.8.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.26.0-alpha + 0.26.1-alpha-SNAPSHOT google-cloud-core From d0ebb38f7f2f030cd798105a6f2f01a752a22600 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Wed, 25 Oct 2017 09:42:23 +1100 Subject: [PATCH 417/663] bump gax version (#2549) and put the version of netty ssl in one place --- google-cloud-core-grpc/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 6732f8212b..d13481600b 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -22,7 +22,6 @@ io.netty netty-tcnative-boringssl-static - 2.0.3.Final com.google.auth From 378cbaf9c8d9fbdc06d2cd037ed4fe1c3852cd52 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 31 Oct 2017 19:15:34 -0700 Subject: [PATCH 418/663] Regenerating clients (breaking changes) (#2564) --- .../cloud/grpc/BaseGrpcServiceException.java | 4 +-- .../cloud/grpc/GrpcTransportOptions.java | 27 ++++++++++++------- .../grpc/BaseGrpcServiceExceptionTest.java | 3 +-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java index 50d9176196..e1516c01ee 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java @@ -72,8 +72,8 @@ public BaseGrpcServiceException(ApiException apiException) { .setMessage(apiException.getMessage()) .setCause(apiException) .setRetryable(apiException.isRetryable()) - .setCode(((GrpcStatusCode) apiException.getStatusCode()).getCode().value()) - .setReason(((GrpcStatusCode) apiException.getStatusCode()).getCode().name()) + .setCode(apiException.getStatusCode().getCode().getHttpStatusCode()) + .setReason(apiException.getStatusCode().getCode().name()) .setLocation(null) .setDebugInfo(null) .build()); diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java index f256be1d9b..70c0d7a4da 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java @@ -18,15 +18,17 @@ import static com.google.common.base.MoreObjects.firstNonNull; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.api.gax.core.CredentialsProvider; -import com.google.api.gax.core.GaxProperties; import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.api.gax.core.GaxProperties; import com.google.api.gax.core.NoCredentialsProvider; -import com.google.api.gax.grpc.ChannelProvider; import com.google.api.gax.grpc.GaxGrpcProperties; -import com.google.api.gax.grpc.InstantiatingChannelProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.TransportChannelProvider; import com.google.api.gax.rpc.UnaryCallSettings; import com.google.auth.Credentials; import com.google.cloud.NoCredentials; @@ -189,11 +191,18 @@ public UnaryCallSettings.Builder getApiCallSettings(RetrySettings retrySettings) /** * Returns a channel provider from the given default provider. */ - public static ChannelProvider setUpChannelProvider( - InstantiatingChannelProvider.Builder providerBuilder, ServiceOptions serviceOptions) { - providerBuilder.setEndpoint(serviceOptions.getHost()) - .setClientLibHeader(ServiceOptions.getGoogApiClientLibName(), - firstNonNull(serviceOptions.getLibraryVersion(), "")); + @BetaApi + public static TransportChannelProvider setUpChannelProvider( + InstantiatingGrpcChannelProvider.Builder providerBuilder, ServiceOptions serviceOptions) { + providerBuilder.setEndpoint(serviceOptions.getHost()); + return providerBuilder.build(); + } + + @BetaApi + public static ApiClientHeaderProvider setUpHeaderProvider( + ApiClientHeaderProvider.Builder providerBuilder, ServiceOptions serviceOptions) { + providerBuilder.setClientLibHeader(ServiceOptions.getGoogApiClientLibName(), + firstNonNull(serviceOptions.getLibraryVersion(), "")); return providerBuilder.build(); } @@ -202,7 +211,7 @@ public static CredentialsProvider setUpCredentialsProvider(ServiceOptions if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { return FixedCredentialsProvider.create(scopedCredentials); } - return new NoCredentialsProvider(); + return NoCredentialsProvider.create(); } diff --git a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java index e35a3a6208..8a95dfc55c 100644 --- a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java @@ -38,7 +38,6 @@ public class BaseGrpcServiceExceptionTest { - private static final int CODE = 1; private static final String MESSAGE = "some message"; private static final boolean NOT_RETRYABLE = false; private static final boolean IDEMPOTENT = true; @@ -81,7 +80,7 @@ public void testBaseServiceException() { assertFalse(serviceException.isRetryable()); assertEquals(MESSAGE, serviceException.getMessage()); assertEquals(apiException, serviceException.getCause()); - assertEquals(Code.INTERNAL.value(), serviceException.getCode()); + assertEquals(500, serviceException.getCode()); assertEquals(Code.INTERNAL.name(), serviceException.getReason()); assertNull(serviceException.getLocation()); assertNull(serviceException.getDebugInfo()); From 91035a939cb83467ef0beb31c5e7702b87c96450 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Wed, 8 Nov 2017 11:19:35 -0800 Subject: [PATCH 419/663] Release 0.27.0 (#2596) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d13481600b..1f49bdc32b 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.8.1-SNAPSHOT + 1.9.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.26.1-alpha-SNAPSHOT + 0.27.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 1c4786c126..0a2d7ccd4b 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.8.1-SNAPSHOT + 1.9.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.26.1-alpha-SNAPSHOT + 0.27.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 39fe80c345..7d615e185e 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.8.0 + 1.9.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.8.0' +compile 'com.google.cloud:google-cloud-core:1.9.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.8.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.9.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 59121724be..e53386407a 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.8.1-SNAPSHOT + 1.9.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.26.1-alpha-SNAPSHOT + 0.27.0-alpha google-cloud-core From e16eceb8e4411e28adc13b8ae1d31357f76f261b Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Wed, 8 Nov 2017 13:31:07 -0800 Subject: [PATCH 420/663] Update pom.xml version to 0.27.1-SNAPSHOT by script (#2595) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 1f49bdc32b..8502b3b62c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.9.0 + 1.9.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.27.0-alpha + 0.27.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 0a2d7ccd4b..671f615d29 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.9.0 + 1.9.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.27.0-alpha + 0.27.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e53386407a..58fa3d5ca9 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.9.0 + 1.9.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.27.0-alpha + 0.27.1-alpha-SNAPSHOT google-cloud-core From 6575d545f237f50056a8f27001e5b156e625f816 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 8 Nov 2017 16:26:28 -0800 Subject: [PATCH 421/663] Release 0.28.0 --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 8502b3b62c..a28418f4cf 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.9.1-SNAPSHOT + 1.10.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.27.1-alpha-SNAPSHOT + 0.28.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 671f615d29..4c3a4f4799 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.9.1-SNAPSHOT + 1.10.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.27.1-alpha-SNAPSHOT + 0.28.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 7d615e185e..2454c2089f 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.9.0 + 1.10.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.9.0' +compile 'com.google.cloud:google-cloud-core:1.10.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.9.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.10.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 58fa3d5ca9..ced21b2a5b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.9.1-SNAPSHOT + 1.10.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.27.1-alpha-SNAPSHOT + 0.28.0-alpha google-cloud-core From b4a80696050a3dac9aaf16434588e31ed986bd19 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 8 Nov 2017 20:35:49 -0800 Subject: [PATCH 422/663] Bumping to next snapshot versions (#2603) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index a28418f4cf..05809dfd2d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.10.0 + 1.10.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.28.0-alpha + 0.28.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 4c3a4f4799..23622bc395 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.10.0 + 1.10.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.28.0-alpha + 0.28.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index ced21b2a5b..1a594b79e5 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.10.0 + 1.10.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.28.0-alpha + 0.28.1-alpha-SNAPSHOT google-cloud-core From cfdf43ac64ed50b7e5ac0f51eee3675b26e039a3 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Tue, 14 Nov 2017 19:19:41 -0800 Subject: [PATCH 423/663] Release 0.29.0 (#2627) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 05809dfd2d..cb2e1c5618 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.10.1-SNAPSHOT + 1.11.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.28.1-alpha-SNAPSHOT + 0.29.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 23622bc395..b14dd53e75 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.10.1-SNAPSHOT + 1.11.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.28.1-alpha-SNAPSHOT + 0.29.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 2454c2089f..b4dfac3d90 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.10.0 + 1.11.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.10.0' +compile 'com.google.cloud:google-cloud-core:1.11.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.10.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.11.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1a594b79e5..82631aa23d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.10.1-SNAPSHOT + 1.11.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.28.1-alpha-SNAPSHOT + 0.29.0-alpha google-cloud-core From afa28a38951b01fbf43c83fc1794e405d66d5573 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Tue, 14 Nov 2017 22:10:08 -0800 Subject: [PATCH 424/663] Bump version to 0.29.1-SNAPSHOT for development (#2628) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index cb2e1c5618..53d01f00c1 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.11.0 + 1.11.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.29.0-alpha + 0.29.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index b14dd53e75..3528295940 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.11.0 + 1.11.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.29.0-alpha + 0.29.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 82631aa23d..70d6b81e8b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.11.0 + 1.11.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.29.0-alpha + 0.29.1-alpha-SNAPSHOT google-cloud-core From 6885ca5adeaafd1b06326145a30a6892b42bf373 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 15 Nov 2017 18:54:22 -0800 Subject: [PATCH 425/663] Release 1.12.0/0.30.0 --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 53d01f00c1..4c08f90b48 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.11.1-SNAPSHOT + 1.12.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.29.1-alpha-SNAPSHOT + 0.30.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 3528295940..fe47c37a54 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.11.1-SNAPSHOT + 1.12.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.29.1-alpha-SNAPSHOT + 0.30.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index b4dfac3d90..5f040b0d7e 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.11.0 + 1.12.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.11.0' +compile 'com.google.cloud:google-cloud-core:1.12.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.11.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.12.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 70d6b81e8b..2fccc7fd15 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.11.1-SNAPSHOT + 1.12.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.29.1-alpha-SNAPSHOT + 0.30.0-alpha google-cloud-core From b0183224d6440f3e31bead9171c852a7b847d269 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 16 Nov 2017 08:59:59 -0800 Subject: [PATCH 426/663] Bumping to next snapshot version (#2635) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4c08f90b48..5294ffa03a 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.12.0 + 1.12.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.30.0-alpha + 0.30.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index fe47c37a54..5b225e1cce 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.12.0 + 1.12.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.30.0-alpha + 0.30.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2fccc7fd15..4069dabdb2 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.12.0 + 1.12.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.30.0-alpha + 0.30.1-alpha-SNAPSHOT google-cloud-core From 7e6dc5804bc5354f457afa2ae46ba2f1855d1dca Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 20 Nov 2017 17:01:12 -0800 Subject: [PATCH 427/663] Moving off some deprecated stuff (#2640) --- .../src/main/java/com/google/cloud/AsyncPageImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index 8048b9e18f..643fe0b21d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -64,7 +64,8 @@ public Page getNextPage() { return asyncPageFetcher != null ? Uninterruptibles.getUninterruptibly(asyncPageFetcher.getNextPage()) : null; } catch (ExecutionException ex) { - throw Throwables.propagate(ex.getCause()); + Throwables.throwIfUnchecked(ex.getCause()); + throw new RuntimeException(ex); } } } From 99fcebafc2d0da225677b5a10ac0047e61310a8f Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 7 Dec 2017 16:07:26 -0800 Subject: [PATCH 428/663] Creating BOM (google-cloud-bom) (#2679) --- google-cloud-core/pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4069dabdb2..6309376650 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -36,7 +36,6 @@ org.json json - 20160810 compile @@ -53,7 +52,6 @@ com.google.code.findbugs jsr305 - 3.0.0 org.easymock From 2b451e4110cf9d0f8fc157f8d9f8471bc2455c66 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Mon, 11 Dec 2017 17:15:52 -0800 Subject: [PATCH 429/663] Bump version to 0.32.0 (#2684) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 5294ffa03a..64faf80e12 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.12.1-SNAPSHOT + 1.14.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.30.1-alpha-SNAPSHOT + 0.32.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5b225e1cce..33f490d417 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.12.1-SNAPSHOT + 1.14.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.30.1-alpha-SNAPSHOT + 0.32.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 5f040b0d7e..8b7858b9a6 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.12.0 + 1.14.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.12.0' +compile 'com.google.cloud:google-cloud-core:1.14.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.12.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.14.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6309376650..cf7ce4a0ef 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.12.1-SNAPSHOT + 1.14.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.30.1-alpha-SNAPSHOT + 0.32.0-alpha google-cloud-core From b23a6f8c4e6eb8ca40ac4f8cd318d0190420b120 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 12 Dec 2017 11:11:40 -0800 Subject: [PATCH 430/663] Bump versions to SNAPSHOT (#2700) alpha version now 0.32.1-alpha-SNAPSHOT beta version now 0.32.1-beta-SNAPSHOT ga version now 1.14.1-SNAPSHOT --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 64faf80e12..40db8bf469 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.14.0 + 1.14.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.32.0-alpha + 0.32.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 33f490d417..c3c747d2a9 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.14.0 + 1.14.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.32.0-alpha + 0.32.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index cf7ce4a0ef..8e24bd9ab0 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.14.0 + 1.14.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.32.0-alpha + 0.32.1-alpha-SNAPSHOT google-cloud-core From ee1774202ac5d9c300e0afd41a58957968c7d5b7 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Thu, 14 Dec 2017 15:42:09 -0800 Subject: [PATCH 431/663] Add support for custom static headers (#2690) Note, PubSub is supported only partially. Full support is dependent on migration of PubSub from Grpc stubs to Gapic stubs Usage: ```java // For manual/semi-manual clients: // Resource Manager // Translate // Compute // Storage // Datastore // Dns // BigQuery // // Logging // Firestore // Spanner HeaderProvider headerProvider = FixedHeaderProvider.create("user-agent", "my-client-name", "custom-header", "custom stuff"); DatastoreOptions options = DatastoreOptions.newBuilder().setHeaderProvider(headerProvider).build(); Datastore datastore = options.getService(); // For generated clients: // All others, except Pub/Sub HeaderProvider headerProvider = FixedHeaderProvider.create("user-agent", "my-client-name", "custom-header", "custom stuff"); LanguageServiceSettings settings = LanguageServiceSettings.newBuilder().setHeaderProvider(headerProvider).build(); LanguageServiceClient client = LanguageServiceClient.create(settings); // Note, PubSub is supported only partially. Full support is dependent on migration of PubSub from Grpc stubs to Gapic stubs ``` --- google-cloud-core-grpc/pom.xml | 1 - .../cloud/grpc/GrpcTransportOptions.java | 32 ------- .../cloud/grpc/GrpcTransportOptionsTest.java | 9 -- google-cloud-core-http/pom.xml | 5 +- .../cloud/http/HttpTransportOptions.java | 33 +++---- .../cloud/http/HttpTransportOptionsTest.java | 10 +- google-cloud-core/pom.xml | 33 ------- .../java/com/google/cloud/ServiceOptions.java | 96 +++++++++++++------ 8 files changed, 93 insertions(+), 126 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 40db8bf469..4664c9ebc8 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -16,7 +16,6 @@ google-cloud-core-grpc - ${project.version} diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java index 70c0d7a4da..aa727f8d0b 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java @@ -22,12 +22,9 @@ import com.google.api.core.InternalApi; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.FixedCredentialsProvider; -import com.google.api.gax.core.GaxProperties; import com.google.api.gax.core.NoCredentialsProvider; -import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.retrying.RetrySettings; -import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.TransportChannelProvider; import com.google.api.gax.rpc.UnaryCallSettings; import com.google.auth.Credentials; @@ -38,7 +35,6 @@ import io.grpc.internal.SharedResourceHolder.Resource; import java.io.IOException; import java.io.ObjectInputStream; -import java.util.Locale; import java.util.Objects; import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledExecutorService; @@ -76,26 +72,6 @@ public void close(ScheduledExecutorService instance) { } }; - /** - * Returns a string value for x-goog-api-client HTTP header. The header is used to report version - * of the client and its protocol-specific dependencies. - * - * For internal use. - * - * @param libraryVersion version of the google-cloud-java library - * @return value of x-goog-api-client HTTP header, which should be provided with each request - */ - @InternalApi - public String getXGoogApiClientHeader(String libraryVersion) { - return String.format(Locale.US, - "gl-java/%s %s/%s gax/%s grpc/%s", - firstNonNull(Runtime.class.getPackage().getImplementationVersion(), ""), - ServiceOptions.getGoogApiClientLibName(), - libraryVersion, - GaxProperties.getGaxVersion(), - GaxGrpcProperties.getGrpcVersion()); - } - /** * An interface for {@link ExecutorService} factories. Implementations of this interface can be * used to provide an user-defined executor to execute requests. Any implementation of this @@ -198,14 +174,6 @@ public static TransportChannelProvider setUpChannelProvider( return providerBuilder.build(); } - @BetaApi - public static ApiClientHeaderProvider setUpHeaderProvider( - ApiClientHeaderProvider.Builder providerBuilder, ServiceOptions serviceOptions) { - providerBuilder.setClientLibHeader(ServiceOptions.getGoogApiClientLibName(), - firstNonNull(serviceOptions.getLibraryVersion(), "")); - return providerBuilder.build(); - } - public static CredentialsProvider setUpCredentialsProvider(ServiceOptions serviceOptions) { Credentials scopedCredentials = serviceOptions.getScopedCredentials(); if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { diff --git a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java index 10454bf9d2..7aff66b2d6 100644 --- a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java @@ -24,7 +24,6 @@ import com.google.cloud.grpc.GrpcTransportOptions.DefaultExecutorFactory; import com.google.cloud.grpc.GrpcTransportOptions.ExecutorFactory; import java.util.concurrent.ScheduledExecutorService; -import java.util.regex.Pattern; import org.easymock.EasyMock; import org.junit.Test; @@ -71,12 +70,4 @@ public void testDefaultExecutorFactory() { ScheduledExecutorService executorService = executorFactory.get(); assertSame(executorService, executorFactory.get()); } - - @Test - public void testHeader() { - String expectedHeaderPattern = "^gl-java/.+ gccl/0.0.0+ gax/.+ grpc/.+"; - assertTrue(Pattern.compile(expectedHeaderPattern) - .matcher(OPTIONS.getXGoogApiClientHeader("0.0.0")) - .find()); - } } diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index c3c747d2a9..29cb2d349f 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -16,7 +16,6 @@ google-cloud-core-http - ${project.version} @@ -95,6 +94,10 @@ + + com.google.api + gax-httpjson + junit junit diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java index 6c096e4083..2ab57195d4 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java @@ -19,11 +19,14 @@ import static com.google.common.base.MoreObjects.firstNonNull; import com.google.api.client.extensions.appengine.http.UrlFetchTransport; -import com.google.api.client.http.HttpHeaders; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.httpjson.HttpHeadersUtils; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.HeaderProvider; import com.google.auth.Credentials; import com.google.auth.http.HttpCredentialsAdapter; import com.google.auth.http.HttpTransportFactory; @@ -33,7 +36,6 @@ import com.google.cloud.TransportOptions; import java.io.IOException; import java.io.ObjectInputStream; -import java.util.Locale; import java.util.Objects; /** @@ -149,7 +151,9 @@ public HttpRequestInitializer getHttpRequestInitializer( final HttpRequestInitializer delegate = scopedCredentials != null && scopedCredentials != NoCredentials.getInstance() ? new HttpCredentialsAdapter(scopedCredentials) : null; - final String xGoogHeader = getXGoogApiClientHeader(serviceOptions.getLibraryVersion()); + HeaderProvider internalHeaderProvider = getInternalHeaderProviderBuilder(serviceOptions).build(); + final HeaderProvider headerProvider = serviceOptions.getMergedHeaderProvider(internalHeaderProvider); + return new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { @@ -163,27 +167,18 @@ public void initialize(HttpRequest httpRequest) throws IOException { httpRequest.setReadTimeout(readTimeout); } - HttpHeaders headers = httpRequest.getHeaders(); - headers.set("x-goog-api-client", xGoogHeader); + HttpHeadersUtils.setHeaders(httpRequest.getHeaders(), headerProvider.getHeaders()); } }; } - /** - * Returns a string value for x-goog-api-client HTTP header. The header is used to report version - * of the client and its protocol-specific dependencies. - * - * For internal use. - * - * @param libraryVersion version of the google-cloud-java library - * @return value of x-goog-api-client HTTP header, which should be provided with each request - */ - String getXGoogApiClientHeader(String libraryVersion) { - return String.format(Locale.US, - "gl-java/%s %s/%s", - firstNonNull(Runtime.class.getPackage().getImplementationVersion(), ""), + ApiClientHeaderProvider.Builder getInternalHeaderProviderBuilder( + ServiceOptions serviceOptions) { + ApiClientHeaderProvider.Builder builder = ApiClientHeaderProvider.newBuilder(); + builder.setClientLibToken( ServiceOptions.getGoogApiClientLibName(), - libraryVersion); + GaxProperties.getLibraryVersion(serviceOptions.getClass())); + return builder; } /** diff --git a/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java index 960dfc1f0e..b0fec9185e 100644 --- a/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java @@ -21,7 +21,9 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import com.google.api.gax.rpc.HeaderProvider; import com.google.auth.http.HttpTransportFactory; +import com.google.cloud.ServiceOptions; import com.google.cloud.http.HttpTransportOptions.DefaultHttpTransportFactory; import java.util.regex.Pattern; import org.easymock.EasyMock; @@ -64,9 +66,13 @@ public void testBaseHashCode() { @Test public void testHeader() { - String expectedHeaderPattern = "^gl-java/.+ gccl/0.0.0"; + String expectedHeaderPattern = "^gl-java/.+ gccl/.* gax/.+"; + ServiceOptions serviceOptions = EasyMock.createMock(ServiceOptions.class); + HeaderProvider headerProvider = OPTIONS.getInternalHeaderProviderBuilder(serviceOptions).build(); + + assertEquals(1, headerProvider.getHeaders().size()); assertTrue(Pattern.compile(expectedHeaderPattern) - .matcher(OPTIONS.getXGoogApiClientHeader("0.0.0")) + .matcher(headerProvider.getHeaders().values().iterator().next()) .find()); } } diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 8e24bd9ab0..e702c89a8f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -16,7 +16,6 @@ google-cloud-core - ${project.version} @@ -94,36 +93,4 @@ test - - - - ./.. - true - - project.properties - - - - - - maven-antrun-plugin - 1.4 - - - process-resources - - - - - - - run - - - - - - diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 37fb4f4242..43bccbdec6 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -28,13 +28,18 @@ import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.core.ApiClock; +import com.google.api.core.BetaApi; import com.google.api.core.CurrentMillisClock; import com.google.api.core.InternalApi; -import com.google.api.gax.core.PropertiesProvider; +import com.google.api.gax.core.GaxProperties; import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.FixedHeaderProvider; +import com.google.api.gax.rpc.HeaderProvider; +import com.google.api.gax.rpc.NoHeaderProvider; import com.google.auth.Credentials; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.io.Files; import java.io.BufferedReader; @@ -48,6 +53,7 @@ import java.io.Serializable; import java.nio.charset.Charset; import java.util.Locale; +import java.util.Map; import java.util.Objects; import java.util.ServiceLoader; import java.util.Set; @@ -72,12 +78,6 @@ public abstract class ServiceOptions, private static final String DEFAULT_HOST = "https://www.googleapis.com"; private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; - private static final String LIBRARY_NAME = "gcloud-java"; - private static final String X_GOOGLE_CLIENT_HEADER_NAME = "gccl"; - - private static final String PROPERTIES_VERSION_KEY = "artifact.version"; - private static final String DEFAULT_PACKAGE_PATH = "com/google/cloud"; - private static final String PROPERTIES_FILE = "project.properties"; private static final RetrySettings DEFAULT_RETRY_SETTINGS = getDefaultRetrySettingsBuilder() .build(); @@ -94,6 +94,7 @@ public abstract class ServiceOptions, private final ApiClock clock; protected Credentials credentials; private final TransportOptions transportOptions; + private final HeaderProvider headerProvider; private transient ServiceRpcFactory serviceRpcFactory; private transient ServiceFactory serviceFactory; @@ -119,6 +120,7 @@ public abstract static class Builder, private ServiceRpcFactory serviceRpcFactory; private ApiClock clock; private TransportOptions transportOptions; + private HeaderProvider headerProvider; @InternalApi("This class should only be extended within google-cloud-java") protected Builder() {} @@ -234,6 +236,22 @@ public B setTransportOptions(TransportOptions transportOptions) { this.transportOptions = transportOptions; return self(); } + + /** + * Sets the static header provider. The header provider will be called during client + * construction only once. The headers returned by the provider will be cached and supplied as + * is for each request issued by the constructed client. Some reserved headers can be overridden + * (e.g. Content-Type) or merged with the default value (e.g. User-Agent) by the underlying + * transport layer. + * + * @param headerProvider the header provider + * @return the builder + */ + @BetaApi + public B setHeaderProvider(HeaderProvider headerProvider) { + this.headerProvider = headerProvider; + return self(); + } } @InternalApi("This class should only be extended within google-cloud-java") @@ -260,6 +278,7 @@ protected ServiceOptions(Class> ser clock = firstNonNull(builder.clock, CurrentMillisClock.getDefaultClock()); transportOptions = firstNonNull(builder.transportOptions, serviceDefaults.getDefaultTransportOptions()); + headerProvider = firstNonNull(builder.headerProvider, new NoHeaderProvider()); } /** @@ -535,40 +554,69 @@ public TransportOptions getTransportOptions() { } /** - * Returns the application's name as a string in the format {@code gcloud-java/[version]}. + * Returns the application's name as a string in the format {@code gcloud-java/[version]}, + * optionally prepended with externally supplied User-Agent header value (via setting custom + * header provider). */ public String getApplicationName() { String libraryVersion = getLibraryVersion(); - return libraryVersion == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + libraryVersion; - } + // We have to do the following since underlying layers often do not appreciate User-Agent + // provided as a normal header and override it or treat setting "application name" as the only + // way to append something to User-Agent header. + StringBuilder sb = new StringBuilder(); + String customUserAgentValue = getUserAgent(); + if (customUserAgentValue != null) { + sb.append(customUserAgentValue).append(' '); + } + if (libraryVersion == null) { + sb.append(getLibraryName()); + } else { + sb.append(getLibraryName()).append('/').append(libraryVersion); + } + + return sb.toString(); + } /** * Returns the library's name, {@code gcloud-java}, as a string. */ public static String getLibraryName() { - return LIBRARY_NAME; + return "gcloud-java"; } /** * Returns the library's name used by x-goog-api-client header as a string. */ public static String getGoogApiClientLibName() { - return X_GOOGLE_CLIENT_HEADER_NAME; + return "gccl"; } /** * Returns the library's version as a string. */ public String getLibraryVersion() { - try { - String version = getVersionProperty(getPackagePath()); - if (version == null) { - version = getVersionProperty(DEFAULT_PACKAGE_PATH); + return GaxProperties.getLibraryVersion(this.getClass()); + } + + @InternalApi + public final HeaderProvider getMergedHeaderProvider(HeaderProvider internalHeaderProvider) { + Map mergedHeaders = + ImmutableMap.builder() + .putAll(internalHeaderProvider.getHeaders()) + .putAll(headerProvider.getHeaders()) + .build(); + return FixedHeaderProvider.create(mergedHeaders); + } + + @InternalApi + public final String getUserAgent() { + if (headerProvider != null) { + for (Map.Entry entry : headerProvider.getHeaders().entrySet()) { + if ("user-agent".equals(entry.getKey().toLowerCase())) { + return entry.getValue(); + } } - return version; - } catch (Exception e) { - // ignore } return null; } @@ -641,14 +689,4 @@ protected RetrySettings defaultRetrySettings() { public static T getFromServiceLoader(Class clazz, T defaultInstance) { return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance); } - - private String getVersionProperty(String packagePath) { - String projectPropertiesPath = "/" + packagePath + "/" + PROPERTIES_FILE; - return PropertiesProvider.loadProperty( - ServiceOptions.class, projectPropertiesPath, PROPERTIES_VERSION_KEY); - } - - private String getPackagePath() { - return this.getClass().getPackage().getName().replaceAll("\\.", "/"); - } } From 6a37dab09c4bd8f01ca586d6b719ee4c2ac46d62 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 21 Dec 2017 11:51:22 -0800 Subject: [PATCH 432/663] Removing compile dependency on org.json (#2728) --- google-cloud-core/pom.xml | 5 ---- .../java/com/google/cloud/ServiceOptions.java | 23 +++++++++----- .../com/google/cloud/ServiceOptionsTest.java | 30 +++++++++++++++++++ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e702c89a8f..b8ba2578dc 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -32,11 +32,6 @@ joda-time compile - - org.json - json - compile - com.google.http-client google-http-client diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 43bccbdec6..cca3518c29 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -27,6 +27,11 @@ import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.client.json.GenericJson; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.JsonObjectParser; +import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.util.Charsets; import com.google.api.core.ApiClock; import com.google.api.core.BetaApi; import com.google.api.core.CurrentMillisClock; @@ -59,9 +64,6 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONTokener; import org.threeten.bp.Duration; /** @@ -454,13 +456,20 @@ private static String getAppEngineProjectIdFromMetadataServer() throws IOExcepti } protected static String getServiceAccountProjectId() { + return getServiceAccountProjectId(System.getenv(CREDENTIAL_ENV_NAME)); + } + + @InternalApi("Visible for testing") + static String getServiceAccountProjectId(String credentialsPath) { String project = null; - String credentialsPath = System.getenv(CREDENTIAL_ENV_NAME); if (credentialsPath != null) { try (InputStream credentialsStream = new FileInputStream(credentialsPath)) { - JSONObject json = new JSONObject(new JSONTokener(credentialsStream)); - project = json.getString("project_id"); - } catch (IOException | JSONException ex) { + JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); + JsonObjectParser parser = new JsonObjectParser(jsonFactory); + GenericJson fileContents = parser.parseAndClose( + credentialsStream, Charsets.UTF_8, GenericJson.class); + project = (String) fileContents.get("project_id"); + } catch (IOException e) { // ignore } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 3238a30c8c..6bd613d6cf 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -19,6 +19,7 @@ import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -28,10 +29,14 @@ import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.Charset; import java.util.Set; import java.util.regex.Pattern; + +import com.google.common.io.Files; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -283,4 +288,29 @@ public void testBaseHashCode() { assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); } + + @Test + public void testGetServiceAccountProjectId() throws Exception { + File credentialsFile = File.createTempFile("credentials", ".json"); + credentialsFile.deleteOnExit(); + Files.write("{\"project_id\":\"my-project-id\"}".getBytes(), credentialsFile); + + assertEquals("my-project-id", ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); + } + + @Test + public void testGetServiceAccountProjectId_badJson() throws Exception { + File credentialsFile = File.createTempFile("credentials", ".json"); + credentialsFile.deleteOnExit(); + Files.write("asdfghj".getBytes(), credentialsFile); + + assertNull(ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); + } + + @Test + public void testGetServiceAccountProjectId_nonExistentFile() throws Exception { + File credentialsFile = new File("/doesnotexist"); + + assertNull(ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); + } } From 63657d249324009db1135a0cf9d465e79ed4c44d Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Wed, 10 Jan 2018 11:52:56 +1100 Subject: [PATCH 433/663] all: fix copyright header (#2763) Fixes #2758. Change the copyright header of all manually-written files to the recommended format. The copyright year is not changed. Autogenerated files should be updated by the code generator. Created by command below: ```shell find -name '*.java' | xargs grep -FL 'Generated("by GAPIC' | xargs fr -f 'Copyright (\d\d\d\d).*' -t 'Copyright $1 Google LLC'` ``` --- .../java/com/google/cloud/grpc/BaseGrpcServiceException.java | 2 +- .../main/java/com/google/cloud/grpc/GrpcTransportOptions.java | 2 +- .../com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java | 2 +- .../java/com/google/cloud/grpc/GrpcTransportOptionsTest.java | 2 +- .../java/com/google/cloud/http/BaseHttpServiceException.java | 2 +- .../main/java/com/google/cloud/http/HttpTransportOptions.java | 2 +- .../com/google/cloud/http/BaseHttpServiceExceptionTest.java | 2 +- .../java/com/google/cloud/http/HttpTransportOptionsTest.java | 2 +- .../src/main/java/com/google/cloud/AsyncPageImpl.java | 2 +- .../src/main/java/com/google/cloud/BaseService.java | 2 +- .../src/main/java/com/google/cloud/BaseServiceException.java | 2 +- .../src/main/java/com/google/cloud/BaseWriteChannel.java | 2 +- .../src/main/java/com/google/cloud/BatchResult.java | 2 +- google-cloud-core/src/main/java/com/google/cloud/ByteArray.java | 2 +- google-cloud-core/src/main/java/com/google/cloud/Date.java | 2 +- .../src/main/java/com/google/cloud/ExceptionHandler.java | 2 +- .../src/main/java/com/google/cloud/FieldSelector.java | 2 +- .../src/main/java/com/google/cloud/GcpLaunchStage.java | 2 +- google-cloud-core/src/main/java/com/google/cloud/Identity.java | 2 +- .../src/main/java/com/google/cloud/MetadataConfig.java | 2 +- .../src/main/java/com/google/cloud/MonitoredResource.java | 2 +- .../main/java/com/google/cloud/MonitoredResourceDescriptor.java | 2 +- .../src/main/java/com/google/cloud/NoCredentials.java | 2 +- google-cloud-core/src/main/java/com/google/cloud/PageImpl.java | 2 +- .../src/main/java/com/google/cloud/PlatformInformation.java | 2 +- google-cloud-core/src/main/java/com/google/cloud/Policy.java | 2 +- .../src/main/java/com/google/cloud/ReadChannel.java | 2 +- .../src/main/java/com/google/cloud/Restorable.java | 2 +- .../src/main/java/com/google/cloud/RestorableState.java | 2 +- .../src/main/java/com/google/cloud/RetryHelper.java | 2 +- .../src/main/java/com/google/cloud/RetryOption.java | 2 +- google-cloud-core/src/main/java/com/google/cloud/Role.java | 2 +- google-cloud-core/src/main/java/com/google/cloud/Service.java | 2 +- .../src/main/java/com/google/cloud/ServiceDefaults.java | 2 +- .../src/main/java/com/google/cloud/ServiceFactory.java | 2 +- .../src/main/java/com/google/cloud/ServiceOptions.java | 2 +- .../src/main/java/com/google/cloud/ServiceRpc.java | 2 +- .../src/main/java/com/google/cloud/StringEnumType.java | 2 +- .../src/main/java/com/google/cloud/StringEnumValue.java | 2 +- google-cloud-core/src/main/java/com/google/cloud/Timestamp.java | 2 +- .../src/main/java/com/google/cloud/TransportOptions.java | 2 +- google-cloud-core/src/main/java/com/google/cloud/Tuple.java | 2 +- .../src/main/java/com/google/cloud/WriteChannel.java | 2 +- .../src/main/java/com/google/cloud/package-info.java | 2 +- .../src/main/java/com/google/cloud/spi/ServiceRpcFactory.java | 2 +- .../main/java/com/google/cloud/testing/BaseEmulatorHelper.java | 2 +- .../com/google/cloud/testing/BlockingProcessStreamReader.java | 2 +- .../src/main/java/com/google/cloud/testing/CommandWrapper.java | 2 +- .../src/main/java/com/google/cloud/testing/Version.java | 2 +- .../src/test/java/com/google/cloud/AsyncPageImplTest.java | 2 +- .../src/test/java/com/google/cloud/BaseSerializationTest.java | 2 +- .../test/java/com/google/cloud/BaseServiceExceptionTest.java | 2 +- .../src/test/java/com/google/cloud/BaseWriteChannelTest.java | 2 +- .../src/test/java/com/google/cloud/BatchResultTest.java | 2 +- .../src/test/java/com/google/cloud/ByteArrayTest.java | 2 +- google-cloud-core/src/test/java/com/google/cloud/DateTest.java | 2 +- .../src/test/java/com/google/cloud/ExceptionHandlerTest.java | 2 +- .../src/test/java/com/google/cloud/FieldSelectorHelperTest.java | 2 +- .../src/test/java/com/google/cloud/IdentityTest.java | 2 +- .../java/com/google/cloud/MonitoredResourceDescriptorTest.java | 2 +- .../src/test/java/com/google/cloud/MonitoredResourceTest.java | 2 +- .../src/test/java/com/google/cloud/PageImplTest.java | 2 +- .../src/test/java/com/google/cloud/PolicyTest.java | 2 +- .../src/test/java/com/google/cloud/RetryOptionTest.java | 2 +- google-cloud-core/src/test/java/com/google/cloud/RoleTest.java | 2 +- .../src/test/java/com/google/cloud/SerializationTest.java | 2 +- .../src/test/java/com/google/cloud/ServiceOptionsTest.java | 2 +- .../src/test/java/com/google/cloud/StringEnumTest.java | 2 +- .../src/test/java/com/google/cloud/TimestampTest.java | 2 +- .../java/com/google/cloud/testing/BaseEmulatorHelperTest.java | 2 +- .../google/cloud/testing/BlockingProcessStreamReaderTest.java | 2 +- .../test/java/com/google/cloud/testing/CommandWrapperTest.java | 2 +- .../src/test/java/com/google/cloud/testing/VersionTest.java | 2 +- 73 files changed, 73 insertions(+), 73 deletions(-) diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java index e1516c01ee..bf7581ec41 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java index aa727f8d0b..e8a3bf0a55 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java index 8a95dfc55c..37acc1cf84 100644 --- a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java index 7aff66b2d6..8d60ef3f68 100644 --- a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java index bc79026185..5ece1a7101 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java index 2ab57195d4..6b7ec6ed05 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java index 0031f32e36..52d17456ea 100644 --- a/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java index b0fec9185e..100d50f0ef 100644 --- a/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index 643fe0b21d..3acd0170bb 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java index de05bfb22b..7db43727ba 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index 10625dd1c0..470c2cf9a8 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index b5f6394a2f..15f93447b2 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java b/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java index 93f745efc8..ab967e5770 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java index 37c2e79188..1d673770ce 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/Date.java b/google-cloud-core/src/main/java/com/google/cloud/Date.java index 8f43be831e..044a7ca72b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Date.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Date.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java index 70d6cd49bb..921e97eb36 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java index 24706b52e5..0444bc476f 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java +++ b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java b/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java index af4b951f34..d3f127f0f6 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/Identity.java b/google-cloud-core/src/main/java/com/google/cloud/Identity.java index a548347654..68a8a5a7de 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Identity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java index e6f93490f0..1bac5b9b28 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java index 052a773560..da9007eff0 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java index e7789d31af..d0301afb82 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java b/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java index 3172609e25..e9ed09f25d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java +++ b/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java index b7309aab5d..c95b6b62b3 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java b/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java index 272fda0293..467f19f4db 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java +++ b/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/Policy.java b/google-cloud-core/src/main/java/com/google/cloud/Policy.java index 9c4282d14a..474e19fc2e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Policy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Policy.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java index aa04baaab1..dc30ae67d0 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/Restorable.java b/google-cloud-core/src/main/java/com/google/cloud/Restorable.java index e2a515c786..d4b961d0a5 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Restorable.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Restorable.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/RestorableState.java b/google-cloud-core/src/main/java/com/google/cloud/RestorableState.java index 4874756527..8e539812c8 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RestorableState.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RestorableState.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index 34505f6d7c..dd6e4c6926 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java b/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java index 09bfa4b5de..fb5c0e8b4a 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/Role.java b/google-cloud-core/src/main/java/com/google/cloud/Role.java index e7742b2b93..fd762228d0 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Role.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Role.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/Service.java b/google-cloud-core/src/main/java/com/google/cloud/Service.java index 44a9f5372d..bfacabdf7f 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Service.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Service.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java index 6918545774..19988fd2ae 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java index bb06127c77..95eaeb44c6 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index cca3518c29..51f5a52f26 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java index 554e33271a..6db7d6f9db 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java b/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java index 5d5e11dbc4..ee54b3acdc 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java +++ b/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java index f027fda5b3..9bfe3df815 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java +++ b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java index bbad6abc64..456877bd27 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java index 84a6001f3d..3626db0e37 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/Tuple.java b/google-cloud-core/src/main/java/com/google/cloud/Tuple.java index 1536a5d271..c9d2b9bc25 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Tuple.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Tuple.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java index 172e4b03bf..ff065266c8 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/package-info.java b/google-cloud-core/src/main/java/com/google/cloud/package-info.java index 50a9efa045..d1212ad6bb 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/package-info.java +++ b/google-cloud-core/src/main/java/com/google/cloud/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java b/google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java index 4dcf540253..bd27986e1d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java +++ b/google-cloud-core/src/main/java/com/google/cloud/spi/ServiceRpcFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index c84980700d..b8f7be4487 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java index f4e69b9b6e..6db3169ab0 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java index eaafca7939..7158c23b64 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java b/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java index bab865eee2..c069bd99e4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java index 50f19725c8..f871ab395a 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java index 57603b9026..84db30197b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index 80476fdb03..5c5773d26f 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java index 1baae9a7e7..03dd66624c 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java b/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java index 3ce49a8e6f..001bba9834 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java b/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java index 0adf2fe8be..c3433016c7 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java index 30a872491a..3c2817a92c 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java index 0a704fccf1..c668df83bd 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java index d95200a1c7..2048a54539 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java index 0063bdb04d..e4227019b3 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java index e380eab471..16c2924c84 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java index 324ed740e4..72c6a45dc0 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java index 2193981ae8..47d434ec2a 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java b/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java index cc334ec732..48c8bbbc08 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java index 26daff4113..4ad000bb78 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java index 75df1d301d..18cb039f1a 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index c76a7f9dc2..62030b168f 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 6bd613d6cf..7afcb7f581 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java index 613f3676cc..362ef4529c 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java index 6aaf048937..2aa07999c8 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java index b4c334762b..e8f5ed565f 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java index 1b22c9f3ff..a2c854ffb9 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java index cfea5a03dd..51f38e70db 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java index 163cf3c3fd..f55659a030 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2016 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 73394526f86e3f17dc136178c25bb23de6e18429 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 17 Jan 2018 15:26:06 -0800 Subject: [PATCH 434/663] Bumping to 1.15.0/0.33.0 for release --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4664c9ebc8..e94773a725 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.14.1-SNAPSHOT + 1.15.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.32.1-alpha-SNAPSHOT + 0.33.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 29cb2d349f..f3fe2f0a79 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.14.1-SNAPSHOT + 1.15.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.32.1-alpha-SNAPSHOT + 0.33.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 8b7858b9a6..b30d622f54 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.14.0 + 1.15.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.14.0' +compile 'com.google.cloud:google-cloud-core:1.15.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.14.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.15.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b8ba2578dc..5d124f34a7 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.14.1-SNAPSHOT + 1.15.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.32.1-alpha-SNAPSHOT + 0.33.0-alpha google-cloud-core From 3c18682f4bf48867bcfd5a43698ca27555b50799 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 17 Jan 2018 17:13:33 -0800 Subject: [PATCH 435/663] Bumping to next snapshot versions (#2789) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index e94773a725..0eda6000c7 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.15.0 + 1.15.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.33.0-alpha + 0.33.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index f3fe2f0a79..e056872386 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.15.0 + 1.15.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.33.0-alpha + 0.33.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 5d124f34a7..948b7bae3d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.15.0 + 1.15.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.33.0-alpha + 0.33.1-alpha-SNAPSHOT google-cloud-core From 4acfa49419942be729f9c2ca30ec1f27ed9b9a04 Mon Sep 17 00:00:00 2001 From: Hanzhen Yi <33737743+hzyi-google@users.noreply.github.com> Date: Thu, 1 Feb 2018 09:17:58 -0800 Subject: [PATCH 436/663] Validate project-id returned from metadata server (#2822) * Validate project-id returned from metadata server to handle cases in which a descriptive failure html page is returned instead of the projectid itself from server when projects are not running in google cloud machines. * update comments * Validate project-id returned from metadata server to handle cases in which a descriptive failure html page is returned instead of the projectid itself from server when projects are not running in google cloud machines. * update comments * fix code review problems * Fix code review problems * fix code review problems * fix useless parentheses --- .../java/com/google/cloud/ServiceOptions.java | 26 ++++++++++++++++++- .../com/google/cloud/ServiceOptionsTest.java | 10 +++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 51f5a52f26..d57c24bc2a 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -452,7 +452,8 @@ private static String getAppEngineProjectIdFromMetadataServer() throws IOExcepti .setReadTimeout(500) .setHeaders(new HttpHeaders().set("Metadata-Flavor", "Google")); HttpResponse response = request.execute(); - return response.parseAsString(); + String projectId = response.parseAsString(); + return projectId != null && isValidProjectId(projectId)? projectId : null; } protected static String getServiceAccountProjectId() { @@ -476,6 +477,29 @@ static String getServiceAccountProjectId(String credentialsPath) { return project; } + /* + * Returns true if the projectId is valid. This method checks whether the projectId + * contains only lowercase letters, digits and hyphens, starts with a lowercase letter + * and does not end with a hyphen, but does not check the length of projectId. This + * method is primarily used to protect against DNS hijacking. + */ + static boolean isValidProjectId(String projectId) { + for (char c : projectId.toCharArray()) { + if (!isLowerCase(c) && !isDigit(c) && c != '-') { + return false; + } + } + return projectId.length() > 0 && isLowerCase(projectId.charAt(0)) + && !projectId.endsWith("-"); + } + + private static boolean isLowerCase(char c) { + return c >= 'a' && c <= 'z'; + } + + private static boolean isDigit(char c) { + return c >= '0' && c <= '9'; + } /** * Returns a Service object for the current service. For instance, when using Google Cloud diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 7afcb7f581..ce72245d9e 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static com.google.common.truth.Truth.assertThat; import com.google.api.core.ApiClock; import com.google.api.core.CurrentMillisClock; @@ -313,4 +314,13 @@ public void testGetServiceAccountProjectId_nonExistentFile() throws Exception { assertNull(ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); } + + @Test + public void testValidateProjectId() throws Exception { + assertThat(ServiceOptions.isValidProjectId("abc-123")).isTrue(); + assertThat(ServiceOptions.isValidProjectId("abc-123-ab")).isTrue(); + assertThat(ServiceOptions.isValidProjectId("abc=123")).isFalse(); + assertThat(ServiceOptions.isValidProjectId("abc123-")).isFalse(); + assertThat(ServiceOptions.isValidProjectId("1abc-23")).isFalse(); + } } From df24825cf4e928242a7884214de7fcc20ce49448 Mon Sep 17 00:00:00 2001 From: Hanzhen Yi <33737743+hzyi-google@users.noreply.github.com> Date: Thu, 1 Feb 2018 13:42:42 -0800 Subject: [PATCH 437/663] Revert "Validate project-id returned from metadata server (#2822)" (#2833) This reverts commit 536af840f93622a8743d7c129104e72909aeab0a. --- .../java/com/google/cloud/ServiceOptions.java | 26 +------------------ .../com/google/cloud/ServiceOptionsTest.java | 10 ------- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index d57c24bc2a..51f5a52f26 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -452,8 +452,7 @@ private static String getAppEngineProjectIdFromMetadataServer() throws IOExcepti .setReadTimeout(500) .setHeaders(new HttpHeaders().set("Metadata-Flavor", "Google")); HttpResponse response = request.execute(); - String projectId = response.parseAsString(); - return projectId != null && isValidProjectId(projectId)? projectId : null; + return response.parseAsString(); } protected static String getServiceAccountProjectId() { @@ -477,29 +476,6 @@ static String getServiceAccountProjectId(String credentialsPath) { return project; } - /* - * Returns true if the projectId is valid. This method checks whether the projectId - * contains only lowercase letters, digits and hyphens, starts with a lowercase letter - * and does not end with a hyphen, but does not check the length of projectId. This - * method is primarily used to protect against DNS hijacking. - */ - static boolean isValidProjectId(String projectId) { - for (char c : projectId.toCharArray()) { - if (!isLowerCase(c) && !isDigit(c) && c != '-') { - return false; - } - } - return projectId.length() > 0 && isLowerCase(projectId.charAt(0)) - && !projectId.endsWith("-"); - } - - private static boolean isLowerCase(char c) { - return c >= 'a' && c <= 'z'; - } - - private static boolean isDigit(char c) { - return c >= '0' && c <= '9'; - } /** * Returns a Service object for the current service. For instance, when using Google Cloud diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index ce72245d9e..7afcb7f581 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static com.google.common.truth.Truth.assertThat; import com.google.api.core.ApiClock; import com.google.api.core.CurrentMillisClock; @@ -314,13 +313,4 @@ public void testGetServiceAccountProjectId_nonExistentFile() throws Exception { assertNull(ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); } - - @Test - public void testValidateProjectId() throws Exception { - assertThat(ServiceOptions.isValidProjectId("abc-123")).isTrue(); - assertThat(ServiceOptions.isValidProjectId("abc-123-ab")).isTrue(); - assertThat(ServiceOptions.isValidProjectId("abc=123")).isFalse(); - assertThat(ServiceOptions.isValidProjectId("abc123-")).isFalse(); - assertThat(ServiceOptions.isValidProjectId("1abc-23")).isFalse(); - } } From 789b4dc75353c8e77fc14bce9b12092aac910b1b Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 5 Feb 2018 11:40:50 -0800 Subject: [PATCH 438/663] bump version to 0.34.0/0.16.0 for release (#2856) * bump version to 0.34.0/0.16.0 for release * bump bom in pom --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0eda6000c7..f205d8dd18 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.15.1-SNAPSHOT + 1.16.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.33.1-alpha-SNAPSHOT + 0.34.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index e056872386..1cca289214 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.15.1-SNAPSHOT + 1.16.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.33.1-alpha-SNAPSHOT + 0.34.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index b30d622f54..e70bc46c4f 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.15.0 + 1.16.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.15.0' +compile 'com.google.cloud:google-cloud-core:1.16.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.15.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.16.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 948b7bae3d..c4d5a8a60c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.15.1-SNAPSHOT + 1.16.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.33.1-alpha-SNAPSHOT + 0.34.0-alpha google-cloud-core From c195abe24e00696be81ee495287284c8ac742675 Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 5 Feb 2018 13:08:51 -0800 Subject: [PATCH 439/663] bump version for dev (#2859) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index f205d8dd18..5f135de5b7 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.16.0 + 1.16.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.34.0-alpha + 0.34.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 1cca289214..9342f9225e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.16.0 + 1.16.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.34.0-alpha + 0.34.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c4d5a8a60c..a9f367796a 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.16.0 + 1.16.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.34.0-alpha + 0.34.1-alpha-SNAPSHOT google-cloud-core From d378149e200c97292cfaf65a862eb5a9f3eef6b8 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Tue, 6 Feb 2018 09:46:28 +1100 Subject: [PATCH 440/663] use GAE_RUNTIME to detect java version (#2837) Fixes #2805. --- .../com/google/cloud/PlatformInformation.java | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java b/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java index 467f19f4db..8c77bb9e91 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java +++ b/google-cloud-core/src/main/java/com/google/cloud/PlatformInformation.java @@ -20,35 +20,15 @@ @InternalApi("This class should only be used within google-cloud-java") public final class PlatformInformation { - public static final String SPECIFICATION_VERSION = - System.getProperty("java.specification.version"); - public static final String GAE_RUNTIME_VERSION = - System.getProperty("com.google.appengine.runtime.version"); - public static final String RUNTIME_JETTY_LOGGER = - System.getProperty("org.eclipse.jetty.util.log.class"); - public static final String JETTY_LOGGER_ON_GAE8_PROD = - "com.google.apphosting.runtime.jetty9.JettyLogger"; - public static final String JETTY_LOGGER_ON_GAE8_DEVSERVER = - " com.google.appengine.development.jetty9.JettyLogger"; //note the leading space + public static final String GAE_RUNTIME = System.getenv("GAE_RUNTIME"); private PlatformInformation() {} - public static boolean isOnGAE() { - return GAE_RUNTIME_VERSION != null; - } - public static boolean isOnGAEStandard7() { - //edge case: when a Java 7 GAE app is deployed to DevServer running on J8, SPECIFICATION_VERSION will be "1.8", - //but RUNTIME_JETTY_LOGGER is unset - return isOnGAE() && SPECIFICATION_VERSION.equals("1.7") - || isOnGAE() && RUNTIME_JETTY_LOGGER == null; + return "java7".equals(GAE_RUNTIME); } public static boolean isOnGAEStandard8() { - return isOnGAE() - && !SPECIFICATION_VERSION.equals("1.7") - && RUNTIME_JETTY_LOGGER != null - && (RUNTIME_JETTY_LOGGER.equals(JETTY_LOGGER_ON_GAE8_DEVSERVER) - || RUNTIME_JETTY_LOGGER.equals(JETTY_LOGGER_ON_GAE8_PROD)); + return "java8".equals(GAE_RUNTIME); } } From f88e8304d08262b777796eeb89507219da543fe6 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Wed, 7 Feb 2018 11:52:18 +1100 Subject: [PATCH 441/663] use grpc-netty-shaded (#2832) Fixes #2813. --- google-cloud-core-grpc/pom.xml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 5f135de5b7..2dbc4efa33 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -18,10 +18,6 @@ google-cloud-core-grpc - - io.netty - netty-tcnative-boringssl-static - com.google.auth google-auth-library-credentials @@ -67,7 +63,7 @@ io.grpc - grpc-netty + grpc-netty-shaded io.grpc From f20200c3dd0e23c60d4a7835fb7ab84cd080a1ba Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 8 Feb 2018 16:12:06 -0800 Subject: [PATCH 442/663] Removing Travis (#2883) --- google-cloud-core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index e70bc46c4f..b67914f38f 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -3,7 +3,7 @@ Google Cloud Java Client -- Core This module provides common functionality required by service-specific modules of this library. -[![Build Status](https://travis-ci.org/GoogleCloudPlatform/google-cloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/google-cloud-java) +[![CircleCI](https://circleci.com/gh/GoogleCloudPlatform/google-cloud-java/tree/master.svg?style=shield)](https://circleci.com/gh/GoogleCloudPlatform/google-cloud-java/tree/master) [![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/google-cloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/google-cloud-java?branch=master) [![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg) [![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) From 3d51035c0d00867a9cac79003824e497ea8e7593 Mon Sep 17 00:00:00 2001 From: Hailong Wen Date: Thu, 8 Feb 2018 20:02:00 -0800 Subject: [PATCH 443/663] Add initial opencensus instrumentation code in Cloud Storage. (#2846) --- google-cloud-core-http/pom.xml | 8 + .../google/cloud/http/CensusHttpModule.java | 167 ++++++++++++++++++ .../cloud/http/CensusHttpModuleTest.java | 159 +++++++++++++++++ 3 files changed, 334 insertions(+) create mode 100644 google-cloud-core-http/src/main/java/com/google/cloud/http/CensusHttpModule.java create mode 100644 google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 9342f9225e..367c2092db 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -123,5 +123,13 @@ guava-testlib test + + io.opencensus + opencensus-api + + + io.opencensus + opencensus-contrib-http-util + diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/CensusHttpModule.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/CensusHttpModule.java new file mode 100644 index 0000000000..0eb882e193 --- /dev/null +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/CensusHttpModule.java @@ -0,0 +1,167 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.http; + +import static com.google.common.base.Preconditions.checkNotNull; +import com.google.api.client.http.HttpExecuteInterceptor; +import com.google.api.client.http.HttpHeaders; +import com.google.api.client.http.HttpRequest; +import com.google.api.client.http.HttpRequestInitializer; +import com.google.common.annotations.VisibleForTesting; +import io.opencensus.contrib.http.util.HttpPropagationUtil; +import io.opencensus.trace.SpanContext; +import io.opencensus.trace.Tracer; +import io.opencensus.trace.propagation.TextFormat; +import java.io.IOException; +import javax.annotation.Nullable; + +/** + * Provides utilities for Open Census to record http stats/trace information and propagate tracing + * context. + */ +public final class CensusHttpModule { + + /** + * OpenCensus tracing component. + * When no OpenCensus implementation is provided, it will return a no-op tracer. + */ + private final Tracer tracer; + + /** + * {@link TextFormat} used in tracing context propagation. + */ + @Nullable + private final TextFormat propagationTextFormat; + + /** + * {@link TextFormat.Setter} for {@link #propagationTextFormat}. + */ + @Nullable + private final TextFormat.Setter propagationTextFormatSetter; + + /** + * Whether spans are stored locally. + */ + private final boolean isRecordEvents; + + /** + * Default HTTP propagation text formatter. + */ + @VisibleForTesting + final static class DefaultPropagationTextFormatSetter extends TextFormat.Setter { + static final TextFormat.Setter INSTANCE = new DefaultPropagationTextFormatSetter(); + + @Override + public void put(HttpHeaders carrier, String key, String value) { + carrier.set(key, value); + } + } + + /** + * An {@link HttpExecuteInterceptor} implementation to inject HTTP request and add getContext + * information before it is executed. + */ + @VisibleForTesting + final class CensusHttpExecuteInterceptor implements HttpExecuteInterceptor { + @Nullable + HttpExecuteInterceptor interceptor; + + CensusHttpExecuteInterceptor(HttpExecuteInterceptor interceptor) { + this.interceptor = interceptor; + } + + @Override + public void intercept(HttpRequest request) throws IOException { + checkNotNull(request); + if (this.interceptor != null) { + this.interceptor.intercept(request); + } + if (propagationTextFormat != null && propagationTextFormatSetter != null) { + SpanContext spanContext = tracer.getCurrentSpan().getContext(); + if (!SpanContext.INVALID.equals(spanContext)) { + propagationTextFormat.inject( + spanContext, request.getHeaders(), propagationTextFormatSetter); + } + } + } + } + + /** + * An {@link HttpRequestInitializer} implementation to set {@link CensusHttpExecuteInterceptor} as + * interceptor. + */ + @VisibleForTesting + final class CensusHttpRequestInitializer implements HttpRequestInitializer { + @Nullable + HttpRequestInitializer initializer; + + CensusHttpRequestInitializer(HttpRequestInitializer initializer) { + this.initializer = initializer; + } + + @Override + public void initialize(HttpRequest request) throws IOException { + checkNotNull(request); + if (this.initializer != null) { + this.initializer.initialize(request); + } + request.setInterceptor(new CensusHttpExecuteInterceptor(request.getInterceptor())); + } + } + + /** + * Creates a {@link CensusHttpModule} with given parameters. + * + * @param tracer the OpenCensus {@code Tracer}. + * @param isRecordEvents whether spans are stored locally. + */ + public CensusHttpModule(Tracer tracer, boolean isRecordEvents) { + checkNotNull(tracer, "tracer"); + this.tracer = tracer; + this.isRecordEvents = isRecordEvents; + this.propagationTextFormat = HttpPropagationUtil.getCloudTraceFormat(); + this.propagationTextFormatSetter = DefaultPropagationTextFormatSetter.INSTANCE; + } + + /** + * Returns the tracing component of OpenCensus. + * + * @return the tracing component of OpenCensus. + */ + public Tracer getTracer() { + return tracer; + } + + /** + * Returns whether spans are stored locally. + * + * @return whether spans are stored locally. + */ + public boolean isRecordEvents() { + return isRecordEvents; + } + + /** + * Returns the {@link HttpExecuteInterceptor} used when initializing the {@link HttpRequest}. + * + * @param initializer the original initializer which will be executed before this initializer. + * @return the {@code HttpExecuteInterceptor}. + */ + public HttpRequestInitializer getHttpRequestInitializer(HttpRequestInitializer initializer) { + return new CensusHttpRequestInitializer(initializer); + } +} diff --git a/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java new file mode 100644 index 0000000000..abc7f7de78 --- /dev/null +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java @@ -0,0 +1,159 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.http; + +import static com.google.common.truth.Truth.assertThat; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.createMockBuilder; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; + +import com.google.api.client.http.HttpExecuteInterceptor; +import com.google.api.client.http.GenericUrl; +import com.google.api.client.http.HttpHeaders; +import com.google.api.client.http.HttpRequest; +import com.google.api.client.http.HttpRequestInitializer; +import com.google.api.client.http.javanet.NetHttpTransport; + +import io.opencensus.common.Scope; +import io.opencensus.trace.Span; +import io.opencensus.trace.SpanContext; +import io.opencensus.trace.SpanId; +import io.opencensus.trace.TraceId; +import io.opencensus.trace.TraceOptions; +import io.opencensus.trace.Tracer; +import io.opencensus.trace.Tracing; +import io.opencensus.trace.propagation.TextFormat; + +import java.io.IOException; +import java.util.EnumSet; +import java.util.Random; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for {@link CensusHttpModule}. */ +@RunWith(JUnit4.class) +public class CensusHttpModuleTest { + + @Rule public final ExpectedException thrown = ExpectedException.none(); + + private final Tracer tracer = Tracing.getTracer(); + private final CensusHttpModule censusHttpModule = new CensusHttpModule(tracer, false); + private HttpRequest httpRequest; + + @Before + public void setUp() throws IOException { + httpRequest = new NetHttpTransport().createRequestFactory().buildRequest( + "GET", new GenericUrl("https://www.google.com"), null); + } + + @Test + public void tracerShouldNotBeNull() { + assertThat(censusHttpModule.getTracer()).isNotNull(); + } + + @Test + public void isRecordEventsShouldBeSet() { + assertThat(censusHttpModule.isRecordEvents()).isEqualTo(false); + } + + @Test + public void getHttpRequestInitializerShouldReturnCorrectClass() { + HttpRequestInitializer initializer = censusHttpModule.getHttpRequestInitializer(null); + assertThat(initializer).isInstanceOf(CensusHttpModule.CensusHttpRequestInitializer.class); + } + + @Test + public void implementationOfDefaultTextFormatSetter() { + String testKey = "testKey"; + String testValue = "testValue"; + TextFormat.Setter setter = + CensusHttpModule.DefaultPropagationTextFormatSetter.INSTANCE; + setter.put(httpRequest.getHeaders(), testKey, testValue); + assertThat(httpRequest.getHeaders().get(testKey)).isEqualTo(testValue); + } + + @Test + public void censusHttpExecuteInterceptorDisallowNullRequest() throws IOException { + HttpExecuteInterceptor interceptor = censusHttpModule.new CensusHttpExecuteInterceptor(null); + thrown.expect(NullPointerException.class); + interceptor.intercept(null); + } + + @Test + public void censusHttpExecuteInterceptorShouldExecuteOriginal() throws IOException { + HttpExecuteInterceptor mockInterceptor = createMock(HttpExecuteInterceptor.class); + HttpExecuteInterceptor censusInterceptor = censusHttpModule.new CensusHttpExecuteInterceptor( + mockInterceptor); + mockInterceptor.intercept(httpRequest); + replay(mockInterceptor); + censusInterceptor.intercept(httpRequest); + verify(mockInterceptor); + } + + @Test + public void censusHttpExecuteInterceptorShouldInjectHeader() throws IOException { + Random random = new Random(); + SpanContext spanContext = SpanContext.create( + TraceId.generateRandomId(random), + SpanId.generateRandomId(random), + TraceOptions.DEFAULT); + Span mockSpan = createMockBuilder(Span.class) + .withConstructor(SpanContext.class, EnumSet.class) + .withArgs(spanContext, null) + .createMock(); + Scope scope = tracer.withSpan(mockSpan); + try { + HttpExecuteInterceptor interceptor = censusHttpModule.new CensusHttpExecuteInterceptor(null); + interceptor.intercept(httpRequest); + assertThat(httpRequest.getHeaders().get("X-Cloud-Trace-Context")).isNotNull(); + } finally { + scope.close(); + } + } + + @Test + public void censusHttpRequestInitializerDisallowNullRequest() throws IOException { + HttpRequestInitializer initializer = censusHttpModule.getHttpRequestInitializer(null); + thrown.expect(NullPointerException.class); + initializer.initialize(null); + } + + @Test + public void censusHttpRequestInitializerShouldExecuteOriginal() throws IOException { + HttpRequestInitializer mockOriginalInitializer = createMock(HttpRequestInitializer.class); + HttpRequestInitializer censusInitializer = censusHttpModule.getHttpRequestInitializer( + mockOriginalInitializer); + mockOriginalInitializer.initialize(httpRequest); + replay(mockOriginalInitializer); + censusInitializer.initialize(httpRequest); + verify(mockOriginalInitializer); + } + + @Test + public void censusHttpRequestInitializerShouldSetInterceptor() throws IOException { + censusHttpModule.getHttpRequestInitializer(null).initialize(httpRequest); + assertThat(httpRequest.getInterceptor()).isInstanceOf( + CensusHttpModule.CensusHttpExecuteInterceptor.class); + } +} From 7e68da63e42b395d5a3eec9b2d43d955f2aabe9c Mon Sep 17 00:00:00 2001 From: Hanzhen Yi <33737743+hzyi-google@users.noreply.github.com> Date: Tue, 13 Feb 2018 15:19:12 -0800 Subject: [PATCH 444/663] Add validation for project-id returned by metadata server (#2868) Validate the project id returned by metadata server by checking the Metadata-Flavor field in the header. --- .../java/com/google/cloud/ServiceOptions.java | 8 ++- .../com/google/cloud/ServiceOptionsTest.java | 49 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 51f5a52f26..950c6fd8e4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -452,7 +452,13 @@ private static String getAppEngineProjectIdFromMetadataServer() throws IOExcepti .setReadTimeout(500) .setHeaders(new HttpHeaders().set("Metadata-Flavor", "Google")); HttpResponse response = request.execute(); - return response.parseAsString(); + return headerContainsMetadataFlavor(response) ? response.parseAsString() : null; + } + + @InternalApi("Visible for testing") + static boolean headerContainsMetadataFlavor(HttpResponse response) { + String metadataFlavorValue = response.getHeaders().getFirstHeaderStringValue("Metadata-Flavor"); + return "Google".equals(metadataFlavorValue); } protected static String getServiceAccountProjectId() { diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 7afcb7f581..49190fc4c2 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -16,6 +16,7 @@ package com.google.cloud; +import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -26,16 +27,29 @@ import com.google.api.core.ApiClock; import com.google.api.core.CurrentMillisClock; +import com.google.api.client.http.HttpResponse; +import com.google.api.client.http.HttpRequest; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.http.LowLevelHttpResponse; +import com.google.api.client.http.LowLevelHttpRequest; +import com.google.api.client.testing.http.HttpTesting; +import com.google.api.client.testing.http.MockHttpTransport; +import com.google.api.client.testing.http.MockLowLevelHttpRequest; +import com.google.api.client.testing.http.MockLowLevelHttpResponse; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; +import java.util.Map; import java.util.Set; import java.util.regex.Pattern; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; import com.google.common.io.Files; import org.junit.Rule; import org.junit.Test; @@ -313,4 +327,39 @@ public void testGetServiceAccountProjectId_nonExistentFile() throws Exception { assertNull(ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); } + + @Test + public void testResponseHeaderContainsMetaDataFlavor() throws Exception { + Multimap headers = ArrayListMultimap.create(); + headers.put("Metadata-Flavor", "Google"); + HttpResponse httpResponse = createHttpResponseWithHeader(headers); + assertThat(ServiceOptions.headerContainsMetadataFlavor(httpResponse)).isTrue(); + } + + @Test + public void testResponseHeaderDoesNotContainMetaDataFlavor() throws Exception { + Multimap headers = ArrayListMultimap.create(); + HttpResponse httpResponse = createHttpResponseWithHeader(headers); + assertThat(ServiceOptions.headerContainsMetadataFlavor(httpResponse)).isFalse(); + } + + private HttpResponse createHttpResponseWithHeader(final Multimap headers) throws Exception { + HttpTransport mockHttpTransport = new MockHttpTransport() { + @Override + public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { + return new MockLowLevelHttpRequest() { + @Override + public LowLevelHttpResponse execute() throws IOException { + MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); + for (Map.Entry entry : headers.entries()) { + response.addHeader(entry.getKey(), entry.getValue()); + } + return response; + } + }; + } + }; + HttpRequest request = mockHttpTransport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL); + return request.execute(); + } } From 9c6a0720fd949f0045808dd3a2aeb6639b1a863a Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Thu, 15 Feb 2018 09:00:42 +1100 Subject: [PATCH 445/663] core: make BaseWriteChannel surprise less (#2900) Fixes #2895. The chunk size should round up, not down. Fixes #2896 by removing flush from capture. It is too surprising that capture might fail. --- .../com/google/cloud/BaseWriteChannel.java | 6 ++--- .../java/com/google/cloud/WriteChannel.java | 4 +--- .../google/cloud/BaseWriteChannelTest.java | 24 +++++++++++-------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index 15f93447b2..1888b2a78c 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -104,8 +104,9 @@ protected int getChunkSize() { @Override public final void setChunkSize(int chunkSize) { - chunkSize = (chunkSize / getMinChunkSize()) * getMinChunkSize(); - this.chunkSize = Math.max(getMinChunkSize(), chunkSize); + int minSize = getMinChunkSize(); + + this.chunkSize = Math.max(minSize, (chunkSize + minSize - 1) / minSize * minSize); } @InternalApi("This class should only be extended within google-cloud-java") @@ -173,7 +174,6 @@ public final void close() throws IOException { public RestorableState capture() { byte[] bufferToSave = null; if (isOpen) { - flush(); bufferToSave = Arrays.copyOf(buffer, limit); } return stateBuilder() diff --git a/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java index ff065266c8..deb57b9259 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java @@ -23,13 +23,11 @@ * A channel for writing data to Google Cloud services. * *

    Implementations of this class may further buffer data internally to reduce remote calls. - * Written data will only be visible after calling {@link #close()}. This interface implements + * Written data might not be visible until calling {@link #close()}. This interface implements * {@link Restorable} to allow saving the writer's state to continue writing afterwards. - *

    */ public interface WriteChannel extends WritableByteChannel, Closeable, Restorable { - /** * Sets the minimum size that will be written by a single RPC. * Written data will be buffered and only flushed upon reaching this size or closing the channel. diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java index 03dd66624c..985310f939 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java @@ -16,6 +16,7 @@ package com.google.cloud; +import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertArrayEquals; @@ -23,18 +24,16 @@ import static org.junit.Assert.assertNull; import com.google.cloud.spi.ServiceRpcFactory; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - import java.io.IOException; import java.io.Serializable; import java.nio.ByteBuffer; import java.nio.channels.ClosedChannelException; import java.util.Arrays; import java.util.Random; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; public class BaseWriteChannelTest { @@ -111,11 +110,16 @@ public void testValidateOpen() throws IOException { @Test public void testChunkSize() { channel.setChunkSize(42); - assertEquals(MIN_CHUNK_SIZE, channel.getChunkSize()); + assertThat(channel.getChunkSize() >= MIN_CHUNK_SIZE).isTrue(); + assertThat(channel.getChunkSize() % MIN_CHUNK_SIZE).isEqualTo(0); + channel.setChunkSize(2 * MIN_CHUNK_SIZE); - assertEquals(2 * MIN_CHUNK_SIZE, channel.getChunkSize()); - channel.setChunkSize(512 * 1025); - assertEquals(2 * MIN_CHUNK_SIZE, channel.getChunkSize()); + assertThat(channel.getChunkSize() >= MIN_CHUNK_SIZE).isTrue(); + assertThat(channel.getChunkSize() % MIN_CHUNK_SIZE).isEqualTo(0); + + channel.setChunkSize(2 * MIN_CHUNK_SIZE + 1); + assertThat(channel.getChunkSize() >= MIN_CHUNK_SIZE).isTrue(); + assertThat(channel.getChunkSize() % MIN_CHUNK_SIZE).isEqualTo(0); } @Test From 7301b2ccb1d566d3ff6ed3539d52ca344fb53617 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 16 Feb 2018 13:44:52 +1100 Subject: [PATCH 446/663] core: allow custom roles (#2863) Role previously mandated that all role strings starts with "role/". If the given string doesn't start with the prefix, Role prepends it. This is incorrect, since custom roles have format "projects/X/roles/Y". This PR makes Role a little smarter at prepending: we only prepend if the given string contains no slash; this keeps the previously-valid use valid. Fixes #2687. --- .../src/main/java/com/google/cloud/Role.java | 15 ++++++++--- .../test/java/com/google/cloud/RoleTest.java | 25 +++++++++++-------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Role.java b/google-cloud-core/src/main/java/com/google/cloud/Role.java index fd762228d0..6c85c880df 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Role.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Role.java @@ -82,15 +82,22 @@ public static Role owner() { /** * Returns a new role given its string value. * - * @param value the string value for the role, for example, {@code "roles/viewer"}, - * {@code "roles/editor"}, or {@code "roles/owner"}. If this value does not start with the - * role prefix {@code roles/}, the prefix is prepended. + *

    If the value contains no slash character ({@code '/'}), the prefix {@code "roles/""} is + * prepended. This slightly simplifies usage for . For custom roles, call this + * method with the fully-qualified name, eg {@code "projects/XXX/roles/YYY"}. + * + * @param value the string value for the role * @see Viewing the Grantable * Roles on Resources */ public static Role of(String value) { checkNotNull(value); - return new Role(value.startsWith(ROLE_PREFIX) ? value : ROLE_PREFIX + value); + if (!value.contains("/")) { + value = ROLE_PREFIX + value; + } + return new Role(value); } @Override diff --git a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java index 18cb039f1a..0101a5b6e2 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java @@ -16,7 +16,7 @@ package com.google.cloud; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertThat; import org.junit.Test; @@ -28,28 +28,31 @@ public class RoleTest { @Test public void testOf() { - assertEquals("roles/viewer", VIEWER.getValue()); - assertEquals("roles/editor", EDITOR.getValue()); - assertEquals("roles/owner", OWNER.getValue()); + assertThat(VIEWER.getValue()).isEqualTo("roles/viewer"); + assertThat(EDITOR.getValue()).isEqualTo("roles/editor"); + assertThat(OWNER.getValue()).isEqualTo("roles/owner"); compareRoles(VIEWER, Role.of("roles/viewer")); compareRoles(EDITOR, Role.of("roles/editor")); compareRoles(OWNER, Role.of("roles/owner")); + + String customRole = "projects/foo/roles/bar"; + assertThat(Role.of(customRole).getValue()).isEqualTo(customRole); } @Test public void testViewer() { - assertEquals("roles/viewer", Role.viewer().getValue()); + assertThat(Role.viewer().getValue()).isEqualTo("roles/viewer"); } @Test public void testEditor() { - assertEquals("roles/editor", Role.editor().getValue()); + assertThat(Role.editor().getValue()).isEqualTo("roles/editor"); } @Test public void testOwner() { - assertEquals("roles/owner", Role.owner().getValue()); + assertThat(Role.owner().getValue()).isEqualTo("roles/owner"); } @Test(expected = NullPointerException.class) @@ -58,9 +61,9 @@ public void testOfNullValue() { } private void compareRoles(Role expected, Role actual) { - assertEquals(expected, actual); - assertEquals(expected.getValue(), actual.getValue()); - assertEquals(expected.hashCode(), actual.hashCode()); - assertEquals(expected.toString(), actual.toString()); + assertThat(actual).isEqualTo(expected); + assertThat(actual.getValue()).isEqualTo(expected.getValue()); + assertThat(actual.hashCode()).isEqualTo(expected.hashCode()); + assertThat(actual.toString()).isEqualTo(expected.toString()); } } From f9a4e54036c9c8d50b30a8ae27f6fbbecf9f39d8 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Wed, 21 Feb 2018 09:36:05 -0800 Subject: [PATCH 447/663] Release 0.35.0-alpha, 0.35.0-beta and 1.17.0 (#2929) Also: fix javadoc issue in Role.java file; fix s/google-cloud-bom.version/bom.version to fix the version update script; fix root README.md version from 0.33.0 (should be 0.34.0) directly to 0.35.0); fix javadoc issue in LocalStorageHelper.java. --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- google-cloud-core/src/main/java/com/google/cloud/Role.java | 7 +++---- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 2dbc4efa33..94cac3168e 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.16.1-SNAPSHOT + 1.17.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.34.1-alpha-SNAPSHOT + 0.35.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 367c2092db..b28af24c50 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.16.1-SNAPSHOT + 1.17.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.34.1-alpha-SNAPSHOT + 0.35.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index b67914f38f..0f7f54fd0f 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.16.0 + 1.17.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.16.0' +compile 'com.google.cloud:google-cloud-core:1.17.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.16.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.17.0" ``` Troubleshooting diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a9f367796a..5becde8bfa 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.16.1-SNAPSHOT + 1.17.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.34.1-alpha-SNAPSHOT + 0.35.0-alpha google-cloud-core diff --git a/google-cloud-core/src/main/java/com/google/cloud/Role.java b/google-cloud-core/src/main/java/com/google/cloud/Role.java index 6c85c880df..e75dd5f8f2 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Role.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Role.java @@ -40,10 +40,9 @@ private Role(String value) { this.value = value; } - /** - * Returns the string identifier for this role. For example, {@code "roles/viewer"}, - * {@code "roles/editor"}, or {@code "roles/owner"}. + * Returns the string identifier for this role. For example, {@code "roles/viewer"}, {@code + * "roles/editor"}, or {@code "roles/owner"}. */ public String getValue() { return value; @@ -84,7 +83,7 @@ public static Role owner() { * *

    If the value contains no slash character ({@code '/'}), the prefix {@code "roles/""} is * prepended. This slightly simplifies usage for . For predefined roles. For custom roles, call this * method with the fully-qualified name, eg {@code "projects/XXX/roles/YYY"}. * From f499235507e175749b0f5ad71c5cb00475392b64 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Wed, 21 Feb 2018 13:09:13 -0800 Subject: [PATCH 448/663] Bump versions to 0.35.1-alpha-SNAPSHOT, 0.35.1-beta-SNAPSHOT and 1.17.1-SNAPSHOT for development (#2933) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 94cac3168e..ea7b652dac 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.17.0 + 1.17.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.35.0-alpha + 0.35.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index b28af24c50..07b11c427b 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.17.0 + 1.17.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.35.0-alpha + 0.35.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 5becde8bfa..9f411b99b3 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.17.0 + 1.17.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.35.0-alpha + 0.35.1-alpha-SNAPSHOT google-cloud-core From c4ff24d0a4c3c0f0cef5a2104daa055a18ed68ca Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 23 Feb 2018 11:42:49 +1100 Subject: [PATCH 449/663] logging: log more kubernetes properties (#2937) Updates #2912. --- .../src/main/java/com/google/cloud/MetadataConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java index 1bac5b9b28..a285462165 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -54,7 +54,7 @@ public static String getInstanceId() { } public static String getClusterName() { - return getAttribute("instance/cluster-name"); + return getAttribute("instance/attributes/cluster-name"); } private static String getAttribute(String attributeName) { From da7b8926e6dae64bed0e2c813b223462624585a2 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 26 Feb 2018 10:18:31 -0800 Subject: [PATCH 450/663] Adding new version update scripts (#2947) versions.txt has both the last-released version (in maven) and the current version (either about-to-be-released or the snapshot version). There are two scripts: bump_versions.py: Bumps the versions stored in version.txt replace_versions.py: Idempotent script which replaces the versions everywhere they are tagged Users can choose to manually update versions.txt if they so choose and skip the bump_versions.py script. --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 3 +++ google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ea7b652dac..8b5bb1e584 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.17.1-SNAPSHOT + 1.17.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.35.1-alpha-SNAPSHOT + 0.35.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 07b11c427b..c732b756df 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.17.1-SNAPSHOT + 1.17.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.35.1-alpha-SNAPSHOT + 0.35.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 0f7f54fd0f..1a6233461f 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -14,6 +14,8 @@ This module provides common functionality required by service-specific modules o Quickstart ---------- + +[//]: # ({x-version-update-start:google-cloud-core:released}) If you are using Maven, add this to your pom.xml file ```xml @@ -30,6 +32,7 @@ If you are using SBT, add this to your dependencies ```Scala libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.17.0" ``` +[//]: # ({x-version-update-end}) Troubleshooting --------------- diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9f411b99b3..3bee945694 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.17.1-SNAPSHOT + 1.17.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.35.1-alpha-SNAPSHOT + 0.35.1-alpha-SNAPSHOT google-cloud-core From 550d6eb82193b7f557275fffdb696cf6641af094 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 27 Feb 2018 09:50:11 -0800 Subject: [PATCH 451/663] Version bump to 0.36.0 (#2967) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 8b5bb1e584..817afa2794 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.17.1-SNAPSHOT + 1.18.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.35.1-alpha-SNAPSHOT + 0.36.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index c732b756df..1fdc9ad06d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.17.1-SNAPSHOT + 1.18.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.35.1-alpha-SNAPSHOT + 0.36.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 1a6233461f..80ebe54d66 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.17.0 + 1.18.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.17.0' +compile 'com.google.cloud:google-cloud-core:1.18.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.17.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.18.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3bee945694..c344e87bb0 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.17.1-SNAPSHOT + 1.18.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.35.1-alpha-SNAPSHOT + 0.36.0-alpha google-cloud-core From 26dbfefc2ef9c5f372647abc647f2477cbb166d0 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 27 Feb 2018 10:07:02 -0800 Subject: [PATCH 452/663] Version bump to snapshot (#2966) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 817afa2794..fb2a3d175a 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.18.0 + 1.18.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.36.0-alpha + 0.36.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 1fdc9ad06d..84c0c9a088 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.18.0 + 1.18.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.36.0-alpha + 0.36.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c344e87bb0..774e180b40 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.18.0 + 1.18.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.36.0-alpha + 0.36.1-alpha-SNAPSHOT google-cloud-core From bbd7af9f99444cd4d9a02631c02dfdc6d30a39f1 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 27 Feb 2018 11:04:55 -0800 Subject: [PATCH 453/663] bump version to 0.37.0 (#2969) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index fb2a3d175a..44ed942b9c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.18.1-SNAPSHOT + 1.19.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.36.1-alpha-SNAPSHOT + 0.37.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 84c0c9a088..552f377439 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.18.1-SNAPSHOT + 1.19.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.36.1-alpha-SNAPSHOT + 0.37.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 80ebe54d66..3e34c6481a 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.18.0 + 1.19.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.18.0' +compile 'com.google.cloud:google-cloud-core:1.19.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.18.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.19.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 774e180b40..5f6e22ad8a 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.18.1-SNAPSHOT + 1.19.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.36.1-alpha-SNAPSHOT + 0.37.0-alpha google-cloud-core From c3cd06f753784ea29e24680d4882713bcc374b6f Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 27 Feb 2018 11:29:42 -0800 Subject: [PATCH 454/663] Version bump to snapshot (#2970) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 44ed942b9c..ddd53cdba1 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.19.0 + 1.19.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.37.0-alpha + 0.37.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 552f377439..71bf31f0cb 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.19.0 + 1.19.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.37.0-alpha + 0.37.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 5f6e22ad8a..0d26bce51a 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.19.0 + 1.19.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.37.0-alpha + 0.37.1-alpha-SNAPSHOT google-cloud-core From 9a7123fc6739ee2403285246bedf68e67df28f3d Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 6 Mar 2018 13:34:25 -0800 Subject: [PATCH 455/663] releasing 0.38.0 (#3004) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ddd53cdba1..f85ad0ae7c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.19.1-SNAPSHOT + 1.20.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.37.1-alpha-SNAPSHOT + 0.38.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 71bf31f0cb..90ea7c7560 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.19.1-SNAPSHOT + 1.20.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.37.1-alpha-SNAPSHOT + 0.38.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 3e34c6481a..0e065c058d 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.19.0 + 1.20.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.19.0' +compile 'com.google.cloud:google-cloud-core:1.20.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.19.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.20.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 0d26bce51a..4b7779cb82 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.19.1-SNAPSHOT + 1.20.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.37.1-alpha-SNAPSHOT + 0.38.0-alpha google-cloud-core From 6941a2edaba06907bfb8dc9f8187c5c63164c5e4 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 6 Mar 2018 13:47:43 -0800 Subject: [PATCH 456/663] Bump versions to snapshot (#3005) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index f85ad0ae7c..93fa3d4e1d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.20.0 + 1.20.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.0-alpha + 0.38.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 90ea7c7560..ae11557bad 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.20.0 + 1.20.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.0-alpha + 0.38.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4b7779cb82..7dc12a5821 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.20.0 + 1.20.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.0-alpha + 0.38.1-alpha-SNAPSHOT google-cloud-core From d4dc9362b4e3f8306bdfb68cd89f7723ac971f4f Mon Sep 17 00:00:00 2001 From: neozwu Date: Wed, 14 Mar 2018 13:36:03 -0700 Subject: [PATCH 457/663] release 0.39.0 (#3042) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 93fa3d4e1d..dd42200478 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.20.1-SNAPSHOT + 1.21.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.39.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index ae11557bad..20243be1d0 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.20.1-SNAPSHOT + 1.21.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.39.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 0e065c058d..26bd7e7173 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.20.0 + 1.21.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.20.0' +compile 'com.google.cloud:google-cloud-core:1.21.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.20.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.21.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7dc12a5821..d43f620ccb 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.20.1-SNAPSHOT + 1.21.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.39.0-alpha google-cloud-core From 6980770f1775cc444df213f660b796552b68ceb2 Mon Sep 17 00:00:00 2001 From: neozwu Date: Wed, 14 Mar 2018 16:08:32 -0700 Subject: [PATCH 458/663] bump version for development (#3045) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index dd42200478..788a7b4d49 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.21.0 + 1.21.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.39.0-alpha + 0.39.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 20243be1d0..7f5bf510f5 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.21.0 + 1.21.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.39.0-alpha + 0.39.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d43f620ccb..a6ccc7fa4c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.21.0 + 1.21.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.39.0-alpha + 0.39.1-alpha-SNAPSHOT google-cloud-core From 1a87191bd9df90a1c231cd3fda798b28dd4b354e Mon Sep 17 00:00:00 2001 From: Neo Wu Date: Fri, 16 Mar 2018 16:12:00 -0700 Subject: [PATCH 459/663] Release 0.40.0 --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 788a7b4d49..0707eb3714 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.21.1-SNAPSHOT + 1.22.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.39.1-alpha-SNAPSHOT + 0.40.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 7f5bf510f5..4b25c65bd2 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.21.1-SNAPSHOT + 1.22.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.39.1-alpha-SNAPSHOT + 0.40.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 26bd7e7173..92e07c17cb 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.21.0 + 1.22.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.21.0' +compile 'com.google.cloud:google-cloud-core:1.22.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.21.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.22.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a6ccc7fa4c..b737667fda 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.21.1-SNAPSHOT + 1.22.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.39.1-alpha-SNAPSHOT + 0.40.0-alpha google-cloud-core From 7d0b0a8d3abf90916056255ecb1e0d70147563bd Mon Sep 17 00:00:00 2001 From: neozwu Date: Fri, 16 Mar 2018 20:37:45 -0700 Subject: [PATCH 460/663] bump to snapshot version (#3055) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0707eb3714..b41799fad6 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.22.0 + 1.22.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.40.0-alpha + 0.40.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 4b25c65bd2..5f61bb8667 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.22.0 + 1.22.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.40.0-alpha + 0.40.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b737667fda..9ac57c2751 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.22.0 + 1.22.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.40.0-alpha + 0.40.1-alpha-SNAPSHOT google-cloud-core From 3b2ada9eb168dbf8469bb63053f696280fccdf60 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Thu, 22 Mar 2018 13:05:34 -0700 Subject: [PATCH 461/663] Release 0.41.0 (#3076) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index b41799fad6..a2315173b6 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.22.1-SNAPSHOT + 1.23.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.40.1-alpha-SNAPSHOT + 0.41.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5f61bb8667..781bf3d731 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.22.1-SNAPSHOT + 1.23.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.40.1-alpha-SNAPSHOT + 0.41.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 92e07c17cb..f2aa4d76ba 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.22.0 + 1.23.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.22.0' +compile 'com.google.cloud:google-cloud-core:1.23.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.22.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.23.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9ac57c2751..9fd60a5451 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.22.1-SNAPSHOT + 1.23.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.40.1-alpha-SNAPSHOT + 0.41.0-alpha google-cloud-core From 722a77b0c529e0be2c24700a096e2c0a6b0eed74 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Fri, 23 Mar 2018 09:45:54 -0700 Subject: [PATCH 462/663] Bump version to 0.41.1-SNAPSHOT for development (#3079) Add texttospeech in root readme --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index a2315173b6..12bbd1e8b2 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.23.0 + 1.23.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.41.0-alpha + 0.41.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 781bf3d731..b8d30bbef7 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.23.0 + 1.23.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.41.0-alpha + 0.41.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9fd60a5451..a3ec47d260 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.23.0 + 1.23.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.41.0-alpha + 0.41.1-alpha-SNAPSHOT google-cloud-core From d581d2cfc48273f44c1807584c7e503fa32d1571 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 27 Mar 2018 16:45:53 -0700 Subject: [PATCH 463/663] Release 0.42.0 (#3095) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 12bbd1e8b2..4cd3c06dc6 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.23.1-SNAPSHOT + 1.24.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.41.1-alpha-SNAPSHOT + 0.42.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index b8d30bbef7..ccdd4f85e2 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.23.1-SNAPSHOT + 1.24.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.41.1-alpha-SNAPSHOT + 0.42.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f2aa4d76ba..274090e18d 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.23.0 + 1.24.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.23.0' +compile 'com.google.cloud:google-cloud-core:1.24.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.23.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.24.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a3ec47d260..7829724d3c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.23.1-SNAPSHOT + 1.24.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.41.1-alpha-SNAPSHOT + 0.42.0-alpha google-cloud-core From 51ddf8be0732b46e575dd1f7280b54449b01472e Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 27 Mar 2018 16:57:25 -0700 Subject: [PATCH 464/663] Bump to snapshot version for development (#3096) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4cd3c06dc6..d8ea9a2a2e 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.24.0 + 1.24.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.0-alpha + 0.42.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index ccdd4f85e2..458dfbb6dc 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.24.0 + 1.24.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.0-alpha + 0.42.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7829724d3c..4a01fadd42 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.24.0 + 1.24.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.0-alpha + 0.42.1-alpha-SNAPSHOT google-cloud-core From d2b242a73a39367a63f27ecfb380f6e6123165be Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 2 Apr 2018 10:23:07 -0700 Subject: [PATCH 465/663] Release 0.42.1 --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d8ea9a2a2e..70099d569d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.24.1-SNAPSHOT + 1.24.1 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.1-alpha-SNAPSHOT + 0.42.1-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 458dfbb6dc..8c1953fa4c 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.24.1-SNAPSHOT + 1.24.1 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.1-alpha-SNAPSHOT + 0.42.1-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 274090e18d..b91b2fcbee 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.24.0 + 1.24.1 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.24.0' +compile 'com.google.cloud:google-cloud-core:1.24.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.24.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.24.1" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4a01fadd42..70b891cf79 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.24.1-SNAPSHOT + 1.24.1 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.1-alpha-SNAPSHOT + 0.42.1-alpha google-cloud-core From f77b5fa4d4a14098c836e1b856230e5c85f0778b Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 2 Apr 2018 11:52:39 -0700 Subject: [PATCH 466/663] Bumping to next snapshot versions (#3117) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 70099d569d..43f570befa 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.24.1 + 1.24.2-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.1-alpha + 0.42.2-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 8c1953fa4c..5a10b448bb 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.24.1 + 1.24.2-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.1-alpha + 0.42.2-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 70b891cf79..204bc611e1 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.24.1 + 1.24.2-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.1-alpha + 0.42.2-alpha-SNAPSHOT google-cloud-core From 7e71ac4ac293f65f102c9fa57141b572bd6585f5 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Wed, 4 Apr 2018 18:00:43 -0700 Subject: [PATCH 467/663] Release 0.43.0/1.25.0 (#3127) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 43f570befa..4ef073a943 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.24.2-SNAPSHOT + 1.25.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.2-alpha-SNAPSHOT + 0.43.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5a10b448bb..4603cfdf2d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.24.2-SNAPSHOT + 1.25.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.2-alpha-SNAPSHOT + 0.43.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index b91b2fcbee..d801c41e3b 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.24.1 + 1.25.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.24.1' +compile 'com.google.cloud:google-cloud-core:1.25.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.24.1" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.25.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 204bc611e1..727b223508 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.24.2-SNAPSHOT + 1.25.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.42.2-alpha-SNAPSHOT + 0.43.0-alpha google-cloud-core From fee55ccf02910fb019ea2704aaeb5a1a7c44d6a4 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Wed, 4 Apr 2018 18:14:35 -0700 Subject: [PATCH 468/663] Bump to snapshot version (#3128) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4ef073a943..c7ddf00d74 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.25.0 + 1.25.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.43.0-alpha + 0.43.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 4603cfdf2d..a5b625b08e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.25.0 + 1.25.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.43.0-alpha + 0.43.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 727b223508..bb28ccf06a 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.25.0 + 1.25.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.43.0-alpha + 0.43.1-alpha-SNAPSHOT google-cloud-core From 6fc86f446c9041988887b828bd584f238414a8f3 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Thu, 12 Apr 2018 18:25:05 -0700 Subject: [PATCH 469/663] core: add parent resource names (#3148) --- .../java/com/google/cloud/BillingName.java | 162 ++++++++++++++++++ .../java/com/google/cloud/FolderName.java | 162 ++++++++++++++++++ .../com/google/cloud/OrganizationName.java | 162 ++++++++++++++++++ .../java/com/google/cloud/ParentName.java | 26 +++ .../java/com/google/cloud/ParentNames.java | 41 +++++ .../java/com/google/cloud/ProjectName.java | 162 ++++++++++++++++++ .../com/google/cloud/UntypedParentName.java | 102 +++++++++++ 7 files changed, 817 insertions(+) create mode 100644 google-cloud-core/src/main/java/com/google/cloud/BillingName.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/FolderName.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/OrganizationName.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/ParentName.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/ParentNames.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/ProjectName.java create mode 100644 google-cloud-core/src/main/java/com/google/cloud/UntypedParentName.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/BillingName.java b/google-cloud-core/src/main/java/com/google/cloud/BillingName.java new file mode 100644 index 0000000000..c0f29bff26 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/BillingName.java @@ -0,0 +1,162 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.api.core.BetaApi; +import com.google.api.pathtemplate.PathTemplate; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +// Formerly generated by GAPIC protoc plugin. +@BetaApi +public class BillingName extends ParentName { + + private static final PathTemplate PATH_TEMPLATE = + PathTemplate.createWithoutUrlEncoding("billingAccounts/{billing_account}"); + + private volatile Map fieldValuesMap; + + private final String billingAccount; + + public String getBillingAccount() { + return billingAccount; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + private BillingName(Builder builder) { + billingAccount = Preconditions.checkNotNull(builder.getBillingAccount()); + } + + public static BillingName of(String billingAccount) { + return newBuilder().setBillingAccount(billingAccount).build(); + } + + public static String format(String billingAccount) { + return newBuilder().setBillingAccount(billingAccount).build().toString(); + } + + public static BillingName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + PATH_TEMPLATE.validatedMatch( + formattedString, "BillingName.parse: formattedString not in valid format"); + return of(matchMap.get("billing_account")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList(values.size()); + for (BillingName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PATH_TEMPLATE.matches(formattedString); + } + + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + fieldMapBuilder.put("billingAccount", billingAccount); + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PATH_TEMPLATE.instantiate("billing_account", billingAccount); + } + + /** Builder for BillingName. */ + public static class Builder { + + private String billingAccount; + + public String getBillingAccount() { + return billingAccount; + } + + public Builder setBillingAccount(String billingAccount) { + this.billingAccount = billingAccount; + return this; + } + + private Builder() {} + + private Builder(BillingName billingName) { + billingAccount = billingName.billingAccount; + } + + public BillingName build() { + return new BillingName(this); + } + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof BillingName) { + BillingName that = (BillingName) o; + return this.billingAccount.equals(that.billingAccount); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= billingAccount.hashCode(); + return h; + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/FolderName.java b/google-cloud-core/src/main/java/com/google/cloud/FolderName.java new file mode 100644 index 0000000000..9863a3a61e --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/FolderName.java @@ -0,0 +1,162 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.api.core.BetaApi; +import com.google.api.pathtemplate.PathTemplate; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +// Formerly generated by GAPIC protoc plugin. +@BetaApi +public class FolderName extends ParentName { + + private static final PathTemplate PATH_TEMPLATE = + PathTemplate.createWithoutUrlEncoding("folders/{folder}"); + + private volatile Map fieldValuesMap; + + private final String folder; + + public String getFolder() { + return folder; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + private FolderName(Builder builder) { + folder = Preconditions.checkNotNull(builder.getFolder()); + } + + public static FolderName of(String folder) { + return newBuilder().setFolder(folder).build(); + } + + public static String format(String folder) { + return newBuilder().setFolder(folder).build().toString(); + } + + public static FolderName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + PATH_TEMPLATE.validatedMatch( + formattedString, "FolderName.parse: formattedString not in valid format"); + return of(matchMap.get("folder")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList(values.size()); + for (FolderName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PATH_TEMPLATE.matches(formattedString); + } + + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + fieldMapBuilder.put("folder", folder); + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PATH_TEMPLATE.instantiate("folder", folder); + } + + /** Builder for FolderName. */ + public static class Builder { + + private String folder; + + public String getFolder() { + return folder; + } + + public Builder setFolder(String folder) { + this.folder = folder; + return this; + } + + private Builder() {} + + private Builder(FolderName folderName) { + folder = folderName.folder; + } + + public FolderName build() { + return new FolderName(this); + } + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof FolderName) { + FolderName that = (FolderName) o; + return this.folder.equals(that.folder); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= folder.hashCode(); + return h; + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/OrganizationName.java b/google-cloud-core/src/main/java/com/google/cloud/OrganizationName.java new file mode 100644 index 0000000000..ff06d65eca --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/OrganizationName.java @@ -0,0 +1,162 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.api.core.BetaApi; +import com.google.api.pathtemplate.PathTemplate; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +// Formerly generated by GAPIC protoc plugin. +@BetaApi +public class OrganizationName extends ParentName { + + private static final PathTemplate PATH_TEMPLATE = + PathTemplate.createWithoutUrlEncoding("organizations/{organization}"); + + private volatile Map fieldValuesMap; + + private final String organization; + + public String getOrganization() { + return organization; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + private OrganizationName(Builder builder) { + organization = Preconditions.checkNotNull(builder.getOrganization()); + } + + public static OrganizationName of(String organization) { + return newBuilder().setOrganization(organization).build(); + } + + public static String format(String organization) { + return newBuilder().setOrganization(organization).build().toString(); + } + + public static OrganizationName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + PATH_TEMPLATE.validatedMatch( + formattedString, "OrganizationName.parse: formattedString not in valid format"); + return of(matchMap.get("organization")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList(values.size()); + for (OrganizationName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PATH_TEMPLATE.matches(formattedString); + } + + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + fieldMapBuilder.put("organization", organization); + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PATH_TEMPLATE.instantiate("organization", organization); + } + + /** Builder for OrganizationName. */ + public static class Builder { + + private String organization; + + public String getOrganization() { + return organization; + } + + public Builder setOrganization(String organization) { + this.organization = organization; + return this; + } + + private Builder() {} + + private Builder(OrganizationName organizationName) { + organization = organizationName.organization; + } + + public OrganizationName build() { + return new OrganizationName(this); + } + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof OrganizationName) { + OrganizationName that = (OrganizationName) o; + return this.organization.equals(that.organization); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= organization.hashCode(); + return h; + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ParentName.java b/google-cloud-core/src/main/java/com/google/cloud/ParentName.java new file mode 100644 index 0000000000..bd40991a56 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/ParentName.java @@ -0,0 +1,26 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.api.core.BetaApi; +import com.google.api.resourcenames.ResourceName; + +// Formerly generated by GAPIC protoc plugin. +@BetaApi +public abstract class ParentName implements ResourceName { + protected ParentName() {} +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ParentNames.java b/google-cloud-core/src/main/java/com/google/cloud/ParentNames.java new file mode 100644 index 0000000000..ef048fedb0 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/ParentNames.java @@ -0,0 +1,41 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.api.core.BetaApi; + +// Formerly generated by GAPIC protoc plugin. +@BetaApi +public class ParentNames { + private ParentNames() {} + + public static ParentName parse(String resourceNameString) { + if (ProjectName.isParsableFrom(resourceNameString)) { + return ProjectName.parse(resourceNameString); + } + if (OrganizationName.isParsableFrom(resourceNameString)) { + return OrganizationName.parse(resourceNameString); + } + if (FolderName.isParsableFrom(resourceNameString)) { + return FolderName.parse(resourceNameString); + } + if (BillingName.isParsableFrom(resourceNameString)) { + return BillingName.parse(resourceNameString); + } + return UntypedParentName.parse(resourceNameString); + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ProjectName.java b/google-cloud-core/src/main/java/com/google/cloud/ProjectName.java new file mode 100644 index 0000000000..81df832662 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/ProjectName.java @@ -0,0 +1,162 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.api.core.BetaApi; +import com.google.api.pathtemplate.PathTemplate; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +// Formerly generated by GAPIC protoc plugin. +@BetaApi +public class ProjectName extends ParentName { + + private static final PathTemplate PATH_TEMPLATE = + PathTemplate.createWithoutUrlEncoding("projects/{project}"); + + private volatile Map fieldValuesMap; + + private final String project; + + public String getProject() { + return project; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + private ProjectName(Builder builder) { + project = Preconditions.checkNotNull(builder.getProject()); + } + + public static ProjectName of(String project) { + return newBuilder().setProject(project).build(); + } + + public static String format(String project) { + return newBuilder().setProject(project).build().toString(); + } + + public static ProjectName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + PATH_TEMPLATE.validatedMatch( + formattedString, "ProjectName.parse: formattedString not in valid format"); + return of(matchMap.get("project")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList(values.size()); + for (ProjectName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PATH_TEMPLATE.matches(formattedString); + } + + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + fieldMapBuilder.put("project", project); + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PATH_TEMPLATE.instantiate("project", project); + } + + /** Builder for ProjectName. */ + public static class Builder { + + private String project; + + public String getProject() { + return project; + } + + public Builder setProject(String project) { + this.project = project; + return this; + } + + private Builder() {} + + private Builder(ProjectName projectName) { + project = projectName.project; + } + + public ProjectName build() { + return new ProjectName(this); + } + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof ProjectName) { + ProjectName that = (ProjectName) o; + return this.project.equals(that.project); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= project.hashCode(); + return h; + } +} diff --git a/google-cloud-core/src/main/java/com/google/cloud/UntypedParentName.java b/google-cloud-core/src/main/java/com/google/cloud/UntypedParentName.java new file mode 100644 index 0000000000..faaca106cb --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/UntypedParentName.java @@ -0,0 +1,102 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import com.google.api.core.BetaApi; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +// Formerly generated by GAPIC protoc plugin. +@BetaApi +public class UntypedParentName extends ParentName { + + private final String rawValue; + private Map valueMap; + + private UntypedParentName(String rawValue) { + this.rawValue = Preconditions.checkNotNull(rawValue); + this.valueMap = ImmutableMap.of("", rawValue); + } + + public static UntypedParentName from(ResourceName resourceName) { + return new UntypedParentName(resourceName.toString()); + } + + public static UntypedParentName parse(String formattedString) { + return new UntypedParentName(formattedString); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList(values.size()); + for (UntypedParentName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return true; + } + + /** Return a map with a single value rawValue keyed on an empty String "". */ + public Map getFieldValuesMap() { + return valueMap; + } + + /** Return the initial rawValue if @param fieldName is an empty String, else return null. */ + public String getFieldValue(String fieldName) { + return valueMap.get(fieldName); + } + + @Override + public String toString() { + return rawValue; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof UntypedParentName) { + UntypedParentName that = (UntypedParentName) o; + return this.rawValue.equals(that.rawValue); + } + return false; + } + + @Override + public int hashCode() { + return rawValue.hashCode(); + } +} From 6c90daa496880d9a62e520490a46aaf57f924ec8 Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 16 Apr 2018 08:25:35 -0700 Subject: [PATCH 470/663] Release 0.44.0 (#3161) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index c7ddf00d74..3f84cbfc6f 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.25.1-SNAPSHOT + 1.26.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.43.1-alpha-SNAPSHOT + 0.44.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index a5b625b08e..ebe3291792 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.25.1-SNAPSHOT + 1.26.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.43.1-alpha-SNAPSHOT + 0.44.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index d801c41e3b..ec6651ea2f 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.25.0 + 1.26.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.25.0' +compile 'com.google.cloud:google-cloud-core:1.26.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.25.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.26.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index bb28ccf06a..9e55f7f9c9 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.25.1-SNAPSHOT + 1.26.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.43.1-alpha-SNAPSHOT + 0.44.0-alpha google-cloud-core From 241f89bcfaa5afb7239cf7e509e08c75fc1de0e1 Mon Sep 17 00:00:00 2001 From: neozwu Date: Mon, 16 Apr 2018 09:12:27 -0700 Subject: [PATCH 471/663] bump version for development (#3162) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 3f84cbfc6f..4b3f7aa163 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.26.0 + 1.26.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.44.0-alpha + 0.44.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index ebe3291792..6e00351c3a 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.26.0 + 1.26.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.44.0-alpha + 0.44.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9e55f7f9c9..457ad76ab7 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.26.0 + 1.26.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.44.0-alpha + 0.44.1-alpha-SNAPSHOT google-cloud-core From efe89a43877ef899e803ec0be44dfb2b4c1e8f68 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Fri, 20 Apr 2018 08:20:26 -0700 Subject: [PATCH 472/663] Release 0.45.0 (#3174) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4b3f7aa163..e69aef041a 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.26.1-SNAPSHOT + 1.27.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.44.1-alpha-SNAPSHOT + 0.45.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 6e00351c3a..46b2cd719f 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.26.1-SNAPSHOT + 1.27.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.44.1-alpha-SNAPSHOT + 0.45.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index ec6651ea2f..02147b3f97 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.26.0 + 1.27.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.26.0' +compile 'com.google.cloud:google-cloud-core:1.27.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.26.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.27.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 457ad76ab7..e8e98078dc 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.26.1-SNAPSHOT + 1.27.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.44.1-alpha-SNAPSHOT + 0.45.0-alpha google-cloud-core From c92c3d82cecc1b5d0834b565ab6859c40eefafd2 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Fri, 20 Apr 2018 11:30:31 -0700 Subject: [PATCH 473/663] Bump version to 0.45.1-alpha-SNAPSHOT for development (#3177) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index e69aef041a..cfb23eb4d2 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.27.0 + 1.27.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.45.0-alpha + 0.45.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 46b2cd719f..dc2f05abfc 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.27.0 + 1.27.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.45.0-alpha + 0.45.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e8e98078dc..7a92c4400c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.27.0 + 1.27.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.45.0-alpha + 0.45.1-alpha-SNAPSHOT google-cloud-core From 2d28a1398f34d1428dc8f54ef64afa18c9e8b2f0 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 27 Apr 2018 11:34:52 -0700 Subject: [PATCH 474/663] Release 0.46.0/1.28.0 --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index cfb23eb4d2..9326a154b9 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.27.1-SNAPSHOT + 1.28.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.45.1-alpha-SNAPSHOT + 0.46.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index dc2f05abfc..2d43bd303e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.27.1-SNAPSHOT + 1.28.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.45.1-alpha-SNAPSHOT + 0.46.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 02147b3f97..715d0f82f7 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.27.0 + 1.28.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.27.0' +compile 'com.google.cloud:google-cloud-core:1.28.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.27.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.28.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7a92c4400c..9c52d7a905 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.27.1-SNAPSHOT + 1.28.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.45.1-alpha-SNAPSHOT + 0.46.0-alpha google-cloud-core From 257a3a296e7b23019e9da94ca38787c68a513284 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 27 Apr 2018 15:07:30 -0700 Subject: [PATCH 475/663] Bump to snapshot versions (#3211) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 9326a154b9..0ce6d43997 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.28.0 + 1.28.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.46.0-alpha + 0.46.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 2d43bd303e..62df304f17 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.28.0 + 1.28.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.46.0-alpha + 0.46.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9c52d7a905..3524de4578 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.28.0 + 1.28.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.46.0-alpha + 0.46.1-alpha-SNAPSHOT google-cloud-core From 0ee32bb561cc638d1bb3f6c08bc2fc9c4bf96a42 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Tue, 1 May 2018 13:55:49 -0700 Subject: [PATCH 476/663] properly add equals() and compare fields (#3218) --- .../google/cloud/BaseServiceException.java | 19 +++++++++++++++++-- .../cloud/BaseServiceExceptionTest.java | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index 470c2cf9a8..a0058a2e3f 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -214,12 +214,27 @@ public boolean isRetryable(boolean idempotent, Set retryableErrors) { @Override public String toString() { - return MoreObjects.toStringHelper(this).add("code", code).add("reason", reason).toString(); + return MoreObjects.toStringHelper(this) + .add("code", code) + .add("reason", reason) + .add("rejected", rejected) + .toString(); } @Override public int hashCode() { - return Objects.hash(code, reason); + return Objects.hash(code, reason, rejected); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Error)) { + return false; + } + Error o = (Error) obj; + return Objects.equals(code, o.code) + && Objects.equals(reason, o.reason) + && Objects.equals(rejected, o.rejected); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index 5c5773d26f..fed2faa883 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -17,6 +17,7 @@ package com.google.cloud; import static com.google.cloud.BaseServiceException.UNKNOWN_CODE; +import static com.google.common.truth.Truth.assertThat; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; @@ -132,4 +133,19 @@ public void testTranslateAndThrow() throws Exception { verify(exceptionMock); } } + + @Test + public void testError_Equal() { + BaseServiceException.Error error = new BaseServiceException.Error(0, "reason", true); + assertThat(error).isEqualTo(error); + assertThat(error.hashCode()).isEqualTo(error.hashCode()); + + BaseServiceException.Error sameError = new BaseServiceException.Error(0, "reason", true); + assertThat(error).isEqualTo(sameError); + assertThat(error.hashCode()).isEqualTo(sameError.hashCode()); + + BaseServiceException.Error error2 = new BaseServiceException.Error(1, "other reason", false); + assertThat(error).isNotEqualTo(error2); + assertThat(error.hashCode()).isNotEqualTo(error2.hashCode()); + } } From 7c298d269ef69f8b7388a8690c9af936368f8890 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Tue, 1 May 2018 15:56:33 -0700 Subject: [PATCH 477/663] add hashCode to NoCredentials (#3216) --- .../src/main/java/com/google/cloud/NoCredentials.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java b/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java index e9ed09f25d..4726c4d0c6 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java +++ b/google-cloud-core/src/main/java/com/google/cloud/NoCredentials.java @@ -40,9 +40,11 @@ public static NoCredentials getInstance() { @Override public boolean equals(Object obj) { - if (!(obj instanceof NoCredentials)) { - return false; - } return this == obj; } + + @Override + public int hashCode() { + return System.identityHashCode(this); + } } From e3b6d171d164ba8c269ede9df0028a18340d7cec Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Mon, 7 May 2018 17:06:46 -0700 Subject: [PATCH 478/663] Release 0.47.0/1.29.0 (#3239) Also fix javadoc --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0ce6d43997..ca5e706cf1 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.28.1-SNAPSHOT + 1.29.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.46.1-alpha-SNAPSHOT + 0.47.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 62df304f17..2a86af060f 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.28.1-SNAPSHOT + 1.29.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.46.1-alpha-SNAPSHOT + 0.47.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 715d0f82f7..45e4450e17 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.28.0 + 1.29.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.28.0' +compile 'com.google.cloud:google-cloud-core:1.29.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.28.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.29.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3524de4578..d66fc8832e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.28.1-SNAPSHOT + 1.29.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.46.1-alpha-SNAPSHOT + 0.47.0-alpha google-cloud-core From 14f7c593d79a2714372fbfabecb972edf260a6fc Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Tue, 8 May 2018 11:41:55 -0700 Subject: [PATCH 479/663] bump to snapshot version (#3245) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ca5e706cf1..bbd1adb19f 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.29.0 + 1.29.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.47.0-alpha + 0.47.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 2a86af060f..44f19bce2a 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.29.0 + 1.29.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.47.0-alpha + 0.47.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d66fc8832e..583c810cfb 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.29.0 + 1.29.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.47.0-alpha + 0.47.1-alpha-SNAPSHOT google-cloud-core From 60b928a7d20f33bce3ac25d12d2ddc379d3620a4 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Thu, 10 May 2018 10:54:50 -0700 Subject: [PATCH 480/663] Move grpc and proto artifacts to google-cloud-java from api-client-staging (second part) (#3251) 1) Radically change the structure of the repo. Now the root `pom.xml` file is not deployed to maven and is not a parent pom for any of the other modules, but is simply an aggregator pom, which aggregates other mostly independent of each other modules. 2) Update proto and grpc artifact to the latest generated versions as of time of this PR. 3) Add `cloudiot-v1` and `websecurityscanner-v1alpha` proto and grp artifacts (not released yet even in api-client-staging). Note, gapic clients for this apis are not added yet. 4) Rename `google-cloud-pom` parent artifact (for manual and gapic clients) to `google-cloud-clients`. 5) Move all manual and gapic clients from root directory to `google-cloud-clients` sub directory. 6) Make `google-cloud-bom` not a child of `google-cloud-clients` (former `google-cloud-pom`) anymore, keep it on root level so it becomes a sibling of `google-cloud-clients` (module which used to be its parent). 7) Similarly make `google-cloud-examples`, `google-cloud-testing` and `google-cloud-util` not children of `google-cloud-clients` and keep them on root level. Make these three modules also excluded from maven deployment (they will not be published to maven anymore). After this PR is done, additional work is required to fix circleci individual IT tests runs (should be trivial). Also deployment and documentation scripts must be modified accordingly (will be done right after pushing this PR). --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index bbd1adb19f..dfbbbf5b0d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -11,8 +11,8 @@ com.google.cloud - google-cloud-pom - 0.47.1-alpha-SNAPSHOT + google-cloud-clients + 0.47.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 44f19bce2a..46149f6639 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -11,8 +11,8 @@ com.google.cloud - google-cloud-pom - 0.47.1-alpha-SNAPSHOT + google-cloud-clients + 0.47.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 583c810cfb..e8930bf751 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -11,8 +11,8 @@ com.google.cloud - google-cloud-pom - 0.47.1-alpha-SNAPSHOT + google-cloud-clients + 0.47.1-alpha-SNAPSHOT google-cloud-core From ea3dc6ffc2172c0c73be3a4ea9f2fd0ec20d66ac Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 11 May 2018 14:53:28 -0700 Subject: [PATCH 481/663] move resource names (#3259) --- .../java/com/google/cloud/BillingName.java | 162 ------------------ .../java/com/google/cloud/FolderName.java | 162 ------------------ .../com/google/cloud/OrganizationName.java | 162 ------------------ .../java/com/google/cloud/ParentName.java | 26 --- .../java/com/google/cloud/ParentNames.java | 41 ----- .../java/com/google/cloud/ProjectName.java | 162 ------------------ .../com/google/cloud/UntypedParentName.java | 102 ----------- 7 files changed, 817 deletions(-) delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/BillingName.java delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/FolderName.java delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/OrganizationName.java delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/ParentName.java delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/ParentNames.java delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/ProjectName.java delete mode 100644 google-cloud-core/src/main/java/com/google/cloud/UntypedParentName.java diff --git a/google-cloud-core/src/main/java/com/google/cloud/BillingName.java b/google-cloud-core/src/main/java/com/google/cloud/BillingName.java deleted file mode 100644 index c0f29bff26..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/BillingName.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import com.google.api.core.BetaApi; -import com.google.api.pathtemplate.PathTemplate; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -// Formerly generated by GAPIC protoc plugin. -@BetaApi -public class BillingName extends ParentName { - - private static final PathTemplate PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("billingAccounts/{billing_account}"); - - private volatile Map fieldValuesMap; - - private final String billingAccount; - - public String getBillingAccount() { - return billingAccount; - } - - public static Builder newBuilder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - private BillingName(Builder builder) { - billingAccount = Preconditions.checkNotNull(builder.getBillingAccount()); - } - - public static BillingName of(String billingAccount) { - return newBuilder().setBillingAccount(billingAccount).build(); - } - - public static String format(String billingAccount) { - return newBuilder().setBillingAccount(billingAccount).build().toString(); - } - - public static BillingName parse(String formattedString) { - if (formattedString.isEmpty()) { - return null; - } - Map matchMap = - PATH_TEMPLATE.validatedMatch( - formattedString, "BillingName.parse: formattedString not in valid format"); - return of(matchMap.get("billing_account")); - } - - public static List parseList(List formattedStrings) { - List list = new ArrayList<>(formattedStrings.size()); - for (String formattedString : formattedStrings) { - list.add(parse(formattedString)); - } - return list; - } - - public static List toStringList(List values) { - List list = new ArrayList(values.size()); - for (BillingName value : values) { - if (value == null) { - list.add(""); - } else { - list.add(value.toString()); - } - } - return list; - } - - public static boolean isParsableFrom(String formattedString) { - return PATH_TEMPLATE.matches(formattedString); - } - - public Map getFieldValuesMap() { - if (fieldValuesMap == null) { - synchronized (this) { - if (fieldValuesMap == null) { - ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); - fieldMapBuilder.put("billingAccount", billingAccount); - fieldValuesMap = fieldMapBuilder.build(); - } - } - } - return fieldValuesMap; - } - - public String getFieldValue(String fieldName) { - return getFieldValuesMap().get(fieldName); - } - - @Override - public String toString() { - return PATH_TEMPLATE.instantiate("billing_account", billingAccount); - } - - /** Builder for BillingName. */ - public static class Builder { - - private String billingAccount; - - public String getBillingAccount() { - return billingAccount; - } - - public Builder setBillingAccount(String billingAccount) { - this.billingAccount = billingAccount; - return this; - } - - private Builder() {} - - private Builder(BillingName billingName) { - billingAccount = billingName.billingAccount; - } - - public BillingName build() { - return new BillingName(this); - } - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof BillingName) { - BillingName that = (BillingName) o; - return this.billingAccount.equals(that.billingAccount); - } - return false; - } - - @Override - public int hashCode() { - int h = 1; - h *= 1000003; - h ^= billingAccount.hashCode(); - return h; - } -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/FolderName.java b/google-cloud-core/src/main/java/com/google/cloud/FolderName.java deleted file mode 100644 index 9863a3a61e..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/FolderName.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import com.google.api.core.BetaApi; -import com.google.api.pathtemplate.PathTemplate; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -// Formerly generated by GAPIC protoc plugin. -@BetaApi -public class FolderName extends ParentName { - - private static final PathTemplate PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("folders/{folder}"); - - private volatile Map fieldValuesMap; - - private final String folder; - - public String getFolder() { - return folder; - } - - public static Builder newBuilder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - private FolderName(Builder builder) { - folder = Preconditions.checkNotNull(builder.getFolder()); - } - - public static FolderName of(String folder) { - return newBuilder().setFolder(folder).build(); - } - - public static String format(String folder) { - return newBuilder().setFolder(folder).build().toString(); - } - - public static FolderName parse(String formattedString) { - if (formattedString.isEmpty()) { - return null; - } - Map matchMap = - PATH_TEMPLATE.validatedMatch( - formattedString, "FolderName.parse: formattedString not in valid format"); - return of(matchMap.get("folder")); - } - - public static List parseList(List formattedStrings) { - List list = new ArrayList<>(formattedStrings.size()); - for (String formattedString : formattedStrings) { - list.add(parse(formattedString)); - } - return list; - } - - public static List toStringList(List values) { - List list = new ArrayList(values.size()); - for (FolderName value : values) { - if (value == null) { - list.add(""); - } else { - list.add(value.toString()); - } - } - return list; - } - - public static boolean isParsableFrom(String formattedString) { - return PATH_TEMPLATE.matches(formattedString); - } - - public Map getFieldValuesMap() { - if (fieldValuesMap == null) { - synchronized (this) { - if (fieldValuesMap == null) { - ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); - fieldMapBuilder.put("folder", folder); - fieldValuesMap = fieldMapBuilder.build(); - } - } - } - return fieldValuesMap; - } - - public String getFieldValue(String fieldName) { - return getFieldValuesMap().get(fieldName); - } - - @Override - public String toString() { - return PATH_TEMPLATE.instantiate("folder", folder); - } - - /** Builder for FolderName. */ - public static class Builder { - - private String folder; - - public String getFolder() { - return folder; - } - - public Builder setFolder(String folder) { - this.folder = folder; - return this; - } - - private Builder() {} - - private Builder(FolderName folderName) { - folder = folderName.folder; - } - - public FolderName build() { - return new FolderName(this); - } - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof FolderName) { - FolderName that = (FolderName) o; - return this.folder.equals(that.folder); - } - return false; - } - - @Override - public int hashCode() { - int h = 1; - h *= 1000003; - h ^= folder.hashCode(); - return h; - } -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/OrganizationName.java b/google-cloud-core/src/main/java/com/google/cloud/OrganizationName.java deleted file mode 100644 index ff06d65eca..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/OrganizationName.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import com.google.api.core.BetaApi; -import com.google.api.pathtemplate.PathTemplate; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -// Formerly generated by GAPIC protoc plugin. -@BetaApi -public class OrganizationName extends ParentName { - - private static final PathTemplate PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("organizations/{organization}"); - - private volatile Map fieldValuesMap; - - private final String organization; - - public String getOrganization() { - return organization; - } - - public static Builder newBuilder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - private OrganizationName(Builder builder) { - organization = Preconditions.checkNotNull(builder.getOrganization()); - } - - public static OrganizationName of(String organization) { - return newBuilder().setOrganization(organization).build(); - } - - public static String format(String organization) { - return newBuilder().setOrganization(organization).build().toString(); - } - - public static OrganizationName parse(String formattedString) { - if (formattedString.isEmpty()) { - return null; - } - Map matchMap = - PATH_TEMPLATE.validatedMatch( - formattedString, "OrganizationName.parse: formattedString not in valid format"); - return of(matchMap.get("organization")); - } - - public static List parseList(List formattedStrings) { - List list = new ArrayList<>(formattedStrings.size()); - for (String formattedString : formattedStrings) { - list.add(parse(formattedString)); - } - return list; - } - - public static List toStringList(List values) { - List list = new ArrayList(values.size()); - for (OrganizationName value : values) { - if (value == null) { - list.add(""); - } else { - list.add(value.toString()); - } - } - return list; - } - - public static boolean isParsableFrom(String formattedString) { - return PATH_TEMPLATE.matches(formattedString); - } - - public Map getFieldValuesMap() { - if (fieldValuesMap == null) { - synchronized (this) { - if (fieldValuesMap == null) { - ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); - fieldMapBuilder.put("organization", organization); - fieldValuesMap = fieldMapBuilder.build(); - } - } - } - return fieldValuesMap; - } - - public String getFieldValue(String fieldName) { - return getFieldValuesMap().get(fieldName); - } - - @Override - public String toString() { - return PATH_TEMPLATE.instantiate("organization", organization); - } - - /** Builder for OrganizationName. */ - public static class Builder { - - private String organization; - - public String getOrganization() { - return organization; - } - - public Builder setOrganization(String organization) { - this.organization = organization; - return this; - } - - private Builder() {} - - private Builder(OrganizationName organizationName) { - organization = organizationName.organization; - } - - public OrganizationName build() { - return new OrganizationName(this); - } - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof OrganizationName) { - OrganizationName that = (OrganizationName) o; - return this.organization.equals(that.organization); - } - return false; - } - - @Override - public int hashCode() { - int h = 1; - h *= 1000003; - h ^= organization.hashCode(); - return h; - } -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ParentName.java b/google-cloud-core/src/main/java/com/google/cloud/ParentName.java deleted file mode 100644 index bd40991a56..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/ParentName.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import com.google.api.core.BetaApi; -import com.google.api.resourcenames.ResourceName; - -// Formerly generated by GAPIC protoc plugin. -@BetaApi -public abstract class ParentName implements ResourceName { - protected ParentName() {} -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ParentNames.java b/google-cloud-core/src/main/java/com/google/cloud/ParentNames.java deleted file mode 100644 index ef048fedb0..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/ParentNames.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import com.google.api.core.BetaApi; - -// Formerly generated by GAPIC protoc plugin. -@BetaApi -public class ParentNames { - private ParentNames() {} - - public static ParentName parse(String resourceNameString) { - if (ProjectName.isParsableFrom(resourceNameString)) { - return ProjectName.parse(resourceNameString); - } - if (OrganizationName.isParsableFrom(resourceNameString)) { - return OrganizationName.parse(resourceNameString); - } - if (FolderName.isParsableFrom(resourceNameString)) { - return FolderName.parse(resourceNameString); - } - if (BillingName.isParsableFrom(resourceNameString)) { - return BillingName.parse(resourceNameString); - } - return UntypedParentName.parse(resourceNameString); - } -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/ProjectName.java b/google-cloud-core/src/main/java/com/google/cloud/ProjectName.java deleted file mode 100644 index 81df832662..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/ProjectName.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import com.google.api.core.BetaApi; -import com.google.api.pathtemplate.PathTemplate; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -// Formerly generated by GAPIC protoc plugin. -@BetaApi -public class ProjectName extends ParentName { - - private static final PathTemplate PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("projects/{project}"); - - private volatile Map fieldValuesMap; - - private final String project; - - public String getProject() { - return project; - } - - public static Builder newBuilder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - private ProjectName(Builder builder) { - project = Preconditions.checkNotNull(builder.getProject()); - } - - public static ProjectName of(String project) { - return newBuilder().setProject(project).build(); - } - - public static String format(String project) { - return newBuilder().setProject(project).build().toString(); - } - - public static ProjectName parse(String formattedString) { - if (formattedString.isEmpty()) { - return null; - } - Map matchMap = - PATH_TEMPLATE.validatedMatch( - formattedString, "ProjectName.parse: formattedString not in valid format"); - return of(matchMap.get("project")); - } - - public static List parseList(List formattedStrings) { - List list = new ArrayList<>(formattedStrings.size()); - for (String formattedString : formattedStrings) { - list.add(parse(formattedString)); - } - return list; - } - - public static List toStringList(List values) { - List list = new ArrayList(values.size()); - for (ProjectName value : values) { - if (value == null) { - list.add(""); - } else { - list.add(value.toString()); - } - } - return list; - } - - public static boolean isParsableFrom(String formattedString) { - return PATH_TEMPLATE.matches(formattedString); - } - - public Map getFieldValuesMap() { - if (fieldValuesMap == null) { - synchronized (this) { - if (fieldValuesMap == null) { - ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); - fieldMapBuilder.put("project", project); - fieldValuesMap = fieldMapBuilder.build(); - } - } - } - return fieldValuesMap; - } - - public String getFieldValue(String fieldName) { - return getFieldValuesMap().get(fieldName); - } - - @Override - public String toString() { - return PATH_TEMPLATE.instantiate("project", project); - } - - /** Builder for ProjectName. */ - public static class Builder { - - private String project; - - public String getProject() { - return project; - } - - public Builder setProject(String project) { - this.project = project; - return this; - } - - private Builder() {} - - private Builder(ProjectName projectName) { - project = projectName.project; - } - - public ProjectName build() { - return new ProjectName(this); - } - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof ProjectName) { - ProjectName that = (ProjectName) o; - return this.project.equals(that.project); - } - return false; - } - - @Override - public int hashCode() { - int h = 1; - h *= 1000003; - h ^= project.hashCode(); - return h; - } -} diff --git a/google-cloud-core/src/main/java/com/google/cloud/UntypedParentName.java b/google-cloud-core/src/main/java/com/google/cloud/UntypedParentName.java deleted file mode 100644 index faaca106cb..0000000000 --- a/google-cloud-core/src/main/java/com/google/cloud/UntypedParentName.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud; - -import com.google.api.core.BetaApi; -import com.google.api.resourcenames.ResourceName; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -// Formerly generated by GAPIC protoc plugin. -@BetaApi -public class UntypedParentName extends ParentName { - - private final String rawValue; - private Map valueMap; - - private UntypedParentName(String rawValue) { - this.rawValue = Preconditions.checkNotNull(rawValue); - this.valueMap = ImmutableMap.of("", rawValue); - } - - public static UntypedParentName from(ResourceName resourceName) { - return new UntypedParentName(resourceName.toString()); - } - - public static UntypedParentName parse(String formattedString) { - return new UntypedParentName(formattedString); - } - - public static List parseList(List formattedStrings) { - List list = new ArrayList<>(formattedStrings.size()); - for (String formattedString : formattedStrings) { - list.add(parse(formattedString)); - } - return list; - } - - public static List toStringList(List values) { - List list = new ArrayList(values.size()); - for (UntypedParentName value : values) { - if (value == null) { - list.add(""); - } else { - list.add(value.toString()); - } - } - return list; - } - - public static boolean isParsableFrom(String formattedString) { - return true; - } - - /** Return a map with a single value rawValue keyed on an empty String "". */ - public Map getFieldValuesMap() { - return valueMap; - } - - /** Return the initial rawValue if @param fieldName is an empty String, else return null. */ - public String getFieldValue(String fieldName) { - return valueMap.get(fieldName); - } - - @Override - public String toString() { - return rawValue; - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UntypedParentName) { - UntypedParentName that = (UntypedParentName) o; - return this.rawValue.equals(that.rawValue); - } - return false; - } - - @Override - public int hashCode() { - return rawValue.hashCode(); - } -} From d7a705a85e9425c8a45f7aa7d6fe0c250ea0cf95 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Fri, 18 May 2018 10:01:00 -0700 Subject: [PATCH 482/663] Bump version to 0.48.0 release (#3288) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index dfbbbf5b0d..e7c75118c5 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.29.1-SNAPSHOT + 1.30.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.47.1-alpha-SNAPSHOT + 0.48.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 46149f6639..593092dc8f 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.29.1-SNAPSHOT + 1.30.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.47.1-alpha-SNAPSHOT + 0.48.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 45e4450e17..efaa152778 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.29.0 + 1.30.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.29.0' +compile 'com.google.cloud:google-cloud-core:1.30.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.29.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.30.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e8930bf751..58b0f4a4c5 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.29.1-SNAPSHOT + 1.30.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.47.1-alpha-SNAPSHOT + 0.48.0-alpha google-cloud-core From c73e3ac58faa8240c52d7f1bda3f69d272320379 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Mon, 21 May 2018 14:56:28 -0700 Subject: [PATCH 483/663] Bump version to 0.48.1-SNASPHOT for development (#3294) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index e7c75118c5..cb6dd8106c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.30.0 + 1.30.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.48.0-alpha + 0.48.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 593092dc8f..31b598d990 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.30.0 + 1.30.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.48.0-alpha + 0.48.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 58b0f4a4c5..1bfbe3f375 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.30.0 + 1.30.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.48.0-alpha + 0.48.1-alpha-SNAPSHOT google-cloud-core From 0d259ab57d3e093612ffaffee0b4e95abf6fe190 Mon Sep 17 00:00:00 2001 From: neozwu Date: Thu, 24 May 2018 10:13:56 -0700 Subject: [PATCH 484/663] release 0.49.0 (#3310) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index cb6dd8106c..a170eed85f 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.30.1-SNAPSHOT + 1.31.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.48.1-alpha-SNAPSHOT + 0.49.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 31b598d990..de6e9bdefa 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.30.1-SNAPSHOT + 1.31.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.48.1-alpha-SNAPSHOT + 0.49.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index efaa152778..693bb3aad1 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.30.0 + 1.31.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.30.0' +compile 'com.google.cloud:google-cloud-core:1.31.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.30.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.31.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1bfbe3f375..26968c7542 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.30.1-SNAPSHOT + 1.31.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.48.1-alpha-SNAPSHOT + 0.49.0-alpha google-cloud-core From 61c746316bb9280fe3e8abda3354a1685004edd6 Mon Sep 17 00:00:00 2001 From: neozwu Date: Thu, 24 May 2018 11:10:53 -0700 Subject: [PATCH 485/663] bump version for development (#3311) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index a170eed85f..bbf1bcd243 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.31.0 + 1.31.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.49.0-alpha + 0.49.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index de6e9bdefa..de7e0a41e2 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.31.0 + 1.31.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.49.0-alpha + 0.49.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 26968c7542..d258648615 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.31.0 + 1.31.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.49.0-alpha + 0.49.1-alpha-SNAPSHOT google-cloud-core From f26cca3340f50cb457bb8ea427ae1ea5889ee80d Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 25 May 2018 16:50:40 -0700 Subject: [PATCH 486/663] Adding Timestamp.toDate() (#3313) --- .../main/java/com/google/cloud/Timestamp.java | 12 ++++++++++ .../java/com/google/cloud/TimestampTest.java | 23 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java index 456877bd27..0c2eca7863 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -130,6 +130,18 @@ public java.sql.Timestamp toSqlTimestamp() { return ts; } + /** + * Returns a new {@code java.util.Date} corresponding to this {@code timestamp}. Any + * sub-millisecond precision will be stripped. + * + * @return An approximate {@code java.util.Date} representation of this {@code timestamp}. + */ + public Date toDate() { + long secondsInMilliseconds = TimeUnit.SECONDS.toMillis(this.seconds); + long nanosInMilliseconds = TimeUnit.NANOSECONDS.toMillis(this.nanos); + return new Date(secondsInMilliseconds + nanosInMilliseconds); + } + @Override public int compareTo(Timestamp other) { int r = Long.compare(seconds, other.seconds); diff --git a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java index 2aa07999c8..51d2ecb20f 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java @@ -21,8 +21,10 @@ import com.google.common.testing.EqualsTester; import java.util.Calendar; +import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; +import java.util.concurrent.TimeUnit; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -35,6 +37,9 @@ public class TimestampTest { private static final String TEST_TIME_ISO = "2015-10-12T15:14:54Z"; private static final long TEST_TIME_SECONDS = 1444662894L; private static final long TEST_TIME_MICROSECONDS = 10000100L; + private static final long TEST_TIME_MILLISECONDS = + TimeUnit.SECONDS.toMillis(1444662894L) + TimeUnit.MICROSECONDS.toMillis(1234); + private static final Date TEST_DATE = new Date(TEST_TIME_MILLISECONDS); @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -64,6 +69,24 @@ public void ofMicroseconds() { assertThat(timestamp.getNanos()).isEqualTo(TEST_TIME_MICROSECONDS % 1000000L * 1000); } + @Test + public void ofDate() { + Timestamp timestamp = Timestamp.of(TEST_DATE); + Long expectedSeconds = TimeUnit.MILLISECONDS.toSeconds(TEST_TIME_MILLISECONDS); + Long expectedNanos = + TimeUnit.MILLISECONDS.toNanos(TEST_TIME_MILLISECONDS) + - TimeUnit.SECONDS.toNanos(expectedSeconds); + assertThat(timestamp.getSeconds()).isEqualTo(expectedSeconds); + assertThat(timestamp.getNanos()).isEqualTo(expectedNanos); + } + + @Test + public void toDate() { + Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 1234 * 1000); + Date date = timestamp.toDate(); + assertThat(TEST_TIME_MILLISECONDS).isEqualTo(date.getTime()); + } + @Test public void toFromSqlTimestamp() { long seconds = TEST_TIME_SECONDS; From 6134d003727ec2cc2e68a41b0822f28a6b8c9adb Mon Sep 17 00:00:00 2001 From: Colin Arnott Date: Sat, 26 May 2018 01:14:36 +0000 Subject: [PATCH 487/663] make MetadataConfig.getAttribute() public (#3307) --- .../src/main/java/com/google/cloud/MetadataConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java index a285462165..9b1ee3ffc6 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -57,7 +57,7 @@ public static String getClusterName() { return getAttribute("instance/attributes/cluster-name"); } - private static String getAttribute(String attributeName) { + public static String getAttribute(String attributeName) { try { URL url = new URL(METADATA_URL + attributeName); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); From 0f8a560d767b679e47f5bb01adb572a63a343da5 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 1 Jun 2018 15:04:04 -0700 Subject: [PATCH 488/663] Release 0.50.0 (#3337) * Also add texttospeech v1 to versions.txt --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index bbf1bcd243..0fd4867b54 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.31.1-SNAPSHOT + 1.32.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.49.1-alpha-SNAPSHOT + 0.50.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index de7e0a41e2..9abd21062f 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.31.1-SNAPSHOT + 1.32.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.49.1-alpha-SNAPSHOT + 0.50.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 693bb3aad1..d402df5213 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.31.0 + 1.32.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.31.0' +compile 'com.google.cloud:google-cloud-core:1.32.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.31.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.32.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d258648615..4da1387fc7 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.31.1-SNAPSHOT + 1.32.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.49.1-alpha-SNAPSHOT + 0.50.0-alpha google-cloud-core From d7cd6b82eb24330c9aa90f48bf03acb22f731de8 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 1 Jun 2018 15:14:47 -0700 Subject: [PATCH 489/663] Bump version for development (#3338) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0fd4867b54..40dae79df6 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.32.0 + 1.32.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.50.0-alpha + 0.50.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 9abd21062f..09c12d2737 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.32.0 + 1.32.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.50.0-alpha + 0.50.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4da1387fc7..4a6b29b6e7 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.32.0 + 1.32.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.50.0-alpha + 0.50.1-alpha-SNAPSHOT google-cloud-core From bad7e6f74180cd321ca190e3dc7d4404f28ffc91 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Thu, 7 Jun 2018 16:17:57 -0700 Subject: [PATCH 490/663] Release 0.51.0 (#3358) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 40dae79df6..3b936ddbde 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.32.1-SNAPSHOT + 1.33.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.50.1-alpha-SNAPSHOT + 0.51.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 09c12d2737..54488175d3 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.32.1-SNAPSHOT + 1.33.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.50.1-alpha-SNAPSHOT + 0.51.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index d402df5213..acc06139cb 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.32.0 + 1.33.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.32.0' +compile 'com.google.cloud:google-cloud-core:1.33.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.32.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.33.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4a6b29b6e7..2c70a75aa8 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.32.1-SNAPSHOT + 1.33.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.50.1-alpha-SNAPSHOT + 0.51.0-alpha google-cloud-core From d4b3c8c4875e52d453f6736352073cd75b4ff214 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 8 Jun 2018 10:55:53 -0700 Subject: [PATCH 491/663] bump version for development (#3360) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 3b936ddbde..907e2cb8f6 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.33.0 + 1.33.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.51.0-alpha + 0.51.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 54488175d3..67588134ad 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.33.0 + 1.33.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.51.0-alpha + 0.51.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2c70a75aa8..1c7b376a2c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.33.0 + 1.33.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.51.0-alpha + 0.51.1-alpha-SNAPSHOT google-cloud-core From e281ca86801011ccad22f2c86e1349cec5c3b224 Mon Sep 17 00:00:00 2001 From: Hanzhen Yi <33737743+hzyi-google@users.noreply.github.com> Date: Mon, 11 Jun 2018 16:42:04 -0700 Subject: [PATCH 492/663] Fix zipslip vulnerability (#3366) Thanks to The Snyk security team for bringing this up to our attention. --- .../com/google/cloud/testing/BaseEmulatorHelper.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index b8f7be4487..2f90f59646 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -404,8 +404,13 @@ private Path downloadEmulator() throws IOException { log.fine("Unzipping emulator"); } ZipEntry entry = zipIn.getNextEntry(); - while (entry != null) { - File filePath = new File(emulatorPath.toFile(), entry.getName()); + while (entry != null) { + File filePath = new File(emulatorFolder, entry.getName()); + String canonicalEmulatorFolderPath = emulatorFolder.getCanonicalPath(); + String canonicalFilePath = filePath.getCanonicalPath(); + if (!canonicalFilePath.startsWith(canonicalEmulatorFolderPath + File.separator)) { + throw new IllegalStateException("Entry is outside of the target dir: " + entry.getName()); + } if (!entry.isDirectory()) { extractFile(zipIn, filePath); } else { From ae2a81db98ca9f94cf6c9fc09ebc53f639a5d7ba Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 14 Jun 2018 10:56:35 -0700 Subject: [PATCH 493/663] Release 0.52.0 (#3376) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 907e2cb8f6..0af41aefc3 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.33.1-SNAPSHOT + 1.34.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.51.1-alpha-SNAPSHOT + 0.52.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 67588134ad..2b50d4d287 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.33.1-SNAPSHOT + 1.34.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.51.1-alpha-SNAPSHOT + 0.52.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index acc06139cb..d1ffd22f66 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.33.0 + 1.34.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.33.0' +compile 'com.google.cloud:google-cloud-core:1.34.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.33.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.34.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1c7b376a2c..36c98a694d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.33.1-SNAPSHOT + 1.34.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.51.1-alpha-SNAPSHOT + 0.52.0-alpha google-cloud-core From e0f0ac04e6c0e484b3cf5eddc92a5e84204169b2 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 14 Jun 2018 14:53:09 -0700 Subject: [PATCH 494/663] Bumping to snapshot versions (#3380) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0af41aefc3..396d0b2a0d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.34.0 + 1.34.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.52.0-alpha + 0.52.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 2b50d4d287..e2e136cf5d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.34.0 + 1.34.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.52.0-alpha + 0.52.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 36c98a694d..8cc31601d4 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.34.0 + 1.34.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.52.0-alpha + 0.52.1-alpha-SNAPSHOT google-cloud-core From 49dc0f5ba6a2ca922692453ee2262c7747f65081 Mon Sep 17 00:00:00 2001 From: Hanzhen Yi <33737743+hzyi-google@users.noreply.github.com> Date: Thu, 21 Jun 2018 14:51:15 -0700 Subject: [PATCH 495/663] Release 0.53.0 (#3399) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 396d0b2a0d..2eeb73321c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.34.1-SNAPSHOT + 1.35.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.52.1-alpha-SNAPSHOT + 0.53.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index e2e136cf5d..9cbb116135 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.34.1-SNAPSHOT + 1.35.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.52.1-alpha-SNAPSHOT + 0.53.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index d1ffd22f66..51c68670fe 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.34.0 + 1.35.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.34.0' +compile 'com.google.cloud:google-cloud-core:1.35.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.34.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.35.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 8cc31601d4..92e656a7c7 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.34.1-SNAPSHOT + 1.35.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.52.1-alpha-SNAPSHOT + 0.53.0-alpha google-cloud-core From 41b9befd89f79ff7a1bda8a5851df047be94c296 Mon Sep 17 00:00:00 2001 From: Hanzhen Yi <33737743+hzyi-google@users.noreply.github.com> Date: Fri, 22 Jun 2018 10:36:30 -0700 Subject: [PATCH 496/663] Bump to next snapshot version (#3401) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 2eeb73321c..23c510287e 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.35.0 + 1.35.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.53.0-alpha + 0.53.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 9cbb116135..43cd3a353e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.35.0 + 1.35.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.53.0-alpha + 0.53.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 92e656a7c7..69923cfd37 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.35.0 + 1.35.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.53.0-alpha + 0.53.1-alpha-SNAPSHOT google-cloud-core From fc6123ff0336aeba7bdf6c6cad3979251271c30f Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 28 Jun 2018 10:43:27 -0700 Subject: [PATCH 497/663] Fixing versioning comments for GA clients (#3411) --- google-cloud-core/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 51c68670fe..4c84a37aad 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -58,9 +58,7 @@ Versioning This library follows [Semantic Versioning](http://semver.org/). -It is currently in major version zero (``0.y.z``), which means that anything -may change at any time and the public API should not be considered -stable. +It is currently in major version one (``1.y.z``), which means that the public API should be considered stable. License ------- From 26dc4e9416e3598490b50d1a96eef9b5f98b1c0a Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 29 Jun 2018 11:11:44 -0700 Subject: [PATCH 498/663] Set project id from credentials (#3413) * Add test for setting project id in service options from credentials * Set projectId from credentials if available * Only set the projectId if not explicitly set --- .../java/com/google/cloud/ServiceOptions.java | 6 ++ .../com/google/cloud/ServiceOptionsTest.java | 71 ++++++++++++++++++- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 950c6fd8e4..99f23a8382 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -43,6 +43,7 @@ import com.google.api.gax.rpc.NoHeaderProvider; import com.google.auth.Credentials; import com.google.auth.oauth2.GoogleCredentials; +import com.google.auth.oauth2.ServiceAccountCredentials; import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; @@ -204,6 +205,11 @@ public B setHost(String host) { */ public B setCredentials(Credentials credentials) { this.credentials = checkNotNull(credentials); + // set project id if available + if (this.projectId == null && + credentials instanceof ServiceAccountCredentials) { + this.projectId = ((ServiceAccountCredentials) credentials).getProjectId(); + } return self(); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 49190fc4c2..ee957a625f 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -83,12 +83,51 @@ public class ServiceOptionsTest { + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" + " \"type\": \"service_account\"\n" + "}"; - private static final InputStream JSON_KEY_STREAM = new ByteArrayInputStream(JSON_KEY.getBytes()); private static GoogleCredentials credentials; static { try { - credentials = GoogleCredentials.fromStream(JSON_KEY_STREAM); + InputStream keyStream = new ByteArrayInputStream(JSON_KEY.getBytes()); + credentials = GoogleCredentials.fromStream(keyStream); + } catch (IOException e) { + fail("Couldn't create fake JSON credentials."); + } + } + + private static final String JSON_KEY_PROJECT_ID = + "{\n" + + " \"private_key_id\": \"somekeyid\",\n" + + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" + + "kAgEAAoIBAQC+K2hSuFpAdrJI\\nnCgcDz2M7t7bjdlsadsasad+fvRSW6TjNQZ3p5LLQY1kSZRqBqylRkzteMOyHg" + + "aR\\n0Pmxh3ILCND5men43j3h4eDbrhQBuxfEMalkG92sL+PNQSETY2tnvXryOvmBRwa/\\nQP/9dJfIkIDJ9Fw9N4" + + "Bhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nknddadwkwewcVxHFhcZJO+XWf6ofLUXpRwiTZakGMn8EE1uVa2" + + "LgczOjwWHGi99MFjxSer5m9\\n1tCa3/KEGKiS/YL71JvjwX3mb+cewlkcmweBKZHM2JPTk0ZednFSpVZMtycjkbLa" + + "\\ndYOS8V85AgMBewECggEBAKksaldajfDZDV6nGqbFjMiizAKJolr/M3OQw16K6o3/\\n0S31xIe3sSlgW0+UbYlF" + + "4U8KifhManD1apVSC3csafaspP4RZUHFhtBywLO9pR5c\\nr6S5aLp+gPWFyIp1pfXbWGvc5VY/v9x7ya1VEa6rXvL" + + "sKupSeWAW4tMj3eo/64ge\\nsdaceaLYw52KeBYiT6+vpsnYrEkAHO1fF/LavbLLOFJmFTMxmsNaG0tuiJHgjshB\\" + + "n82DpMCbXG9YcCgI/DbzuIjsdj2JC1cascSP//3PmefWysucBQe7Jryb6NQtASmnv\\nCdDw/0jmZTEjpe4S1lxfHp" + + "lAhHFtdgYTvyYtaLZiVVkCgYEA8eVpof2rceecw/I6\\n5ng1q3Hl2usdWV/4mZMvR0fOemacLLfocX6IYxT1zA1FF" + + "JlbXSRsJMf/Qq39mOR2\\nSpW+hr4jCoHeRVYLgsbggtrevGmILAlNoqCMpGZ6vDmJpq6ECV9olliDvpPgWOP+\\nm" + + "YPDreFBGxWvQrADNbRt2dmGsrsCgYEAyUHqB2wvJHFqdmeBsaacewzV8x9WgmeX\\ngUIi9REwXlGDW0Mz50dxpxcK" + + "CAYn65+7TCnY5O/jmL0VRxU1J2mSWyWTo1C+17L0\\n3fUqjxL1pkefwecxwecvC+gFFYdJ4CQ/MHHXU81Lwl1iWdF" + + "Cd2UoGddYaOF+KNeM\\nHC7cmqra+JsCgYEAlUNywzq8nUg7282E+uICfCB0LfwejuymR93CtsFgb7cRd6ak\\nECR" + + "8FGfCpH8ruWJINllbQfcHVCX47ndLZwqv3oVFKh6pAS/vVI4dpOepP8++7y1u\\ncoOvtreXCX6XqfrWDtKIvv0vjl" + + "HBhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nkndj5uNl5SiuVxHFhcZJO+XWf6ofLUregtevZakGMn8EE1uVa" + + "2AY7eafmoU/nZPT\\n00YB0TBATdCbn/nBSuKDESkhSg9s2GEKQZG5hBmL5uCMfo09z3SfxZIhJdlerreP\\nJ7gSi" + + "dI12N+EZxYd4xIJh/HFDgp7RRO87f+WJkofMQKBgGTnClK1VMaCRbJZPriw\\nEfeFCoOX75MxKwXs6xgrw4W//AYG" + + "GUjDt83lD6AZP6tws7gJ2IwY/qP7+lyhjEqN\\nHtfPZRGFkGZsdaksdlaksd323423d+15/UvrlRSFPNj1tWQmNKk" + + "XyRDW4IG1Oa2p\\nrALStNBx5Y9t0/LQnFI4w3aG\\n-----END PRIVATE KEY-----\\n\",\n" + + " \"project_id\": \"someprojectid\",\n" + + " \"client_email\": \"someclientid@developer.gserviceaccount.com\",\n" + + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" + + " \"type\": \"service_account\"\n" + + "}"; + private static GoogleCredentials credentialsWithProjectId; + + static { + try { + InputStream keyStream = new ByteArrayInputStream(JSON_KEY_PROJECT_ID.getBytes()); + credentialsWithProjectId = GoogleCredentials.fromStream(keyStream); } catch (IOException e) { fail("Couldn't create fake JSON credentials."); } @@ -266,6 +305,32 @@ public void testBuilderNullCredentials() { TestServiceOptions.newBuilder().setCredentials(null).build(); } + @Test + public void testBuilderServiceAccount_setsProjectId() { + TestServiceOptions options = TestServiceOptions.newBuilder() + .setCredentials(credentialsWithProjectId) + .build(); + assertEquals("someprojectid", options.getProjectId()); + } + + @Test + public void testBuilderServiceAccount_explicitSetProjectIdBefore() { + TestServiceOptions options = TestServiceOptions.newBuilder() + .setProjectId("override-project-id") + .setCredentials(credentialsWithProjectId) + .build(); + assertEquals("override-project-id", options.getProjectId()); + } + + @Test + public void testBuilderServiceAccount_explicitSetProjectIdAfter() { + TestServiceOptions options = TestServiceOptions.newBuilder() + .setCredentials(credentialsWithProjectId) + .setProjectId("override-project-id") + .build(); + assertEquals("override-project-id", options.getProjectId()); + } + @Test public void testGetProjectIdRequired() { assertTrue(OPTIONS.projectIdRequired()); @@ -342,7 +407,7 @@ public void testResponseHeaderDoesNotContainMetaDataFlavor() throws Exception { HttpResponse httpResponse = createHttpResponseWithHeader(headers); assertThat(ServiceOptions.headerContainsMetadataFlavor(httpResponse)).isFalse(); } - + private HttpResponse createHttpResponseWithHeader(final Multimap headers) throws Exception { HttpTransport mockHttpTransport = new MockHttpTransport() { @Override From 55ddecc8b28e665a0b36d5b401a4dd0716089e35 Mon Sep 17 00:00:00 2001 From: Hanzhen Yi <33737743+hzyi-google@users.noreply.github.com> Date: Tue, 10 Jul 2018 16:07:13 -0700 Subject: [PATCH 499/663] Fix the error when calling Timestamp.of(Date date) when date is pre epoch (#3434) * Fix the error when calling Timestamp.of(Date date) when date is pre epoch. --- .../src/main/java/com/google/cloud/Timestamp.java | 9 ++++++--- .../test/java/com/google/cloud/TimestampTest.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java index 0c2eca7863..17e26d9c99 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -78,9 +78,12 @@ public static Timestamp ofTimeSecondsAndNanos(long seconds, int nanos) { * @throws IllegalArgumentException if the timestamp is outside the representable range */ public static Timestamp ofTimeMicroseconds(long microseconds) { - long seconds = TimeUnit.MICROSECONDS.toSeconds(microseconds); - int nanos = - (int) TimeUnit.MICROSECONDS.toNanos(microseconds - TimeUnit.SECONDS.toMicros(seconds)); + long seconds = microseconds / 1_000_000; + int nanos = (int)(microseconds % 1_000_000 * 1000); + if (nanos < 0) { + seconds--; + nanos += 1_000_000_000; + } checkArgument( Timestamps.isValid(seconds, nanos), "timestamp out of range: %s, %s", seconds, nanos); return new Timestamp(seconds, nanos); diff --git a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java index 51d2ecb20f..c78f54627c 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java @@ -39,7 +39,9 @@ public class TimestampTest { private static final long TEST_TIME_MICROSECONDS = 10000100L; private static final long TEST_TIME_MILLISECONDS = TimeUnit.SECONDS.toMillis(1444662894L) + TimeUnit.MICROSECONDS.toMillis(1234); + private static final long TEST_TIME_MILLISECONDS_NEGATIVE = -1000L; private static final Date TEST_DATE = new Date(TEST_TIME_MILLISECONDS); + private static final Date TEST_DATE_PRE_EPOCH = new Date(TEST_TIME_MILLISECONDS_NEGATIVE); @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -80,6 +82,19 @@ public void ofDate() { assertThat(timestamp.getNanos()).isEqualTo(expectedNanos); } + @Test + public void ofDatePreEpoch() { + Timestamp timestamp = Timestamp.of(TEST_DATE_PRE_EPOCH); + long expectedSeconds = TEST_TIME_MILLISECONDS_NEGATIVE / 1_000; + int expectedNanos = (int)(TEST_TIME_MILLISECONDS_NEGATIVE % 1_000 * 1000_000); + if (expectedNanos < 0) { + expectedSeconds--; + expectedNanos += 1_000_000_000; + } + assertThat(timestamp.getSeconds()).isEqualTo(expectedSeconds); + assertThat(timestamp.getNanos()).isEqualTo(expectedNanos); + } + @Test public void toDate() { Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 1234 * 1000); From 950c66042c6cec743e9981cbef00aaefc31f89b0 Mon Sep 17 00:00:00 2001 From: Hanzhen Yi <33737743+hzyi-google@users.noreply.github.com> Date: Wed, 11 Jul 2018 15:34:32 -0700 Subject: [PATCH 500/663] Retry IOException: Error writing request body to server to fix the intermittent failure when uploading to gcs(#3433) --- .../java/com/google/cloud/BaseServiceException.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index a0058a2e3f..565ae614f3 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -254,11 +254,13 @@ public static boolean isRetryable(Integer code, String reason, boolean idempoten @InternalApi public static boolean isRetryable(boolean idempotent, IOException exception) { - boolean exceptionIsRetryable = exception instanceof SocketTimeoutException - || exception instanceof SocketException - || (exception instanceof SSLHandshakeException - && !(exception.getCause() instanceof CertificateException)) - || "insufficient data written".equals(exception.getMessage()); + boolean exceptionIsRetryable = + exception instanceof SocketTimeoutException + || exception instanceof SocketException + || (exception instanceof SSLHandshakeException + && !(exception.getCause() instanceof CertificateException)) + || "insufficient data written".equals(exception.getMessage()) + || "Error writing request body to server".equals(exception.getMessage()); return idempotent && exceptionIsRetryable; } From 07f5192ffaf40a535c51cb2009f3e11049bd1081 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 12 Jul 2018 11:57:22 -0700 Subject: [PATCH 501/663] Release 0.54.0 (#3457) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 23c510287e..99061c25bf 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.35.1-SNAPSHOT + 1.36.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.53.1-alpha-SNAPSHOT + 0.54.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 43cd3a353e..cf46db7ea4 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.35.1-SNAPSHOT + 1.36.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.53.1-alpha-SNAPSHOT + 0.54.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 4c84a37aad..63cf25845a 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.35.0 + 1.36.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.35.0' +compile 'com.google.cloud:google-cloud-core:1.36.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.35.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.36.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 69923cfd37..6c16181abd 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.35.1-SNAPSHOT + 1.36.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.53.1-alpha-SNAPSHOT + 0.54.0-alpha google-cloud-core From 6db36275b3e43d988e084f8df0e6730558057613 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 12 Jul 2018 12:47:20 -0700 Subject: [PATCH 502/663] Bumping to snapshot versions (#3463) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 99061c25bf..e0b91e14f7 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.36.0 + 1.36.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.54.0-alpha + 0.54.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index cf46db7ea4..6028f8b8d1 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.36.0 + 1.36.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.54.0-alpha + 0.54.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6c16181abd..a631b19139 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.36.0 + 1.36.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.54.0-alpha + 0.54.1-alpha-SNAPSHOT google-cloud-core From 93746422000ac42d18105455d330a386ab68a3ed Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Thu, 19 Jul 2018 18:22:07 -0700 Subject: [PATCH 503/663] Release 0.55.0 (#3485) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index e0b91e14f7..f79e03cd84 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.36.1-SNAPSHOT + 1.37.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.54.1-alpha-SNAPSHOT + 0.55.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 6028f8b8d1..e9fd510cc7 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.36.1-SNAPSHOT + 1.37.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.54.1-alpha-SNAPSHOT + 0.55.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 63cf25845a..d8729de5e7 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.36.0 + 1.37.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.36.0' +compile 'com.google.cloud:google-cloud-core:1.37.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.36.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.37.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a631b19139..4b09fc9b05 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.36.1-SNAPSHOT + 1.37.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.54.1-alpha-SNAPSHOT + 0.55.0-alpha google-cloud-core From 55312e1f209683aef4683051ac472f6c8c534e1f Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 20 Jul 2018 11:26:20 -0700 Subject: [PATCH 504/663] bump version for development (#3486) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index f79e03cd84..d6afbdf1b2 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.37.0 + 1.37.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.0-alpha + 0.55.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index e9fd510cc7..0572c68ef1 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.37.0 + 1.37.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.0-alpha + 0.55.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4b09fc9b05..89fff1c302 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.37.0 + 1.37.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.0-alpha + 0.55.1-alpha-SNAPSHOT google-cloud-core From bd788b96f4df5be464e480ba0a86b780303625ef Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 20 Jul 2018 12:23:34 -0700 Subject: [PATCH 505/663] Release 0.55.1 (#3489) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d6afbdf1b2..02c61599b6 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.37.1-SNAPSHOT + 1.37.1 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.1-alpha-SNAPSHOT + 0.55.1-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 0572c68ef1..b20a4f32c3 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.37.1-SNAPSHOT + 1.37.1 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.1-alpha-SNAPSHOT + 0.55.1-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index d8729de5e7..3baa3a99e2 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.37.0 + 1.37.1 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.37.0' +compile 'com.google.cloud:google-cloud-core:1.37.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.37.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.37.1" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 89fff1c302..4f8d97b33a 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.37.1-SNAPSHOT + 1.37.1 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.1-alpha-SNAPSHOT + 0.55.1-alpha google-cloud-core From dbfcfe51fc764a4f9f5168a445586fb8ab5c15a1 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 20 Jul 2018 13:32:48 -0700 Subject: [PATCH 506/663] bump version for development (#3490) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 02c61599b6..a5b74748dd 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.37.1 + 1.37.2-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.1-alpha + 0.55.2-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index b20a4f32c3..e1e218082e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.37.1 + 1.37.2-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.1-alpha + 0.55.2-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4f8d97b33a..a54d1f5486 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.37.1 + 1.37.2-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.1-alpha + 0.55.2-alpha-SNAPSHOT google-cloud-core From 746c37670da894f019d0fe3bd6a60d7eef22cd01 Mon Sep 17 00:00:00 2001 From: Hanzhen Yi <33737743+hzyi-google@users.noreply.github.com> Date: Tue, 24 Jul 2018 11:21:16 -0700 Subject: [PATCH 507/663] Fix pom urls (#3499) --- google-cloud-core-grpc/pom.xml | 2 +- google-cloud-core-http/pom.xml | 2 +- google-cloud-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index a5b74748dd..7b007eb15e 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -5,7 +5,7 @@ 1.37.2-SNAPSHOT jar Google Cloud Core gRPC - https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc + https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc Core gRPC module for the google-cloud. diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index e1e218082e..bfd68f3d5e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -5,7 +5,7 @@ 1.37.2-SNAPSHOT jar Google Cloud Core HTTP - https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http + https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http Core http module for the google-cloud. diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a54d1f5486..60fed4a2af 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -5,7 +5,7 @@ 1.37.2-SNAPSHOT jar Google Cloud Core - https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core + https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core Core module for the google-cloud. From 037a6b95aa0f4e2b5bb11c555a9fa0a9cb3f9ccf Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 1 Aug 2018 15:23:45 -0700 Subject: [PATCH 508/663] Release 0.56.0 (#3521) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 7b007eb15e..ab054f024b 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.37.2-SNAPSHOT + 1.38.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.2-alpha-SNAPSHOT + 0.56.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index bfd68f3d5e..1a9770560a 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.37.2-SNAPSHOT + 1.38.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.2-alpha-SNAPSHOT + 0.56.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 3baa3a99e2..f1c8492b71 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.37.1 + 1.38.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.37.1' +compile 'com.google.cloud:google-cloud-core:1.38.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.37.1" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.38.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 60fed4a2af..64e039638d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.37.2-SNAPSHOT + 1.38.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.55.2-alpha-SNAPSHOT + 0.56.0-alpha google-cloud-core From 9898ce3bfea27e204e1c3f82809b4a19422b5e3e Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Wed, 1 Aug 2018 16:26:30 -0700 Subject: [PATCH 509/663] Bumping to snapshot versions (#3523) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ab054f024b..76fef2f35f 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.38.0 + 1.38.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.56.0-alpha + 0.56.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 1a9770560a..568e491fd3 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.38.0 + 1.38.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.56.0-alpha + 0.56.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 64e039638d..9ce88cf933 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.38.0 + 1.38.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.56.0-alpha + 0.56.1-alpha-SNAPSHOT google-cloud-core From 3a8f4a30379f2f099bb1274c364454c855020609 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 9 Aug 2018 16:25:03 -0700 Subject: [PATCH 510/663] Bump versions to 1.39.0/0.57.0 (#3548) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 76fef2f35f..95c6119312 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.38.1-SNAPSHOT + 1.39.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.56.1-alpha-SNAPSHOT + 0.57.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 568e491fd3..faf948fdd9 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.38.1-SNAPSHOT + 1.39.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.56.1-alpha-SNAPSHOT + 0.57.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f1c8492b71..d595f363e1 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.38.0 + 1.39.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.38.0' +compile 'com.google.cloud:google-cloud-core:1.39.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.38.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.39.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9ce88cf933..c7c8d2c8ba 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.38.1-SNAPSHOT + 1.39.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.56.1-alpha-SNAPSHOT + 0.57.0-alpha google-cloud-core From 621e1e4f8050330df7dffe2b535dee8d4d88c5f7 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 10 Aug 2018 10:13:44 -0700 Subject: [PATCH 511/663] Bump to snapshot (#3553) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 95c6119312..0b3a22d464 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.39.0 + 1.39.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.57.0-alpha + 0.57.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index faf948fdd9..d7e2dc8894 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.39.0 + 1.39.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.57.0-alpha + 0.57.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c7c8d2c8ba..88ee6a411f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.39.0 + 1.39.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.57.0-alpha + 0.57.1-alpha-SNAPSHOT google-cloud-core From f92b6c07d1c64ad9aa942e6ba93be6e02a3e7f62 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Wed, 15 Aug 2018 15:54:35 -0700 Subject: [PATCH 512/663] Release 0.58.0 and 1.40.0 (#3565) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0b3a22d464..2f88038da4 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.39.1-SNAPSHOT + 1.40.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.57.1-alpha-SNAPSHOT + 0.58.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index d7e2dc8894..1884531357 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.39.1-SNAPSHOT + 1.40.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.57.1-alpha-SNAPSHOT + 0.58.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index d595f363e1..363a648aaf 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.39.0 + 1.40.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.39.0' +compile 'com.google.cloud:google-cloud-core:1.40.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.39.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.40.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 88ee6a411f..2ffb1895fb 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.39.1-SNAPSHOT + 1.40.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.57.1-alpha-SNAPSHOT + 0.58.0-alpha google-cloud-core From 46a60ac99b9bbb120f377a167673f6ee25686cfb Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Wed, 15 Aug 2018 17:23:45 -0700 Subject: [PATCH 513/663] Bump version to 0.58.1-SNAPSHOT and 1.40.1-SNAPSHOT for development (#3566) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 2f88038da4..c0dbf29d9b 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.40.0 + 1.40.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.58.0-alpha + 0.58.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 1884531357..0e88111587 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.40.0 + 1.40.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.58.0-alpha + 0.58.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2ffb1895fb..f0a6e8afd0 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.40.0 + 1.40.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.58.0-alpha + 0.58.1-alpha-SNAPSHOT google-cloud-core From 6378356f03140a2fe6ca128f7ae9dc9c05ec0136 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Wed, 22 Aug 2018 16:39:03 -0700 Subject: [PATCH 514/663] release 0.59.0 (#3598) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index c0dbf29d9b..d174317d5a 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.40.1-SNAPSHOT + 1.41.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.58.1-alpha-SNAPSHOT + 0.59.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 0e88111587..3aba07b008 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.40.1-SNAPSHOT + 1.41.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.58.1-alpha-SNAPSHOT + 0.59.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 363a648aaf..0b4a23cb92 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.40.0 + 1.41.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.40.0' +compile 'com.google.cloud:google-cloud-core:1.41.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.40.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.41.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f0a6e8afd0..1403c9ece3 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.40.1-SNAPSHOT + 1.41.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.58.1-alpha-SNAPSHOT + 0.59.0-alpha google-cloud-core From ad47a2779cefeb6f0ac13e3e506d7523da8e36a1 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Thu, 23 Aug 2018 19:32:16 -0700 Subject: [PATCH 515/663] bump version for development (#3599) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d174317d5a..a04b6c16ac 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.41.0 + 1.41.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.59.0-alpha + 0.59.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 3aba07b008..88b0c4262e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.41.0 + 1.41.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.59.0-alpha + 0.59.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1403c9ece3..4e4d87a258 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.41.0 + 1.41.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.59.0-alpha + 0.59.1-alpha-SNAPSHOT google-cloud-core From e332030b0327fe8c76f719a50e0ecbdd183078f2 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 27 Aug 2018 13:48:10 -0400 Subject: [PATCH 516/663] upgrade auth version (#3606) * upgrade auth version * jdk5 no longer comes in with oauth --- google-cloud-core-http/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 88b0c4262e..ae32dfa6c7 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -29,12 +29,6 @@ com.google.auth google-auth-library-oauth2-http - - - com.google.guava - guava-jdk5 - - com.google.http-client From da0a4a35788e566b55f8a91c853444486cceb9bc Mon Sep 17 00:00:00 2001 From: Hanzhen Yi <33737743+hzyi-google@users.noreply.github.com> Date: Thu, 30 Aug 2018 15:43:20 -0700 Subject: [PATCH 517/663] Release 0.60.0 (#3623) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index a04b6c16ac..0a38bf6e72 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.41.1-SNAPSHOT + 1.42.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.59.1-alpha-SNAPSHOT + 0.60.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index ae32dfa6c7..38ba64b26c 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.41.1-SNAPSHOT + 1.42.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.59.1-alpha-SNAPSHOT + 0.60.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 0b4a23cb92..0fc384d6b7 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.41.0 + 1.42.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.41.0' +compile 'com.google.cloud:google-cloud-core:1.42.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.41.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.42.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4e4d87a258..d3164b6009 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.41.1-SNAPSHOT + 1.42.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.59.1-alpha-SNAPSHOT + 0.60.0-alpha google-cloud-core From cd9ccd05265426693ba780c350182bd2f20a155a Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 6 Sep 2018 16:26:48 -0700 Subject: [PATCH 518/663] Release 0.61.0/1.43.0 (#3653) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0a38bf6e72..1dbf962aa3 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.42.0 + 1.43.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.60.0-alpha + 0.61.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 38ba64b26c..c4699e6560 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.42.0 + 1.43.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.60.0-alpha + 0.61.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 0fc384d6b7..f61ec4a213 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.42.0 + 1.43.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.42.0' +compile 'com.google.cloud:google-cloud-core:1.43.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.42.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.43.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d3164b6009..86f4bfb828 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.42.0 + 1.43.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.60.0-alpha + 0.61.0-alpha google-cloud-core From 8e4cce09b9444eec2e631785356b4dd2df0ae272 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 7 Sep 2018 10:14:04 -0700 Subject: [PATCH 519/663] Bump to snapshot version for development (#3656) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 1dbf962aa3..ce253199dd 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.43.0 + 1.43.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.61.0-alpha + 0.61.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index c4699e6560..51a6fc5bd7 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.43.0 + 1.43.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.61.0-alpha + 0.61.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 86f4bfb828..a9f6d5fca5 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.43.0 + 1.43.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.61.0-alpha + 0.61.1-alpha-SNAPSHOT google-cloud-core From b747e4b1bcf1d84cdfbe2f5e4adfe386c7737bec Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 13 Sep 2018 09:47:56 -0700 Subject: [PATCH 520/663] Release 1.44.0/0.62.0 (#3677) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ce253199dd..94de3c333a 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.43.1-SNAPSHOT + 1.44.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.61.1-alpha-SNAPSHOT + 0.62.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 51a6fc5bd7..25840fb0fb 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.43.1-SNAPSHOT + 1.44.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.61.1-alpha-SNAPSHOT + 0.62.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f61ec4a213..74cc343290 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.43.0 + 1.44.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.43.0' +compile 'com.google.cloud:google-cloud-core:1.44.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.43.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.44.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a9f6d5fca5..6a299c0817 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.43.1-SNAPSHOT + 1.44.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.61.1-alpha-SNAPSHOT + 0.62.0-alpha google-cloud-core From a17b6aaba46ef85e0c310f529d9b75ecec3d6b91 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Thu, 13 Sep 2018 10:59:16 -0700 Subject: [PATCH 521/663] Bump to next snapshot versions (#3679) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 94de3c333a..7ebd0db023 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.44.0 + 1.44.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.62.0-alpha + 0.62.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 25840fb0fb..a97dff986e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.44.0 + 1.44.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.62.0-alpha + 0.62.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6a299c0817..3415d5dc2d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.44.0 + 1.44.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.62.0-alpha + 0.62.1-alpha-SNAPSHOT google-cloud-core From c53fcf39128300b6c456ebe21be1b4978756b48b Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 20 Sep 2018 13:37:58 -0700 Subject: [PATCH 522/663] Release 1.45.0/0.63.0 (#3710) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 7ebd0db023..23f1dffe4b 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.44.1-SNAPSHOT + 1.45.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.62.1-alpha-SNAPSHOT + 0.63.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index a97dff986e..9eb516f2cf 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.44.1-SNAPSHOT + 1.45.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.62.1-alpha-SNAPSHOT + 0.63.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 74cc343290..e0f87409f7 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.44.0 + 1.45.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.44.0' +compile 'com.google.cloud:google-cloud-core:1.45.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.44.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.45.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3415d5dc2d..3ce5884098 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.44.1-SNAPSHOT + 1.45.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.62.1-alpha-SNAPSHOT + 0.63.0-alpha google-cloud-core From 9de4f7d9364421669bcc5d53d26e996c6b385eec Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 20 Sep 2018 17:22:25 -0700 Subject: [PATCH 523/663] Bump version to 0.63.1-beta-SNAPSHOT (#3714) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 23f1dffe4b..8008aa98b1 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.45.0 + 1.45.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.63.0-alpha + 0.63.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 9eb516f2cf..852a1d1eb4 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.45.0 + 1.45.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.63.0-alpha + 0.63.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3ce5884098..cc4717aee1 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.45.0 + 1.45.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.63.0-alpha + 0.63.1-alpha-SNAPSHOT google-cloud-core From b376b3dd6aa2036766606451ea01255a767f2278 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Tue, 25 Sep 2018 10:11:18 -0700 Subject: [PATCH 524/663] Add retries to downloadEmulator() to mitigate transient network issues (#3719) * Add retries to downloadEmulator() to mitigate transient network issues --- .../cloud/testing/BaseEmulatorHelper.java | 14 ++++- .../cloud/testing/BaseEmulatorHelperTest.java | 56 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index 2f90f59646..841d7e3e07 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -16,7 +16,10 @@ package com.google.cloud.testing; +import com.google.api.core.CurrentMillisClock; import com.google.api.core.InternalApi; +import com.google.cloud.ExceptionHandler; +import com.google.cloud.RetryHelper; import com.google.cloud.ServiceOptions; import com.google.common.io.CharStreams; import com.google.common.util.concurrent.SettableFuture; @@ -46,6 +49,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -366,7 +370,15 @@ public boolean isAvailable() { @Override public void start() throws IOException { - Path emulatorPath = downloadEmulator(); + ExceptionHandler retryOnAnythingExceptionHandler = ExceptionHandler.newBuilder().retryOn(Exception.class).build(); + + Path emulatorPath = RetryHelper.runWithRetries(new Callable() { + @Override + public Path call() throws IOException { + return downloadEmulator(); + } + }, ServiceOptions.getDefaultRetrySettings(), retryOnAnythingExceptionHandler, + CurrentMillisClock.getDefaultClock()); process = CommandWrapper.create() .setCommand(commandText) .setDirectory(emulatorPath) diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java index e8f5ed565f..7cb4a4ab07 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java @@ -20,9 +20,15 @@ import com.google.cloud.ServiceOptions; import com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner; import com.google.common.collect.ImmutableList; + import java.io.ByteArrayInputStream; +import java.io.EOFException; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; import java.util.List; import java.util.concurrent.TimeoutException; import java.util.logging.Logger; @@ -96,6 +102,41 @@ public void testEmulatorHelper() throws IOException, InterruptedException, Timeo EasyMock.verify(); } + @Test + public void testEmulatorHelperDownloadWithRetries() throws IOException, InterruptedException, TimeoutException { + String mockExternalForm = "mockExternalForm"; + String mockInputStream = "mockInputStream"; + String mockProtocol = "mockProtocol"; + String mockFile = "mockFile"; + String mockCommandText = "mockCommandText"; + + MockURLStreamHandler mockURLStreamHandler = EasyMock.createMock(MockURLStreamHandler.class); + URLConnection mockURLConnection = EasyMock.mock(URLConnection.class); + + EasyMock.expect(mockURLStreamHandler.toExternalForm(EasyMock.anyObject(URL.class))) + .andReturn(mockExternalForm).anyTimes(); + EasyMock.expect(mockURLConnection.getInputStream()) + .andReturn(new ByteArrayInputStream(mockInputStream.getBytes())).anyTimes(); + EasyMock.expect(mockURLStreamHandler.openConnection(EasyMock.anyObject(URL.class))) + .andThrow(new EOFException()).times(1); + EasyMock.expect(mockURLStreamHandler.openConnection(EasyMock.anyObject(URL.class))) + .andReturn(mockURLConnection).times(1); + EasyMock.replay(mockURLStreamHandler, mockURLConnection); + + URL url = new URL(mockProtocol, null, 0, mockFile, mockURLStreamHandler); + BaseEmulatorHelper.DownloadableEmulatorRunner runner = + new BaseEmulatorHelper.DownloadableEmulatorRunner(ImmutableList.of(mockCommandText), url, null); + + File cachedFile = new File(System.getProperty("java.io.tmpdir"), mockExternalForm); + cachedFile.delete(); //Clear the cached version so we're always testing the download + + runner.start(); + + EasyMock.verify(); + + cachedFile.delete(); //Cleanup + } + @Test public void testEmulatorHelperMultipleRunners() throws IOException, InterruptedException, TimeoutException { Process process = EasyMock.createStrictMock(Process.class); @@ -117,4 +158,19 @@ public void testEmulatorHelperMultipleRunners() throws IOException, InterruptedE helper.stop(Duration.ofMinutes(1)); EasyMock.verify(); } + + /** + * URLStreamHandler has a protected method which needs to be mocked, so we need our own implementation in this package + */ + private class MockURLStreamHandler extends URLStreamHandler { + @Override + protected URLConnection openConnection(URL u) throws IOException { + return null; + } + + @Override + protected String toExternalForm(URL u) { + return null; + } + } } From 71f7e99c33cf08e2a8a971174ab2f1856f73ed9a Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Tue, 25 Sep 2018 10:49:00 -0700 Subject: [PATCH 525/663] Remove dependency on vulnerable version of jackson, upgrade to jackson2 (#3724) --- google-cloud-core-http/pom.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 852a1d1eb4..f9ec6fae85 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -66,17 +66,6 @@ - - com.google.http-client - google-http-client-jackson - compile - - - guava-jdk5 - com.google.guava - - - com.google.http-client google-http-client-jackson2 From 3561bf747c650313da27ced26de8e92b66d1a3db Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 27 Sep 2018 12:20:32 -0700 Subject: [PATCH 526/663] Release 1.46.0/0.64.0 (#3742) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 8008aa98b1..6441563b2d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.45.1-SNAPSHOT + 1.46.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.63.1-alpha-SNAPSHOT + 0.64.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index f9ec6fae85..f0689175f9 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.45.1-SNAPSHOT + 1.46.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.63.1-alpha-SNAPSHOT + 0.64.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index e0f87409f7..cdf67e3be3 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.45.0 + 1.46.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.45.0' +compile 'com.google.cloud:google-cloud-core:1.46.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.45.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.46.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index cc4717aee1..3692027028 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.45.1-SNAPSHOT + 1.46.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.63.1-alpha-SNAPSHOT + 0.64.0-alpha google-cloud-core From 285905b0751fedc52acee866ecfc02b26ec87fd5 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 27 Sep 2018 13:54:34 -0700 Subject: [PATCH 527/663] Bump to next snapshot version (#3744) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 6441563b2d..905a4810c4 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.46.0 + 1.46.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.64.0-alpha + 0.64.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index f0689175f9..e51a1105e0 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.46.0 + 1.46.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.64.0-alpha + 0.64.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3692027028..2464c2de47 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.46.0 + 1.46.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.64.0-alpha + 0.64.1-alpha-SNAPSHOT google-cloud-core From 34f5f7deab53cbd1115d08e58e11011f970515bb Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 4 Oct 2018 10:46:45 -0700 Subject: [PATCH 528/663] Release 1.47.0/0.65.0 (#3767) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 905a4810c4..eff0492e94 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.46.1-SNAPSHOT + 1.47.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.64.1-alpha-SNAPSHOT + 0.65.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index e51a1105e0..4b8603390d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.46.1-SNAPSHOT + 1.47.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.64.1-alpha-SNAPSHOT + 0.65.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index cdf67e3be3..340271f5ef 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.46.0 + 1.47.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.46.0' +compile 'com.google.cloud:google-cloud-core:1.47.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.46.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.47.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2464c2de47..c8461d5ae5 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.46.1-SNAPSHOT + 1.47.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.64.1-alpha-SNAPSHOT + 0.65.0-alpha google-cloud-core From 1d831e44363b8340115cc9545fb6b062050f3d02 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 4 Oct 2018 11:25:08 -0700 Subject: [PATCH 529/663] Bump to next snapshot version (#3768) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index eff0492e94..ee476cdaca 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.47.0 + 1.47.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.65.0-alpha + 0.65.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 4b8603390d..1c0391f18c 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.47.0 + 1.47.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.65.0-alpha + 0.65.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c8461d5ae5..d60deae6d4 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.47.0 + 1.47.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.65.0-alpha + 0.65.1-alpha-SNAPSHOT google-cloud-core From 69cc2322083bcc7b090f42526aedb89c9db3a76b Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 4 Oct 2018 13:18:15 -0700 Subject: [PATCH 530/663] Remove CircleCI status, coveralls, and version eye badges (#3771) --- google-cloud-core/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 340271f5ef..909955666a 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -3,11 +3,9 @@ Google Cloud Java Client -- Core This module provides common functionality required by service-specific modules of this library. -[![CircleCI](https://circleci.com/gh/GoogleCloudPlatform/google-cloud-java/tree/master.svg?style=shield)](https://circleci.com/gh/GoogleCloudPlatform/google-cloud-java/tree/master) -[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/google-cloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/google-cloud-java?branch=master) +[![Kokoro CI](http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/master.svg)](http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/master.html) [![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg) [![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) -[![Dependency Status](https://www.versioneye.com/user/projects/58fe4c8d6ac171426c414772/badge.svg?style=flat)](https://www.versioneye.com/user/projects/58fe4c8d6ac171426c414772) - [Homepage](https://googlecloudplatform.github.io/google-cloud-java/) - [API Documentation](https://googlecloudplatform.github.io/google-cloud-java/apidocs/index.html?com/google/cloud/package-summary.html) From 4c7a2f78f9a04b77641e9339ae76a6ac58da600d Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 5 Oct 2018 18:19:23 -0700 Subject: [PATCH 531/663] Release google-cloud-java v0.66.0 (#3782) * Release v0.66.0 * Fix javadoc in firestore CollectionReference --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ee476cdaca..9178de19ac 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.47.1-SNAPSHOT + 1.48.0 jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.65.1-alpha-SNAPSHOT + 0.66.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 1c0391f18c..a3971d7ae5 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.47.1-SNAPSHOT + 1.48.0 jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.65.1-alpha-SNAPSHOT + 0.66.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 909955666a..cee794fec1 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.47.0 + 1.48.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.47.0' +compile 'com.google.cloud:google-cloud-core:1.48.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.47.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.48.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d60deae6d4..1032abfa50 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.47.1-SNAPSHOT + 1.48.0 jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.65.1-alpha-SNAPSHOT + 0.66.0-alpha google-cloud-core From 073a5a952212dbe32ec6ec2b3c35edd72d3fa35c Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Sat, 6 Oct 2018 11:45:23 -0700 Subject: [PATCH 532/663] Release v0.66.1-SNAPSHOT (#3784) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 9178de19ac..45e63fc923 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.48.0 + 1.48.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.66.0-alpha + 0.66.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index a3971d7ae5..6cb0bb748a 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.48.0 + 1.48.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.66.0-alpha + 0.66.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1032abfa50..246a5090da 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.48.0 + 1.48.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.66.0-alpha + 0.66.1-alpha-SNAPSHOT google-cloud-core From 06f6c8f727cc58958c359d342ebf0461e829fffa Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 10 Oct 2018 12:06:24 -0700 Subject: [PATCH 533/663] Fix urls from GoogleCloudPlatform org to googleapis org (#3793) * Fix urls from GoogleCloudPlatform org to googleapis org * Fix typo --- google-cloud-core-grpc/pom.xml | 2 +- google-cloud-core-http/pom.xml | 2 +- google-cloud-core/README.md | 14 +++++++------- google-cloud-core/pom.xml | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 45e63fc923..dc7ae79daf 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -5,7 +5,7 @@ 1.48.1-SNAPSHOT jar Google Cloud Core gRPC - https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc + https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc Core gRPC module for the google-cloud. diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 6cb0bb748a..400624e76a 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -5,7 +5,7 @@ 1.48.1-SNAPSHOT jar Google Cloud Core HTTP - https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http + https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http Core http module for the google-cloud. diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index cee794fec1..d22edb3d0d 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -7,8 +7,8 @@ This module provides common functionality required by service-specific modules o [![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg) [![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) -- [Homepage](https://googlecloudplatform.github.io/google-cloud-java/) -- [API Documentation](https://googlecloudplatform.github.io/google-cloud-java/apidocs/index.html?com/google/cloud/package-summary.html) +- [Homepage](https://googleapis.github.io/google-cloud-java/) +- [API Documentation](https://googleapis.github.io/google-cloud-java/apidocs/index.html?com/google/cloud/package-summary.html) Quickstart ---------- @@ -35,7 +35,7 @@ libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.48.0" Troubleshooting --------------- -To get help, follow the instructions in the [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting). +To get help, follow the instructions in the [shared Troubleshooting document](https://github.com/googleapis/google-cloud-common/blob/master/troubleshooting/readme.md#troubleshooting). Java Versions ------------- @@ -47,7 +47,7 @@ Contributing Contributions to this library are always welcome and highly encouraged. -See `google-cloud`'s [CONTRIBUTING] documentation and the [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started. +See `google-cloud`'s [CONTRIBUTING] documentation and the [shared documentation](https://github.com/googleapis/google-cloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information. @@ -64,7 +64,7 @@ License Apache 2.0 - See [LICENSE] for more information. -[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/CONTRIBUTING.md -[code-of-conduct]:https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct -[LICENSE]: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/LICENSE +[CONTRIBUTING]:https://github.com/googleapis/google-cloud-java/blob/master/CONTRIBUTING.md +[code-of-conduct]:https://github.com/googleapis/google-cloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct +[LICENSE]: https://github.com/googleapis/google-cloud-java/blob/master/LICENSE [cloud-platform]: https://cloud.google.com/ diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 246a5090da..f740ddc7e3 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -5,7 +5,7 @@ 1.48.1-SNAPSHOT jar Google Cloud Core - https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core + https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core Core module for the google-cloud. From 54fe3fe9018e4ff3fac86910725d887cca3406f5 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 11 Oct 2018 09:50:15 -0700 Subject: [PATCH 534/663] Release v0.67.0 (#3807) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index dc7ae79daf..00d2ed6500 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.48.1-SNAPSHOT + 1.49.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.66.1-alpha-SNAPSHOT + 0.67.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 400624e76a..2030c036f1 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.48.1-SNAPSHOT + 1.49.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.66.1-alpha-SNAPSHOT + 0.67.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index d22edb3d0d..30db66189b 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.48.0 + 1.49.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.48.0' +compile 'com.google.cloud:google-cloud-core:1.49.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.48.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.49.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f740ddc7e3..d6dfc8ca67 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.48.1-SNAPSHOT + 1.49.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.66.1-alpha-SNAPSHOT + 0.67.0-alpha google-cloud-core From 01eb76859fd0d2c1aa7ed7a5bd11e11afd6d95d3 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 11 Oct 2018 13:31:41 -0700 Subject: [PATCH 535/663] Bump next snapshot (#3810) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 00d2ed6500..6eb3118a54 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.49.0 + 1.49.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.67.0-alpha + 0.67.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 2030c036f1..17edd25394 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.49.0 + 1.49.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.67.0-alpha + 0.67.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d6dfc8ca67..4870789a80 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.49.0 + 1.49.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.67.0-alpha + 0.67.1-alpha-SNAPSHOT google-cloud-core From 4cec401b7051d15b84e7a87daf057f7b4d6c137c Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 25 Oct 2018 12:18:15 -0700 Subject: [PATCH 536/663] Release v0.68.0 (#3857) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 6eb3118a54..4e3ed5400e 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.49.1-SNAPSHOT + 1.50.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.67.1-alpha-SNAPSHOT + 0.68.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 17edd25394..098cc6a2e0 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.49.1-SNAPSHOT + 1.50.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.67.1-alpha-SNAPSHOT + 0.68.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 30db66189b..f225b88555 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.49.0 + 1.50.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.49.0' +compile 'com.google.cloud:google-cloud-core:1.50.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.49.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.50.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4870789a80..cd3584ecea 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.49.1-SNAPSHOT + 1.50.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.67.1-alpha-SNAPSHOT + 0.68.0-alpha google-cloud-core From 4d9d61e85ae11135df9d125ff91e12ad4fb457ce Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 25 Oct 2018 15:46:37 -0700 Subject: [PATCH 537/663] Bump next snapshot (#3862) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4e3ed5400e..70d5333bfb 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.50.0 + 1.50.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.68.0-alpha + 0.68.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 098cc6a2e0..55e7c2022e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.50.0 + 1.50.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.68.0-alpha + 0.68.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index cd3584ecea..18d48f6b95 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.50.0 + 1.50.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.68.0-alpha + 0.68.1-alpha-SNAPSHOT google-cloud-core From 8bba797568d9934be4c266bf3dcaf328ebf52460 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 1 Nov 2018 13:47:10 -0700 Subject: [PATCH 538/663] Release v0.69.0 (#3890) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 70d5333bfb..a8e3e51949 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.50.1-SNAPSHOT + 1.51.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.68.1-alpha-SNAPSHOT + 0.69.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 55e7c2022e..eb97d9e61b 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.50.1-SNAPSHOT + 1.51.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.68.1-alpha-SNAPSHOT + 0.69.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index f225b88555..81c52fc6e2 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.50.0 + 1.51.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.50.0' +compile 'com.google.cloud:google-cloud-core:1.51.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.50.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.51.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 18d48f6b95..f641464f4c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.50.1-SNAPSHOT + 1.51.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.68.1-alpha-SNAPSHOT + 0.69.0-alpha google-cloud-core From 5f61c2101289cf63fd115469072037762432f2c7 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 1 Nov 2018 14:19:43 -0700 Subject: [PATCH 539/663] Bump next snapshot (#3892) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index a8e3e51949..d1bebe0c2c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.51.0 + 1.51.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.69.0-alpha + 0.69.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index eb97d9e61b..63af872b1c 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.51.0 + 1.51.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.69.0-alpha + 0.69.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f641464f4c..df9fa24db8 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.51.0 + 1.51.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.69.0-alpha + 0.69.1-alpha-SNAPSHOT google-cloud-core From 57115b93d822f696b141f88b4d0ae1d2928d6ef1 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 7 Nov 2018 15:33:45 -0800 Subject: [PATCH 540/663] Release google-cloud-java v0.70.0 (#3921) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d1bebe0c2c..95983b1c55 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.51.1-SNAPSHOT + 1.52.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.69.1-alpha-SNAPSHOT + 0.70.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 63af872b1c..24ff3f0c8e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.51.1-SNAPSHOT + 1.52.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.69.1-alpha-SNAPSHOT + 0.70.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 81c52fc6e2..74cef784d2 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.51.0 + 1.52.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.51.0' +compile 'com.google.cloud:google-cloud-core:1.52.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.51.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.52.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index df9fa24db8..6b4b638100 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.51.1-SNAPSHOT + 1.52.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.69.1-alpha-SNAPSHOT + 0.70.0-alpha google-cloud-core From 7b39a279108097c5c6bd356bb3d5d060b910ba11 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 7 Nov 2018 15:36:43 -0800 Subject: [PATCH 541/663] Bump next snapshot (#3922) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 95983b1c55..d72622d311 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.52.0 + 1.52.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.70.0-alpha + 0.70.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 24ff3f0c8e..650cf74235 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.52.0 + 1.52.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.70.0-alpha + 0.70.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6b4b638100..4ca795db6d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.52.0 + 1.52.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.70.0-alpha + 0.70.1-alpha-SNAPSHOT google-cloud-core From b48d18b84a0ba13e738b497f3e76823f27a253a2 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 15 Nov 2018 16:52:33 -0800 Subject: [PATCH 542/663] Release v0.71.0 (#3978) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d72622d311..70b451a19e 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.52.1-SNAPSHOT + 1.53.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.70.1-alpha-SNAPSHOT + 0.71.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 650cf74235..4730f3111d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.52.1-SNAPSHOT + 1.53.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.70.1-alpha-SNAPSHOT + 0.71.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 74cef784d2..674ac3916b 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.52.0 + 1.53.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.52.0' +compile 'com.google.cloud:google-cloud-core:1.53.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.52.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.53.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4ca795db6d..27db3e8879 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.52.1-SNAPSHOT + 1.53.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.70.1-alpha-SNAPSHOT + 0.71.0-alpha google-cloud-core From 37ffad713e12992e7b8841cf6b0b3b4c566aa382 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 16 Nov 2018 09:43:35 -0800 Subject: [PATCH 543/663] Bump next snapshot (#3981) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 70b451a19e..5264b77d35 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.53.0 + 1.53.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.71.0-alpha + 0.71.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 4730f3111d..fea01bc994 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.53.0 + 1.53.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.71.0-alpha + 0.71.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 27db3e8879..6f69bc1680 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.53.0 + 1.53.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.71.0-alpha + 0.71.1-alpha-SNAPSHOT google-cloud-core From 21543194b1049efa7f42c55d66d412c0b8cc0f9a Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Thu, 29 Nov 2018 00:56:38 +0530 Subject: [PATCH 544/663] Add missing fields on MonitoredResourceUtil (#3887) * added missing fields #3559 * Fix indentation --- .../src/main/java/com/google/cloud/MetadataConfig.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java index 9b1ee3ffc6..85d2418455 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -57,6 +57,14 @@ public static String getClusterName() { return getAttribute("instance/attributes/cluster-name"); } + public static String getContainerName(){ + return getAttribute("instance/attributes/container-name"); + } + + public static String getNamespaceId(){ + return getAttribute("instance/attributes/namespace-id"); + } + public static String getAttribute(String attributeName) { try { URL url = new URL(METADATA_URL + attributeName); From 3034a8b721c62198b8a48f259f30ff03611dfc82 Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Thu, 29 Nov 2018 01:01:51 +0530 Subject: [PATCH 545/663] Add helpers to convert core Date class with java.util.Date class (#3911) * #3157 add methods toDate, fromDate * resolved test case Date.getYear() * update as per feedback * Update javadoc string --- .../src/main/java/com/google/cloud/Date.java | 41 +++++++++++++++++-- .../test/java/com/google/cloud/DateTest.java | 25 ++++++++++- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Date.java b/google-cloud-core/src/main/java/com/google/cloud/Date.java index 044a7ca72b..002ef84cdf 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Date.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Date.java @@ -16,14 +16,15 @@ package com.google.cloud; -import com.google.api.core.BetaApi; -import com.google.common.base.Preconditions; - import java.io.Serializable; +import java.util.Calendar; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.google.api.core.BetaApi; +import com.google.common.base.Preconditions; + /** * Represents a Date without time, such as 2017-03-17. Date is timezone independent. */ @@ -69,6 +70,40 @@ public static Date parseDate(String date) { return new Date(year, month, dayOfMonth); } + /** + * Convert a Google Date to a Java Util Date. + * + * @param date the date of the Google Date. + * @return java.util.Date + */ + public static java.util.Date toJavaUtilDate(Date date) { + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + // Calender.MONTH starts from 0 while G C date starts from 1 + cal.set(date.year, date.month - 1, date.dayOfMonth); + return cal.getTime(); + } + + /** + * Convert a Java Util Date to a Google Date. + * + * @param date the date of the java.util.Date + * @return Google Java Date + */ + public static Date fromJavaUtilDate(java.util.Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + // Calender.MONTH starts from 0 while G C date starts from 1 + return new Date(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH)); + } + /** Returns the year. */ public int getYear() { return year; diff --git a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java index 3c2817a92c..31dbf6416b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java @@ -19,15 +19,21 @@ import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; -import com.google.common.testing.EqualsTester; +import java.text.ParseException; +import java.text.SimpleDateFormat; + import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import com.google.common.testing.EqualsTester; + /** Unit tests for {@link Date}. */ @RunWith(JUnit4.class) public class DateTest { + private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); + @Test public void parseDate() { Date date = Date.parseDate("2016-09-18"); @@ -71,6 +77,23 @@ public void serialization() { reserializeAndAssert(Date.fromYearMonthDay(2017, 4, 20)); } + @Test + public void testToJavaUtilDate() throws ParseException { + Date gcDate = Date.parseDate("2016-09-18"); + java.util.Date juDate1 = SIMPLE_DATE_FORMAT.parse("2016-09-18"); + java.util.Date juDate2 = Date.toJavaUtilDate(gcDate); + assertThat(juDate1).isEqualTo(juDate2); + } + + @Test + public void testFromJavaUtilDate() throws ParseException { + java.util.Date juDate = SIMPLE_DATE_FORMAT.parse("2016-09-18"); + Date gcDate = Date.fromJavaUtilDate(juDate); + assertThat(gcDate.getYear()).isEqualTo(2016); + assertThat(gcDate.getMonth()).isEqualTo(9); + assertThat(gcDate.getDayOfMonth()).isEqualTo(18); + } + private void assertDescending(Date... dates) { for (int i = 0; i < dates.length - 1; i++) { assertThat(dates[i]).isEquivalentAccordingToCompareTo(dates[i]); From 0bf4355b5e37d1428110074cc7f0a05642b21d04 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Wed, 28 Nov 2018 15:25:45 -0800 Subject: [PATCH 546/663] Release v0.72.0 (#4113) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 5264b77d35..8e3fd52b84 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.53.1-SNAPSHOT + 1.54.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.71.1-alpha-SNAPSHOT + 0.72.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index fea01bc994..4cdd78fdeb 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.53.1-SNAPSHOT + 1.54.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.71.1-alpha-SNAPSHOT + 0.72.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 674ac3916b..459a26379b 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.53.0 + 1.54.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.53.0' +compile 'com.google.cloud:google-cloud-core:1.54.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.53.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.54.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6f69bc1680..e4d1cb3ff0 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.53.1-SNAPSHOT + 1.54.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.71.1-alpha-SNAPSHOT + 0.72.0-alpha google-cloud-core From a66592caa3aa7889e447cca2566d6779100406e8 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 29 Nov 2018 14:28:50 -0800 Subject: [PATCH 547/663] Bump next snapshot (#4118) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 8e3fd52b84..f2aa520509 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.54.0 + 1.54.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.72.0-alpha + 0.72.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 4cdd78fdeb..9011826655 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.54.0 + 1.54.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.72.0-alpha + 0.72.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e4d1cb3ff0..82fdd52412 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.54.0 + 1.54.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.72.0-alpha + 0.72.1-alpha-SNAPSHOT google-cloud-core From 33c7087a79e552f2c527e11969e0d5a9deae9f24 Mon Sep 17 00:00:00 2001 From: elisheva-qlogic <43041115+elisheva-qlogic@users.noreply.github.com> Date: Thu, 29 Nov 2018 17:30:15 -0500 Subject: [PATCH 548/663] Make TestServiceFactory and TestServiceRpcFactory interfaces public (#4112) --- .../src/test/java/com/google/cloud/ServiceOptionsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index ee957a625f..55d90b6510 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -180,7 +180,7 @@ private TestServiceImpl(TestServiceOptions options) { } } - private interface TestServiceFactory extends ServiceFactory {} + public interface TestServiceFactory extends ServiceFactory {} private static class DefaultTestServiceFactory implements TestServiceFactory { private static final TestServiceFactory INSTANCE = new DefaultTestServiceFactory(); @@ -191,7 +191,7 @@ public TestService create(TestServiceOptions options) { } } - private interface TestServiceRpcFactory + public interface TestServiceRpcFactory extends ServiceRpcFactory {} private static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory { From d939e62793907f8ceca2c6145354552973f5e788 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 29 Nov 2018 16:14:56 -0800 Subject: [PATCH 549/663] Java 11 compatibility (#3821) * Add the javax.annotation-api as a compile scope to the google-api-grpc projects * Upgrade maven-compiler-plugin 3.5.1->3.7.0 and maven-jar-plugin 2.6->3.1.0 * Add annotation-api compile dependency to google-cloud-clients * Fix objensis version 3.1.0->2.6 * Fix service option test visibility * Temporarily using Java 7 build to test Java 11 * Restore the java 7 test to use the java 7 image --- .../src/test/java/com/google/cloud/ServiceOptionsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 55d90b6510..cbb4dd04f1 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -171,7 +171,7 @@ public long millisTime() { } } - private interface TestService extends Service {} + interface TestService extends Service {} private static class TestServiceImpl extends BaseService implements TestService { @@ -209,7 +209,7 @@ private static class DefaultTestServiceRpc implements TestServiceRpc { DefaultTestServiceRpc(TestServiceOptions options) {} } - private static class TestServiceOptions + static class TestServiceOptions extends ServiceOptions { private static class Builder extends ServiceOptions.Builder { From 923fd78189c2762c522d9fb187f8c2ea5fd17f94 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 30 Nov 2018 11:29:29 -0800 Subject: [PATCH 550/663] Run google-java-format on all artifacts (#4121) * Run google-java-format on all artifats * Format some missed files * Add more missed files * Fix formatting issues from the merge --- .../cloud/grpc/BaseGrpcServiceException.java | 42 ++--- .../cloud/grpc/GrpcTransportOptions.java | 56 +++---- .../grpc/BaseGrpcServiceExceptionTest.java | 2 - .../cloud/grpc/GrpcTransportOptionsTest.java | 15 +- .../cloud/http/BaseHttpServiceException.java | 68 ++++---- .../google/cloud/http/CensusHttpModule.java | 35 ++--- .../cloud/http/HttpTransportOptions.java | 37 ++--- .../http/BaseHttpServiceExceptionTest.java | 26 ++-- .../cloud/http/CensusHttpModuleTest.java | 42 ++--- .../cloud/http/HttpTransportOptionsTest.java | 21 +-- .../java/com/google/cloud/AsyncPageImpl.java | 8 +- .../java/com/google/cloud/BaseService.java | 43 +++--- .../google/cloud/BaseServiceException.java | 64 ++++---- .../com/google/cloud/BaseWriteChannel.java | 40 ++--- .../java/com/google/cloud/BatchResult.java | 30 ++-- .../main/java/com/google/cloud/ByteArray.java | 33 +--- .../src/main/java/com/google/cloud/Date.java | 12 +- .../com/google/cloud/ExceptionHandler.java | 53 +++---- .../java/com/google/cloud/FieldSelector.java | 38 +++-- .../java/com/google/cloud/GcpLaunchStage.java | 13 +- .../main/java/com/google/cloud/Identity.java | 91 ++++------- .../java/com/google/cloud/MetadataConfig.java | 14 +- .../com/google/cloud/MonitoredResource.java | 58 ++----- .../cloud/MonitoredResourceDescriptor.java | 75 ++++----- .../main/java/com/google/cloud/PageImpl.java | 8 +- .../main/java/com/google/cloud/Policy.java | 88 +++++------ .../java/com/google/cloud/ReadChannel.java | 6 +- .../java/com/google/cloud/Restorable.java | 6 +- .../com/google/cloud/RestorableState.java | 4 +- .../java/com/google/cloud/RetryHelper.java | 28 ++-- .../java/com/google/cloud/RetryOption.java | 2 +- .../com/google/cloud/ServiceDefaults.java | 5 +- .../java/com/google/cloud/ServiceFactory.java | 4 +- .../java/com/google/cloud/ServiceOptions.java | 125 +++++++-------- .../java/com/google/cloud/ServiceRpc.java | 4 +- .../java/com/google/cloud/StringEnumType.java | 18 +-- .../com/google/cloud/StringEnumValue.java | 8 +- .../main/java/com/google/cloud/Timestamp.java | 2 +- .../com/google/cloud/TransportOptions.java | 7 +- .../java/com/google/cloud/WriteChannel.java | 8 +- .../java/com/google/cloud/package-info.java | 4 +- .../cloud/testing/BaseEmulatorHelper.java | 146 ++++++++---------- .../testing/BlockingProcessStreamReader.java | 11 +- .../google/cloud/testing/CommandWrapper.java | 4 +- .../com/google/cloud/testing/Version.java | 5 +- .../com/google/cloud/AsyncPageImplTest.java | 19 +-- .../google/cloud/BaseSerializationTest.java | 21 +-- .../cloud/BaseServiceExceptionTest.java | 27 ++-- .../google/cloud/BaseWriteChannelTest.java | 34 ++-- .../java/com/google/cloud/ByteArrayTest.java | 6 +- .../test/java/com/google/cloud/DateTest.java | 4 +- .../google/cloud/ExceptionHandlerTest.java | 105 +++++++------ .../google/cloud/FieldSelectorHelperTest.java | 52 ++++--- .../java/com/google/cloud/IdentityTest.java | 6 - .../MonitoredResourceDescriptorTest.java | 22 ++- .../google/cloud/MonitoredResourceTest.java | 54 ++++--- .../java/com/google/cloud/PageImplTest.java | 8 +- .../java/com/google/cloud/PolicyTest.java | 65 ++++---- .../com/google/cloud/RetryOptionTest.java | 2 - .../test/java/com/google/cloud/RoleTest.java | 1 - .../com/google/cloud/SerializationTest.java | 51 +++--- .../com/google/cloud/ServiceOptionsTest.java | 99 ++++++------ .../java/com/google/cloud/StringEnumTest.java | 20 +-- .../java/com/google/cloud/TimestampTest.java | 2 +- .../cloud/testing/BaseEmulatorHelperTest.java | 29 ++-- .../BlockingProcessStreamReaderTest.java | 57 +++---- .../cloud/testing/CommandWrapperTest.java | 4 +- .../com/google/cloud/testing/VersionTest.java | 3 +- 68 files changed, 938 insertions(+), 1162 deletions(-) diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java index bf7581ec41..dffa4d37ee 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/BaseGrpcServiceException.java @@ -19,24 +19,26 @@ import com.google.api.client.http.HttpResponseException; import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; -import com.google.api.gax.grpc.GrpcStatusCode; import com.google.api.gax.rpc.ApiException; import com.google.cloud.BaseServiceException; import com.google.common.base.MoreObjects; import java.io.IOException; import java.util.Collections; -/** - * Base class for all exceptions from grpc-based services. - */ +/** Base class for all exceptions from grpc-based services. */ public class BaseGrpcServiceException extends BaseServiceException { private static final long serialVersionUID = -2685197215731335549L; @InternalApi("This class should only be extended within google-cloud-java") protected BaseGrpcServiceException(String message, Throwable cause, int code, boolean retryable) { - super(ExceptionData.newBuilder().setMessage(message).setCause(cause).setCode(code) - .setRetryable(retryable).build()); + super( + ExceptionData.newBuilder() + .setMessage(message) + .setCause(cause) + .setCode(code) + .setRetryable(retryable) + .build()); } @InternalApi("This class should only be extended within google-cloud-java") @@ -51,14 +53,15 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id // In cases where an exception is an instance of HttpResponseException, // check the status code to determine whether it's retryable code = ((HttpResponseException) exception).getStatusCode(); - retryable = BaseServiceException - .isRetryable(code, null, idempotent, Collections.emptySet()); + retryable = + BaseServiceException.isRetryable(code, null, idempotent, Collections.emptySet()); } return ExceptionData.newBuilder() .setMessage(exception.getMessage()) .setCause(exception) - .setRetryable(MoreObjects - .firstNonNull(retryable, BaseServiceException.isRetryable(idempotent, exception))) + .setRetryable( + MoreObjects.firstNonNull( + retryable, BaseServiceException.isRetryable(idempotent, exception))) .setCode(code) .setReason(null) .setLocation(null) @@ -68,14 +71,15 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id @BetaApi public BaseGrpcServiceException(ApiException apiException) { - super(ExceptionData.newBuilder() - .setMessage(apiException.getMessage()) - .setCause(apiException) - .setRetryable(apiException.isRetryable()) - .setCode(apiException.getStatusCode().getCode().getHttpStatusCode()) - .setReason(apiException.getStatusCode().getCode().name()) - .setLocation(null) - .setDebugInfo(null) - .build()); + super( + ExceptionData.newBuilder() + .setMessage(apiException.getMessage()) + .setCause(apiException) + .setRetryable(apiException.isRetryable()) + .setCode(apiException.getStatusCode().getCode().getHttpStatusCode()) + .setReason(apiException.getStatusCode().getCode().name()) + .setLocation(null) + .setDebugInfo(null) + .build()); } } diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java index e8a3bf0a55..b003607d97 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java @@ -41,10 +41,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -/** - * Class representing service options for those services that use gRPC as the transport - * layer. - */ +/** Class representing service options for those services that use gRPC as the transport layer. */ public class GrpcTransportOptions implements TransportOptions { private static final long serialVersionUID = -9049538465533951165L; @@ -52,9 +49,7 @@ public class GrpcTransportOptions implements TransportOptions { private transient ExecutorFactory executorFactory; - /** - * Shared thread pool executor. - */ + /** Shared thread pool executor. */ private static final Resource EXECUTOR = new Resource() { @Override @@ -75,8 +70,8 @@ public void close(ScheduledExecutorService instance) { /** * An interface for {@link ExecutorService} factories. Implementations of this interface can be * used to provide an user-defined executor to execute requests. Any implementation of this - * interface must override the {@code get()} method to return the desired executor. The - * {@code release(executor)} method should be overriden to free resources used by the executor (if + * interface must override the {@code get()} method to return the desired executor. The {@code + * release(executor)} method should be overriden to free resources used by the executor (if * needed) according to application's logic. * *

    Implementation must provide a public no-arg constructor. Loading of a factory implementation @@ -86,14 +81,10 @@ public void close(ScheduledExecutorService instance) { */ public interface ExecutorFactory { - /** - * Gets an executor service instance. - */ + /** Gets an executor service instance. */ T get(); - /** - * Releases resources used by the executor and possibly shuts it down. - */ + /** Releases resources used by the executor and possibly shuts it down. */ void release(T executor); } @@ -113,9 +104,7 @@ public synchronized void release(ScheduledExecutorService executor) { } } - /** - * Builder for {@code GrpcTransportOptions}. - */ + /** Builder for {@code GrpcTransportOptions}. */ public static class Builder { private ExecutorFactory executorFactory; @@ -144,45 +133,42 @@ public Builder setExecutorFactory(ExecutorFactory exec @SuppressWarnings("unchecked") private GrpcTransportOptions(Builder builder) { - executorFactory = firstNonNull(builder.executorFactory, - ServiceOptions.getFromServiceLoader(ExecutorFactory.class, DefaultExecutorFactory.INSTANCE)); + executorFactory = + firstNonNull( + builder.executorFactory, + ServiceOptions.getFromServiceLoader( + ExecutorFactory.class, DefaultExecutorFactory.INSTANCE)); executorFactoryClassName = executorFactory.getClass().getName(); } - /** - * Returns a scheduled executor service provider. - */ + /** Returns a scheduled executor service provider. */ public ExecutorFactory getExecutorFactory() { return executorFactory; } - /** - * Returns a builder for API call settings. - */ + /** Returns a builder for API call settings. */ @Deprecated public UnaryCallSettings.Builder getApiCallSettings(RetrySettings retrySettings) { return UnaryCallSettings.newUnaryCallSettingsBuilder().setRetrySettings(retrySettings); } - /** - * Returns a channel provider from the given default provider. - */ + /** Returns a channel provider from the given default provider. */ @BetaApi public static TransportChannelProvider setUpChannelProvider( - InstantiatingGrpcChannelProvider.Builder providerBuilder, ServiceOptions serviceOptions) { + InstantiatingGrpcChannelProvider.Builder providerBuilder, + ServiceOptions serviceOptions) { providerBuilder.setEndpoint(serviceOptions.getHost()); return providerBuilder.build(); } public static CredentialsProvider setUpCredentialsProvider(ServiceOptions serviceOptions) { Credentials scopedCredentials = serviceOptions.getScopedCredentials(); - if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { - return FixedCredentialsProvider.create(scopedCredentials); - } - return NoCredentialsProvider.create(); + if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) { + return FixedCredentialsProvider.create(scopedCredentials); + } + return NoCredentialsProvider.create(); } - public Builder toBuilder() { return new Builder(this); } diff --git a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java index 37acc1cf84..696de60c55 100644 --- a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/BaseGrpcServiceExceptionTest.java @@ -26,7 +26,6 @@ import static org.junit.Assert.assertTrue; import com.google.api.gax.grpc.GrpcStatusCode; -import com.google.api.gax.rpc.ApiException; import com.google.api.gax.rpc.InternalException; import com.google.cloud.BaseServiceException; import com.google.cloud.RetryHelper; @@ -104,5 +103,4 @@ public void testTranslateAndThrow() throws Exception { verify(exceptionMock); } } - } diff --git a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java index 8d60ef3f68..b51eab96ce 100644 --- a/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java +++ b/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/GrpcTransportOptionsTest.java @@ -31,9 +31,8 @@ public class GrpcTransportOptionsTest { private static final ExecutorFactory MOCK_EXECUTOR_FACTORY = EasyMock.createMock(ExecutorFactory.class); - private static final GrpcTransportOptions OPTIONS = GrpcTransportOptions.newBuilder() - .setExecutorFactory(MOCK_EXECUTOR_FACTORY) - .build(); + private static final GrpcTransportOptions OPTIONS = + GrpcTransportOptions.newBuilder().setExecutorFactory(MOCK_EXECUTOR_FACTORY).build(); private static final GrpcTransportOptions DEFAULT_OPTIONS = GrpcTransportOptions.newBuilder().build(); private static final GrpcTransportOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); @@ -48,9 +47,8 @@ public void testBuilder() { public void testBaseEquals() { assertEquals(OPTIONS, OPTIONS_COPY); assertNotEquals(DEFAULT_OPTIONS, OPTIONS); - GrpcTransportOptions options = OPTIONS.toBuilder() - .setExecutorFactory(new DefaultExecutorFactory()) - .build(); + GrpcTransportOptions options = + OPTIONS.toBuilder().setExecutorFactory(new DefaultExecutorFactory()).build(); assertNotEquals(OPTIONS, options); } @@ -58,9 +56,8 @@ public void testBaseEquals() { public void testBaseHashCode() { assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); - GrpcTransportOptions options = OPTIONS.toBuilder() - .setExecutorFactory(new DefaultExecutorFactory()) - .build(); + GrpcTransportOptions options = + OPTIONS.toBuilder().setExecutorFactory(new DefaultExecutorFactory()).build(); assertNotEquals(OPTIONS.hashCode(), options.hashCode()); } diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java index 5ece1a7101..26f43b276f 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/BaseHttpServiceException.java @@ -25,22 +25,20 @@ import java.io.IOException; import java.util.Set; -/** - * Base class for all exceptions from http-based services. - */ +/** Base class for all exceptions from http-based services. */ public class BaseHttpServiceException extends BaseServiceException { private static final long serialVersionUID = -5793034110344127954L; public static final int UNKNOWN_CODE = 0; @InternalApi("This class should only be extended within google-cloud-java") - protected BaseHttpServiceException(IOException exception, boolean idempotent, - Set retryableErrors) { + protected BaseHttpServiceException( + IOException exception, boolean idempotent, Set retryableErrors) { super(makeExceptionData(exception, idempotent, retryableErrors)); } - private static ExceptionData makeExceptionData(IOException exception, boolean idempotent, - Set retryableErrors) { + private static ExceptionData makeExceptionData( + IOException exception, boolean idempotent, Set retryableErrors) { int code = UNKNOWN_CODE; String reason = null; String location = null; @@ -50,8 +48,8 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id if (exception instanceof GoogleJsonResponseException) { GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails(); if (jsonError != null) { - BaseServiceException.Error error = new BaseServiceException.Error(jsonError.getCode(), - reason(jsonError)); + BaseServiceException.Error error = + new BaseServiceException.Error(jsonError.getCode(), reason(jsonError)); code = error.getCode(); reason = error.getReason(); retryable = error.isRetryable(idempotent, retryableErrors); @@ -66,7 +64,8 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id } } else { // In cases where an exception is an instance of HttpResponseException but not - // an instance of GoogleJsonResponseException, check the status code to determine whether it's retryable + // an instance of GoogleJsonResponseException, check the status code to determine whether + // it's retryable code = ((HttpResponseException) exception).getStatusCode(); retryable = BaseServiceException.isRetryable(code, null, idempotent, retryableErrors); } @@ -74,8 +73,9 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id return ExceptionData.newBuilder() .setMessage(message(exception)) .setCause(exception) - .setRetryable(MoreObjects - .firstNonNull(retryable, BaseServiceException.isRetryable(idempotent, exception))) + .setRetryable( + MoreObjects.firstNonNull( + retryable, BaseServiceException.isRetryable(idempotent, exception))) .setCode(code) .setReason(reason) .setLocation(location) @@ -84,12 +84,16 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id } @InternalApi("This class should only be extended within google-cloud-java") - protected BaseHttpServiceException(GoogleJsonError googleJsonError, boolean idempotent, + protected BaseHttpServiceException( + GoogleJsonError googleJsonError, + boolean idempotent, Set retryableErrors) { super(makeExceptionData(googleJsonError, idempotent, retryableErrors)); } - private static ExceptionData makeExceptionData(GoogleJsonError googleJsonError, boolean idempotent, + private static ExceptionData makeExceptionData( + GoogleJsonError googleJsonError, + boolean idempotent, Set retryableErrors) { int code = googleJsonError.getCode(); String reason = reason(googleJsonError); @@ -113,23 +117,34 @@ private static ExceptionData makeExceptionData(GoogleJsonError googleJsonError, } @InternalApi("This class should only be extended within google-cloud-java") - protected BaseHttpServiceException(int code, String message, String reason, boolean idempotent, + protected BaseHttpServiceException( + int code, + String message, + String reason, + boolean idempotent, Set retryableErrors) { this(code, message, reason, idempotent, retryableErrors, null); } @InternalApi("This class should only be extended within google-cloud-java") - protected BaseHttpServiceException(int code, String message, String reason, boolean idempotent, - Set retryableErrors, Throwable cause) { - super(ExceptionData.newBuilder() - .setMessage(message) - .setCause(cause) - .setRetryable(BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors)) - .setCode(code) - .setReason(reason) - .setLocation(null) - .setDebugInfo(null) - .build()); + protected BaseHttpServiceException( + int code, + String message, + String reason, + boolean idempotent, + Set retryableErrors, + Throwable cause) { + super( + ExceptionData.newBuilder() + .setMessage(message) + .setCause(cause) + .setRetryable( + BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors)) + .setCode(code) + .setReason(reason) + .setLocation(null) + .setDebugInfo(null) + .build()); } private static String reason(GoogleJsonError error) { @@ -148,5 +163,4 @@ private static String message(IOException exception) { } return exception.getMessage(); } - } diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/CensusHttpModule.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/CensusHttpModule.java index 0eb882e193..d141507cc0 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/CensusHttpModule.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/CensusHttpModule.java @@ -17,6 +17,7 @@ package com.google.cloud.http; import static com.google.common.base.Preconditions.checkNotNull; + import com.google.api.client.http.HttpExecuteInterceptor; import com.google.api.client.http.HttpHeaders; import com.google.api.client.http.HttpRequest; @@ -36,33 +37,23 @@ public final class CensusHttpModule { /** - * OpenCensus tracing component. - * When no OpenCensus implementation is provided, it will return a no-op tracer. + * OpenCensus tracing component. When no OpenCensus implementation is provided, it will return a + * no-op tracer. */ private final Tracer tracer; - /** - * {@link TextFormat} used in tracing context propagation. - */ - @Nullable - private final TextFormat propagationTextFormat; + /** {@link TextFormat} used in tracing context propagation. */ + @Nullable private final TextFormat propagationTextFormat; - /** - * {@link TextFormat.Setter} for {@link #propagationTextFormat}. - */ - @Nullable - private final TextFormat.Setter propagationTextFormatSetter; + /** {@link TextFormat.Setter} for {@link #propagationTextFormat}. */ + @Nullable private final TextFormat.Setter propagationTextFormatSetter; - /** - * Whether spans are stored locally. - */ + /** Whether spans are stored locally. */ private final boolean isRecordEvents; - /** - * Default HTTP propagation text formatter. - */ + /** Default HTTP propagation text formatter. */ @VisibleForTesting - final static class DefaultPropagationTextFormatSetter extends TextFormat.Setter { + static final class DefaultPropagationTextFormatSetter extends TextFormat.Setter { static final TextFormat.Setter INSTANCE = new DefaultPropagationTextFormatSetter(); @Override @@ -77,8 +68,7 @@ public void put(HttpHeaders carrier, String key, String value) { */ @VisibleForTesting final class CensusHttpExecuteInterceptor implements HttpExecuteInterceptor { - @Nullable - HttpExecuteInterceptor interceptor; + @Nullable HttpExecuteInterceptor interceptor; CensusHttpExecuteInterceptor(HttpExecuteInterceptor interceptor) { this.interceptor = interceptor; @@ -106,8 +96,7 @@ public void intercept(HttpRequest request) throws IOException { */ @VisibleForTesting final class CensusHttpRequestInitializer implements HttpRequestInitializer { - @Nullable - HttpRequestInitializer initializer; + @Nullable HttpRequestInitializer initializer; CensusHttpRequestInitializer(HttpRequestInitializer initializer) { this.initializer = initializer; diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java index 6b7ec6ed05..6802e50549 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java @@ -38,10 +38,7 @@ import java.io.ObjectInputStream; import java.util.Objects; -/** - * Class representing service options for those services that use HTTP as the transport - * layer. - */ +/** Class representing service options for those services that use HTTP as the transport layer. */ public class HttpTransportOptions implements TransportOptions { private static final long serialVersionUID = 7890117765045419810L; @@ -69,9 +66,7 @@ public HttpTransport create() { } } - /** - * Builder for {@code HttpTransportOptions}. - */ + /** Builder for {@code HttpTransportOptions}. */ public static class Builder { private HttpTransportFactory httpTransportFactory; @@ -104,7 +99,7 @@ public Builder setHttpTransportFactory(HttpTransportFactory httpTransportFactory * Sets the timeout in milliseconds to establish a connection. * * @param connectTimeout connection timeout in milliseconds. 0 for an infinite timeout, a - * negative number for the default value (20000). + * negative number for the default value (20000). * @return the builder */ public Builder setConnectTimeout(int connectTimeout) { @@ -116,7 +111,7 @@ public Builder setConnectTimeout(int connectTimeout) { * Sets the timeout in milliseconds to read data from an established connection. * * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a negative number - * for the default value (20000). + * for the default value (20000). * @return the builder */ public Builder setReadTimeout(int readTimeout) { @@ -126,17 +121,17 @@ public Builder setReadTimeout(int readTimeout) { } private HttpTransportOptions(Builder builder) { - httpTransportFactory = firstNonNull(builder.httpTransportFactory, - ServiceOptions.getFromServiceLoader(HttpTransportFactory.class, - DefaultHttpTransportFactory.INSTANCE)); + httpTransportFactory = + firstNonNull( + builder.httpTransportFactory, + ServiceOptions.getFromServiceLoader( + HttpTransportFactory.class, DefaultHttpTransportFactory.INSTANCE)); httpTransportFactoryClassName = httpTransportFactory.getClass().getName(); connectTimeout = builder.connectTimeout; readTimeout = builder.readTimeout; } - /** - * Returns the HTTP transport factory. - */ + /** Returns the HTTP transport factory. */ public HttpTransportFactory getHttpTransportFactory() { return httpTransportFactory; } @@ -150,9 +145,12 @@ public HttpRequestInitializer getHttpRequestInitializer( Credentials scopedCredentials = serviceOptions.getScopedCredentials(); final HttpRequestInitializer delegate = scopedCredentials != null && scopedCredentials != NoCredentials.getInstance() - ? new HttpCredentialsAdapter(scopedCredentials) : null; - HeaderProvider internalHeaderProvider = getInternalHeaderProviderBuilder(serviceOptions).build(); - final HeaderProvider headerProvider = serviceOptions.getMergedHeaderProvider(internalHeaderProvider); + ? new HttpCredentialsAdapter(scopedCredentials) + : null; + HeaderProvider internalHeaderProvider = + getInternalHeaderProviderBuilder(serviceOptions).build(); + final HeaderProvider headerProvider = + serviceOptions.getMergedHeaderProvider(internalHeaderProvider); return new HttpRequestInitializer() { @Override @@ -203,8 +201,7 @@ public Builder toBuilder() { @Override public int hashCode() { - return Objects.hash(httpTransportFactoryClassName, connectTimeout, - readTimeout); + return Objects.hash(httpTransportFactoryClassName, connectTimeout, readTimeout); } @Override diff --git a/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java index 52d17456ea..e88a32a9af 100644 --- a/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java @@ -57,23 +57,23 @@ public CustomServiceException(int code, String message, String reason, boolean i super(code, message, reason, idempotent, RETRYABLE_ERRORS); } - private static final Set RETRYABLE_ERRORS = ImmutableSet - .of(new Error(CODE, REASON), new Error(null, REASON), - new Error(CODE_NO_REASON, null)); + private static final Set RETRYABLE_ERRORS = + ImmutableSet.of( + new Error(CODE, REASON), new Error(null, REASON), new Error(CODE_NO_REASON, null)); } @Test public void testBaseServiceException() { - BaseServiceException serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, - IDEMPOTENT, EMPTY_RETRYABLE_ERRORS); + BaseServiceException serviceException = + new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS); assertEquals(CODE, serviceException.getCode()); assertEquals(MESSAGE, serviceException.getMessage()); assertEquals(REASON, serviceException.getReason()); assertFalse(serviceException.isRetryable()); assertNull(serviceException.getCause()); - serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, - EMPTY_RETRYABLE_ERRORS); + serviceException = + new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS); assertEquals(CODE, serviceException.getCode()); assertEquals(MESSAGE, serviceException.getMessage()); assertEquals(REASON, serviceException.getReason()); @@ -81,16 +81,18 @@ public void testBaseServiceException() { assertNull(serviceException.getCause()); Exception cause = new RuntimeException(); - serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, - EMPTY_RETRYABLE_ERRORS, cause); + serviceException = + new BaseHttpServiceException( + CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS, cause); assertEquals(CODE, serviceException.getCode()); assertEquals(MESSAGE, serviceException.getMessage()); assertEquals(REASON, serviceException.getReason()); assertFalse(serviceException.isRetryable()); assertEquals(cause, serviceException.getCause()); - serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, NOT_IDEMPOTENT, - EMPTY_RETRYABLE_ERRORS, cause); + serviceException = + new BaseHttpServiceException( + CODE, MESSAGE, REASON, NOT_IDEMPOTENT, EMPTY_RETRYABLE_ERRORS, cause); assertEquals(CODE, serviceException.getCode()); assertEquals(MESSAGE, serviceException.getMessage()); assertEquals(REASON, serviceException.getReason()); @@ -160,6 +162,4 @@ public void testTranslateAndThrow() throws Exception { verify(exceptionMock); } } - - } diff --git a/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java index abc7f7de78..7d2827bfb9 100644 --- a/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java @@ -17,19 +17,17 @@ package com.google.cloud.http; import static com.google.common.truth.Truth.assertThat; - import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createMockBuilder; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; -import com.google.api.client.http.HttpExecuteInterceptor; import com.google.api.client.http.GenericUrl; +import com.google.api.client.http.HttpExecuteInterceptor; import com.google.api.client.http.HttpHeaders; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.javanet.NetHttpTransport; - import io.opencensus.common.Scope; import io.opencensus.trace.Span; import io.opencensus.trace.SpanContext; @@ -39,11 +37,9 @@ import io.opencensus.trace.Tracer; import io.opencensus.trace.Tracing; import io.opencensus.trace.propagation.TextFormat; - import java.io.IOException; import java.util.EnumSet; import java.util.Random; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -63,8 +59,10 @@ public class CensusHttpModuleTest { @Before public void setUp() throws IOException { - httpRequest = new NetHttpTransport().createRequestFactory().buildRequest( - "GET", new GenericUrl("https://www.google.com"), null); + httpRequest = + new NetHttpTransport() + .createRequestFactory() + .buildRequest("GET", new GenericUrl("https://www.google.com"), null); } @Test @@ -103,8 +101,8 @@ public void censusHttpExecuteInterceptorDisallowNullRequest() throws IOException @Test public void censusHttpExecuteInterceptorShouldExecuteOriginal() throws IOException { HttpExecuteInterceptor mockInterceptor = createMock(HttpExecuteInterceptor.class); - HttpExecuteInterceptor censusInterceptor = censusHttpModule.new CensusHttpExecuteInterceptor( - mockInterceptor); + HttpExecuteInterceptor censusInterceptor = + censusHttpModule.new CensusHttpExecuteInterceptor(mockInterceptor); mockInterceptor.intercept(httpRequest); replay(mockInterceptor); censusInterceptor.intercept(httpRequest); @@ -114,14 +112,16 @@ public void censusHttpExecuteInterceptorShouldExecuteOriginal() throws IOExcepti @Test public void censusHttpExecuteInterceptorShouldInjectHeader() throws IOException { Random random = new Random(); - SpanContext spanContext = SpanContext.create( - TraceId.generateRandomId(random), - SpanId.generateRandomId(random), - TraceOptions.DEFAULT); - Span mockSpan = createMockBuilder(Span.class) - .withConstructor(SpanContext.class, EnumSet.class) - .withArgs(spanContext, null) - .createMock(); + SpanContext spanContext = + SpanContext.create( + TraceId.generateRandomId(random), + SpanId.generateRandomId(random), + TraceOptions.DEFAULT); + Span mockSpan = + createMockBuilder(Span.class) + .withConstructor(SpanContext.class, EnumSet.class) + .withArgs(spanContext, null) + .createMock(); Scope scope = tracer.withSpan(mockSpan); try { HttpExecuteInterceptor interceptor = censusHttpModule.new CensusHttpExecuteInterceptor(null); @@ -142,8 +142,8 @@ public void censusHttpRequestInitializerDisallowNullRequest() throws IOException @Test public void censusHttpRequestInitializerShouldExecuteOriginal() throws IOException { HttpRequestInitializer mockOriginalInitializer = createMock(HttpRequestInitializer.class); - HttpRequestInitializer censusInitializer = censusHttpModule.getHttpRequestInitializer( - mockOriginalInitializer); + HttpRequestInitializer censusInitializer = + censusHttpModule.getHttpRequestInitializer(mockOriginalInitializer); mockOriginalInitializer.initialize(httpRequest); replay(mockOriginalInitializer); censusInitializer.initialize(httpRequest); @@ -153,7 +153,7 @@ public void censusHttpRequestInitializerShouldExecuteOriginal() throws IOExcepti @Test public void censusHttpRequestInitializerShouldSetInterceptor() throws IOException { censusHttpModule.getHttpRequestInitializer(null).initialize(httpRequest); - assertThat(httpRequest.getInterceptor()).isInstanceOf( - CensusHttpModule.CensusHttpExecuteInterceptor.class); + assertThat(httpRequest.getInterceptor()) + .isInstanceOf(CensusHttpModule.CensusHttpExecuteInterceptor.class); } } diff --git a/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java index 100d50f0ef..1ff7871aec 100644 --- a/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java @@ -33,11 +33,12 @@ public class HttpTransportOptionsTest { private static final HttpTransportFactory MOCK_HTTP_TRANSPORT_FACTORY = EasyMock.createMock(HttpTransportFactory.class); - private static final HttpTransportOptions OPTIONS = HttpTransportOptions.newBuilder() - .setConnectTimeout(1234) - .setHttpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) - .setReadTimeout(5678) - .build(); + private static final HttpTransportOptions OPTIONS = + HttpTransportOptions.newBuilder() + .setConnectTimeout(1234) + .setHttpTransportFactory(MOCK_HTTP_TRANSPORT_FACTORY) + .setReadTimeout(5678) + .build(); private static final HttpTransportOptions DEFAULT_OPTIONS = HttpTransportOptions.newBuilder().build(); private static final HttpTransportOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); @@ -68,11 +69,13 @@ public void testBaseHashCode() { public void testHeader() { String expectedHeaderPattern = "^gl-java/.+ gccl/.* gax/.+"; ServiceOptions serviceOptions = EasyMock.createMock(ServiceOptions.class); - HeaderProvider headerProvider = OPTIONS.getInternalHeaderProviderBuilder(serviceOptions).build(); + HeaderProvider headerProvider = + OPTIONS.getInternalHeaderProviderBuilder(serviceOptions).build(); assertEquals(1, headerProvider.getHeaders().size()); - assertTrue(Pattern.compile(expectedHeaderPattern) - .matcher(headerProvider.getHeaders().values().iterator().next()) - .find()); + assertTrue( + Pattern.compile(expectedHeaderPattern) + .matcher(headerProvider.getHeaders().values().iterator().next()) + .find()); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index 3acd0170bb..25cae6f7c8 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -62,7 +62,8 @@ private SyncNextPageFetcher(NextPageFetcher asyncPageFetcher) { public Page getNextPage() { try { return asyncPageFetcher != null - ? Uninterruptibles.getUninterruptibly(asyncPageFetcher.getNextPage()) : null; + ? Uninterruptibles.getUninterruptibly(asyncPageFetcher.getNextPage()) + : null; } catch (ExecutionException ex) { Throwables.throwIfUnchecked(ex.getCause()); throw new RuntimeException(ex); @@ -70,15 +71,12 @@ public Page getNextPage() { } } - /** - * Creates an {@code AsyncPageImpl} object. - */ + /** Creates an {@code AsyncPageImpl} object. */ public AsyncPageImpl(NextPageFetcher asyncPageFetcher, String cursor, Iterable results) { super(new SyncNextPageFetcher(asyncPageFetcher), cursor, results); this.asyncPageFetcher = asyncPageFetcher; } - @Override public ApiFuture> getNextPageAsync() { if (getNextPageToken() == null || asyncPageFetcher == null) { diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java index 7db43727ba..781f29b421 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java @@ -27,28 +27,32 @@ public abstract class BaseService> implements Service { - public static final Interceptor EXCEPTION_HANDLER_INTERCEPTOR = new Interceptor() { + public static final Interceptor EXCEPTION_HANDLER_INTERCEPTOR = + new Interceptor() { - private static final long serialVersionUID = -8429573486870467828L; + private static final long serialVersionUID = -8429573486870467828L; - @Override - public RetryResult afterEval(Exception exception, RetryResult retryResult) { - return Interceptor.RetryResult.CONTINUE_EVALUATION; - } + @Override + public RetryResult afterEval(Exception exception, RetryResult retryResult) { + return Interceptor.RetryResult.CONTINUE_EVALUATION; + } - @Override - public RetryResult beforeEval(Exception exception) { - if (exception instanceof BaseServiceException) { - boolean retriable = ((BaseServiceException) exception).isRetryable(); - return retriable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.CONTINUE_EVALUATION; - } - return Interceptor.RetryResult.CONTINUE_EVALUATION; - } - }; - public static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.newBuilder() - .abortOn(RuntimeException.class) - .addInterceptors(EXCEPTION_HANDLER_INTERCEPTOR) - .build(); + @Override + public RetryResult beforeEval(Exception exception) { + if (exception instanceof BaseServiceException) { + boolean retriable = ((BaseServiceException) exception).isRetryable(); + return retriable + ? Interceptor.RetryResult.RETRY + : Interceptor.RetryResult.CONTINUE_EVALUATION; + } + return Interceptor.RetryResult.CONTINUE_EVALUATION; + } + }; + public static final ExceptionHandler EXCEPTION_HANDLER = + ExceptionHandler.newBuilder() + .abortOn(RuntimeException.class) + .addInterceptors(EXCEPTION_HANDLER_INTERCEPTOR) + .build(); private final OptionsT options; @@ -57,7 +61,6 @@ protected BaseService(OptionsT options) { this.options = options; } - @Override public OptionsT getOptions() { return options; diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java index 565ae614f3..e9e9e2aa63 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -28,9 +28,7 @@ import java.util.concurrent.ExecutionException; import javax.net.ssl.SSLHandshakeException; -/** - * Base class for all service exceptions. - */ +/** Base class for all service exceptions. */ public class BaseServiceException extends RuntimeException { private static final long serialVersionUID = 759921776378760835L; @@ -54,8 +52,14 @@ public static final class ExceptionData implements Serializable { private final String location; private final String debugInfo; - private ExceptionData(String message, Throwable cause, int code, boolean retryable, - String reason, String location, String debugInfo) { + private ExceptionData( + String message, + Throwable cause, + int code, + boolean retryable, + String reason, + String location, + String debugInfo) { this.message = message; this.cause = cause; this.code = code; @@ -101,10 +105,15 @@ public static ExceptionData from(int code, String message, String reason, boolea return from(code, message, reason, retryable, null); } - public static ExceptionData from(int code, String message, String reason, boolean retryable, - Throwable cause) { - return newBuilder().setCode(code).setMessage(message).setReason(reason) - .setRetryable(retryable).setCause(cause).build(); + public static ExceptionData from( + int code, String message, String reason, boolean retryable, Throwable cause) { + return newBuilder() + .setCode(code) + .setMessage(message) + .setReason(reason) + .setRetryable(retryable) + .setCause(cause) + .build(); } @InternalApi @@ -156,8 +165,7 @@ public Builder setDebugInfo(String debugInfo) { } public ExceptionData build() { - return new ExceptionData(message, cause, code, retryable, reason, location, - debugInfo); + return new ExceptionData(message, cause, code, retryable, reason, location, debugInfo); } } } @@ -181,15 +189,11 @@ public Error(Integer code, String reason, boolean rejected) { this.rejected = rejected; } - - /** - * Returns the code associated with this exception. - */ + /** Returns the code associated with this exception. */ public Integer getCode() { return code; } - /** * Returns true if the error indicates that the API call was certainly not accepted by the * server. For instance, if the server returns a rate limit exceeded error, it certainly did not @@ -199,10 +203,7 @@ public boolean isRejected() { return rejected; } - - /** - * Returns the reason that caused the exception. - */ + /** Returns the reason that caused the exception. */ public String getReason() { return reason; } @@ -238,14 +239,12 @@ public boolean equals(Object obj) { } } - @InternalApi - public static boolean isRetryable(Integer code, String reason, boolean idempotent, - Set retryableErrors) { + public static boolean isRetryable( + Integer code, String reason, boolean idempotent, Set retryableErrors) { for (Error retryableError : retryableErrors) { if ((retryableError.getCode() == null || retryableError.getCode().equals(code)) - && (retryableError.getReason() == null - || retryableError.getReason().equals(reason))) { + && (retryableError.getReason() == null || retryableError.getReason().equals(reason))) { return idempotent || retryableError.isRejected(); } } @@ -288,30 +287,21 @@ protected BaseServiceException(ExceptionData exceptionData) { this.debugInfo = exceptionData.getDebugInfo(); } - /** - * Returns the code associated with this exception. - */ + /** Returns the code associated with this exception. */ public int getCode() { return code; } - - /** - * Returns the reason that caused the exception. - */ + /** Returns the reason that caused the exception. */ public String getReason() { return reason; } - - /** - * Returns {@code true} when it is safe to retry the operation that caused this exception. - */ + /** Returns {@code true} when it is safe to retry the operation that caused this exception. */ public boolean isRetryable() { return retryable; } - /** * Returns the service location where the error causing the exception occurred. Returns {@code * null} if not available. diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index 1888b2a78c..865af88959 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -33,8 +33,8 @@ * @param the entity this channel writes data to. Possibly with additional configuration */ public abstract class BaseWriteChannel< - ServiceOptionsT extends ServiceOptions, - EntityT extends Serializable> implements WriteChannel { + ServiceOptionsT extends ServiceOptions, EntityT extends Serializable> + implements WriteChannel { private static final int MIN_CHUNK_SIZE = 256 * 1024; private static final int DEFAULT_CHUNK_SIZE = 8 * MIN_CHUNK_SIZE; @@ -48,12 +48,10 @@ public abstract class BaseWriteChannel< private boolean isOpen = true; private int chunkSize = getDefaultChunkSize(); - protected int getMinChunkSize() { return MIN_CHUNK_SIZE; } - protected int getDefaultChunkSize() { return DEFAULT_CHUNK_SIZE; } @@ -66,42 +64,34 @@ protected int getDefaultChunkSize() { */ protected abstract void flushBuffer(int length, boolean last); - protected ServiceOptionsT getOptions() { return options; } - protected EntityT getEntity() { return entity; } - protected String getUploadId() { return uploadId; } - protected long getPosition() { return position; } - protected byte[] getBuffer() { return buffer; } - protected int getLimit() { return limit; } - protected int getChunkSize() { return chunkSize; } - @Override public final void setChunkSize(int chunkSize) { int minSize = getMinChunkSize(); @@ -165,9 +155,7 @@ public final void close() throws IOException { } } - /** - * Creates a {@link BaseState.Builder} for the current write channel. - */ + /** Creates a {@link BaseState.Builder} for the current write channel. */ protected abstract BaseState.Builder stateBuilder(); @Override @@ -184,9 +172,7 @@ public RestorableState capture() { .build(); } - /** - * Restores the state of the current write channel given a {@link BaseState} object. - */ + /** Restores the state of the current write channel given a {@link BaseState} object. */ protected void restore(BaseState state) { if (state.buffer != null) { this.buffer = state.buffer.clone(); @@ -198,7 +184,7 @@ protected void restore(BaseState state) { } protected abstract static class BaseState< - ServiceOptionsT extends ServiceOptions, EntityT extends Serializable> + ServiceOptionsT extends ServiceOptions, EntityT extends Serializable> implements RestorableState, Serializable { private static final long serialVersionUID = 8541062465055125619L; @@ -231,8 +217,7 @@ protected BaseState(Builder builder) { * configuration */ public abstract static class Builder< - ServiceOptionsT extends ServiceOptions, - EntityT extends Serializable> { + ServiceOptionsT extends ServiceOptions, EntityT extends Serializable> { private final ServiceOptionsT serviceOptions; private final EntityT entity; private final String uploadId; @@ -248,25 +233,21 @@ protected Builder(ServiceOptionsT options, EntityT entity, String uploadId) { this.uploadId = uploadId; } - public Builder setPosition(long position) { this.position = position; return this; } - public Builder setBuffer(byte[] buffer) { this.buffer = buffer; return this; } - public Builder setIsOpen(boolean isOpen) { this.isOpen = isOpen; return this; } - public Builder setChunkSize(int chunkSize) { this.chunkSize = chunkSize; return this; @@ -277,8 +258,8 @@ public Builder setChunkSize(int chunkSize) { @Override public int hashCode() { - return Objects.hash(serviceOptions, entity, uploadId, position, isOpen, chunkSize, - Arrays.hashCode(buffer)); + return Objects.hash( + serviceOptions, entity, uploadId, position, isOpen, chunkSize, Arrays.hashCode(buffer)); } @Override @@ -316,7 +297,7 @@ public static ValueHolder create(String name, Object value) { public String toString() { String result = name + "="; if (value != null && value.getClass().isArray()) { - Object[] objectArray = new Object[]{value}; + Object[] objectArray = new Object[] {value}; String arrayString = Arrays.deepToString(objectArray); result += arrayString.substring(1, arrayString.length() - 1); } else { @@ -338,8 +319,7 @@ protected List toStringHelper() { @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append(getClass().getSimpleName()) - .append('{'); + builder.append(getClass().getSimpleName()).append('{'); String nextSeparator = ""; for (ValueHolder valueHolder : toStringHelper()) { builder.append(nextSeparator).append(valueHolder); diff --git a/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java b/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java index ab967e5770..7281571f91 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BatchResult.java @@ -28,7 +28,6 @@ * * @param the type of the result * @param the type of the service-dependent exception thrown when a processing error occurs - * */ public abstract class BatchResult { @@ -38,8 +37,7 @@ public abstract class BatchResult { private final List> toBeNotified = new LinkedList<>(); @InternalApi("This class should only be extended within google-cloud-java") - protected BatchResult() { - } + protected BatchResult() {} /** * Returns {@code true} if the batch has been completed and the result is available; {@code false} @@ -69,14 +67,14 @@ public T get() throws E { * @throws IllegalStateException if the batch has been completed already */ public void notify(Callback callback) { - checkState(!completed, "The batch has been completed. All the calls to the notify()" - + " method should be done prior to submitting the batch."); + checkState( + !completed, + "The batch has been completed. All the calls to the notify()" + + " method should be done prior to submitting the batch."); toBeNotified.add(callback); } - /** - * Sets an error and status as completed. Notifies all callbacks. - */ + /** Sets an error and status as completed. Notifies all callbacks. */ protected void error(E error) { this.error = checkNotNull(error); this.completed = true; @@ -85,9 +83,7 @@ protected void error(E error) { } } - /** - * Sets a result and status as completed. Notifies all callbacks. - */ + /** Sets a result and status as completed. Notifies all callbacks. */ protected void success(T result) { this.result = result; this.completed = true; @@ -96,18 +92,12 @@ protected void success(T result) { } } - /** - * An interface for the batch callbacks. - */ + /** An interface for the batch callbacks. */ public interface Callback { - /** - * The method to be called when the batched operation succeeds. - */ + /** The method to be called when the batched operation succeeds. */ void success(T result); - /** - * The method to be called when the batched operation fails. - */ + /** The method to be called when the batched operation fails. */ void error(E exception); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java index 1d673770ce..24857f9f64 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -21,7 +21,6 @@ import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.io.BaseEncoding; import com.google.protobuf.ByteString; - import java.io.IOException; import java.io.InputStream; import java.io.Serializable; @@ -29,9 +28,7 @@ import java.nio.charset.StandardCharsets; import java.util.Iterator; -/** - * An immutable byte array holder. - */ +/** An immutable byte array holder. */ @BetaApi public class ByteArray implements Iterable, Serializable { @@ -73,23 +70,17 @@ public final boolean equals(Object obj) { || obj instanceof ByteArray && byteString.equals(((ByteArray) obj).byteString); } - /** - * Returns the number of bytes in this {@code ByteArray}. - */ + /** Returns the number of bytes in this {@code ByteArray}. */ public final int length() { return byteString.size(); } - /** - * Returns a copy of this {@code ByteArray} as an array of bytes. - */ + /** Returns a copy of this {@code ByteArray} as an array of bytes. */ public final byte[] toByteArray() { return byteString.toByteArray(); } - /** - * Returns a copy of this {@code ByteArray} as an {@code UTF-8} string. - */ + /** Returns a copy of this {@code ByteArray} as an {@code UTF-8} string. */ public final String toStringUtf8() { return byteString.toStringUtf8(); } @@ -99,16 +90,12 @@ public final String toBase64() { return encoder.encode(toByteArray()); } - /** - * Returns the content of this {@code ByteArray} as a read-only {@link ByteBuffer}. - */ + /** Returns the content of this {@code ByteArray} as a read-only {@link ByteBuffer}. */ public final ByteBuffer asReadOnlyByteBuffer() { return byteString.asReadOnlyByteBuffer(); } - /** - * Returns an {@link InputStream} for this {@code ByteArray} content. - */ + /** Returns an {@link InputStream} for this {@code ByteArray} content. */ public final InputStream asInputStream() { return byteString.newInput(); } @@ -133,9 +120,7 @@ public final void copyTo(byte[] target) { byteString.copyTo(target, 0, 0, length()); } - /** - * Creates a {@code ByteArray} object given an array of bytes. The bytes are copied. - */ + /** Creates a {@code ByteArray} object given an array of bytes. The bytes are copied. */ public static final ByteArray copyFrom(byte[] bytes) { return new ByteArray(ByteString.copyFrom(bytes)); } @@ -148,9 +133,7 @@ public static final ByteArray copyFrom(String string) { return new ByteArray(ByteString.copyFrom(string, StandardCharsets.UTF_8)); } - /** - * Creates a {@code ByteArray} object given a {@link ByteBuffer}. The bytes are copied. - */ + /** Creates a {@code ByteArray} object given a {@link ByteBuffer}. The bytes are copied. */ public static final ByteArray copyFrom(ByteBuffer bytes) { return new ByteArray(ByteString.copyFrom(bytes)); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/Date.java b/google-cloud-core/src/main/java/com/google/cloud/Date.java index 002ef84cdf..442e7dca0e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Date.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Date.java @@ -16,18 +16,15 @@ package com.google.cloud; +import com.google.api.core.BetaApi; +import com.google.common.base.Preconditions; import java.io.Serializable; import java.util.Calendar; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.google.api.core.BetaApi; -import com.google.common.base.Preconditions; - -/** - * Represents a Date without time, such as 2017-03-17. Date is timezone independent. - */ +/** Represents a Date without time, such as 2017-03-17. Date is timezone independent. */ @BetaApi("This is going to be replaced with LocalDate from threetenbp") public final class Date implements Comparable, Serializable { @@ -101,7 +98,8 @@ public static Date fromJavaUtilDate(java.util.Date date) { cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); // Calender.MONTH starts from 0 while G C date starts from 1 - return new Date(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH)); + return new Date( + cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH)); } /** Returns the year. */ diff --git a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java index 921e97eb36..d243de1807 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java @@ -26,16 +26,13 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; - import java.io.Serializable; import java.lang.reflect.Method; import java.util.Objects; import java.util.Set; import java.util.concurrent.Callable; -/** - * Exception retry algorithm implementation used by {@link RetryHelper}. - */ +/** Exception retry algorithm implementation used by {@link RetryHelper}. */ @BetaApi public final class ExceptionHandler implements ResultRetryAlgorithm, Serializable { @@ -52,16 +49,18 @@ public final class ExceptionHandler implements ResultRetryAlgorithm, Ser public interface Interceptor extends Serializable { enum RetryResult { - NO_RETRY, RETRY, CONTINUE_EVALUATION; + NO_RETRY, + RETRY, + CONTINUE_EVALUATION; } /** * This method is called before exception evaluation and could short-circuit the process. * * @param exception the exception that is being evaluated - * @return {@link RetryResult} to indicate if the exception should be ignored ( - * {@link RetryResult#RETRY}), propagated ({@link RetryResult#NO_RETRY}), or evaluation - * should proceed ({@link RetryResult#CONTINUE_EVALUATION}). + * @return {@link RetryResult} to indicate if the exception should be ignored ( {@link + * RetryResult#RETRY}), propagated ({@link RetryResult#NO_RETRY}), or evaluation should + * proceed ({@link RetryResult#CONTINUE_EVALUATION}). */ RetryResult beforeEval(Exception exception); @@ -70,16 +69,14 @@ enum RetryResult { * * @param exception the exception that is being evaluated * @param retryResult the result of the evaluation so far - * @return {@link RetryResult} to indicate if the exception should be ignored ( - * {@link RetryResult#RETRY}), propagated ({@link RetryResult#NO_RETRY}), or evaluation - * should proceed ({@link RetryResult#CONTINUE_EVALUATION}). + * @return {@link RetryResult} to indicate if the exception should be ignored ( {@link + * RetryResult#RETRY}), propagated ({@link RetryResult#NO_RETRY}), or evaluation should + * proceed ({@link RetryResult#CONTINUE_EVALUATION}). */ RetryResult afterEval(Exception exception, RetryResult retryResult); } - /** - * ExceptionHandler builder. - */ + /** ExceptionHandler builder. */ public static class Builder { private final ImmutableList.Builder interceptors = ImmutableList.builder(); @@ -90,8 +87,6 @@ public static class Builder { private Builder() {} - - /** * Adds the exception handler interceptors. Call order will be maintained. * @@ -133,9 +128,7 @@ public final Builder abortOn(Class... exceptions) { return this; } - /** - * Returns a new ExceptionHandler instance. - */ + /** Returns a new ExceptionHandler instance. */ public ExceptionHandler build() { return new ExceptionHandler(this); } @@ -201,8 +194,8 @@ private static void addRetryInfo(RetryInfo retryInfo, Set dest) { dest.add(retryInfo); } - private static RetryInfo findMostSpecificRetryInfo(Set retryInfo, - Class exception) { + private static RetryInfo findMostSpecificRetryInfo( + Set retryInfo, Class exception) { for (RetryInfo current : retryInfo) { if (current.exception.isAssignableFrom(exception)) { RetryInfo match = findMostSpecificRetryInfo(current.children, exception); @@ -228,18 +221,20 @@ private static Method getCallableMethod(Class clazz) { void verifyCaller(Callable callable) { Method callMethod = getCallableMethod(callable.getClass()); for (Class exceptionOrError : callMethod.getExceptionTypes()) { - Preconditions.checkArgument(Exception.class.isAssignableFrom(exceptionOrError), + Preconditions.checkArgument( + Exception.class.isAssignableFrom(exceptionOrError), "Callable method exceptions must be derived from Exception"); @SuppressWarnings("unchecked") Class exception = (Class) exceptionOrError; - Preconditions.checkArgument(findMostSpecificRetryInfo(retryInfo, exception) != null, + Preconditions.checkArgument( + findMostSpecificRetryInfo(retryInfo, exception) != null, "Declared exception '" + exception + "' is not covered by exception handler"); } } @Override public boolean shouldRetry(Throwable prevThrowable, Object prevResponse) { - if(!(prevThrowable instanceof Exception)) { + if (!(prevThrowable instanceof Exception)) { return false; } Exception ex = (Exception) prevThrowable; @@ -263,8 +258,8 @@ public boolean shouldRetry(Throwable prevThrowable, Object prevResponse) { } @Override - public TimedAttemptSettings createNextAttempt(Throwable prevThrowable, Object prevResponse, - TimedAttemptSettings prevSettings) { + public TimedAttemptSettings createNextAttempt( + Throwable prevThrowable, Object prevResponse, TimedAttemptSettings prevSettings) { // Return null to indicate that this implementation does not provide any specific attempt // settings, so by default the TimedRetryAlgorithm options can be used instead. return null; @@ -290,15 +285,11 @@ public boolean equals(Object obj) { && Objects.equals(retryInfo, other.retryInfo); } - - /** - * Returns an instance which retry any checked exception and abort on any runtime exception. - */ + /** Returns an instance which retry any checked exception and abort on any runtime exception. */ public static ExceptionHandler getDefaultInstance() { return DEFAULT_INSTANCE; } - public static Builder newBuilder() { return new Builder(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java index 0444bc476f..aad60f7a4d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java +++ b/google-cloud-core/src/main/java/com/google/cloud/FieldSelector.java @@ -21,7 +21,6 @@ import com.google.common.base.Joiner; import com.google.common.collect.Lists; import com.google.common.collect.Sets; - import java.util.Arrays; import java.util.List; import java.util.Set; @@ -32,7 +31,6 @@ */ public interface FieldSelector { - /** * Returns a string selector. This selector is passed to a Google Cloud service (possibly with * other field selectors) to specify which resource fields should be returned by an API call. @@ -58,7 +56,9 @@ public String apply(FieldSelector fieldSelector) { } }; - private static String selector(List required, FieldSelector[] others, + private static String selector( + List required, + FieldSelector[] others, String... extraResourceFields) { Set fieldStrings = Sets.newHashSetWithExpectedSize(required.size() + others.length); fieldStrings.addAll(Lists.transform(required, FIELD_TO_STRING_FUNCTION)); @@ -73,16 +73,16 @@ private static String selector(List required, FieldSele * This method is not supposed to be used directly by users. */ public static String selector(List required, FieldSelector... others) { - return selector(required, others, new String[]{}); + return selector(required, others, new String[] {}); } /** * Returns a composite selector given a number of resource fields and a container name. The * string selector returned by this method can be used for field selection in API calls that - * return a list of resources. This method is not supposed to be used directly by users. + * return a list of resources. This method is not supposed to be used directly by users. */ - public static String listSelector(String containerName, List required, - FieldSelector... others) { + public static String listSelector( + String containerName, List required, FieldSelector... others) { return "nextPageToken," + containerName + '(' + selector(required, others) + ')'; } @@ -93,25 +93,35 @@ public static String listSelector(String containerName, List required, - FieldSelector[] others, String... extraResourceFields) { + public static String listSelector( + String containerName, + List required, + FieldSelector[] others, + String... extraResourceFields) { return listSelector(EMPTY_FIELDS, containerName, required, others, extraResourceFields); } /** * Returns a composite selector given a number of top level fields as strings, a number of * resource fields and a container name. This method also takes an {@code extraResourceFields} - * parameter to specify some extra resource fields as strings. The string selector returned by + * parameter to specify some extra resource fields as strings. The string selector returned by * this method can be used for field selection in API calls that return a list of resources. * This method is not supposed to be used directly by users. */ - public static String listSelector(String[] topLevelFields, String containerName, - List required, FieldSelector[] others, + public static String listSelector( + String[] topLevelFields, + String containerName, + List required, + FieldSelector[] others, String... extraResourceFields) { Set topLevelStrings = Sets.newHashSetWithExpectedSize(topLevelFields.length + 1); topLevelStrings.addAll(Lists.asList("nextPageToken", topLevelFields)); - return Joiner.on(',').join(topLevelStrings) + "," + containerName + '(' - + selector(required, others, extraResourceFields) + ')'; + return Joiner.on(',').join(topLevelStrings) + + "," + + containerName + + '(' + + selector(required, others, extraResourceFields) + + ')'; } } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java b/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java index d3f127f0f6..e83f773c9d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GcpLaunchStage.java @@ -22,10 +22,11 @@ /** * A qualifier indicating what level of access and support can be expected of a particular Google * Cloud Platform feature. The "GeneralAvailability" qualifier is not provided since the vast - * majority of features are in this category. Note that features may be in a later launch stage - * than the client library annotation indicates. + * majority of features are in this category. Note that features may be in a later launch stage than + * the client library annotation indicates. * - *

    See more at the Launch Stages Documentation. + *

    See more at the Launch Stages + * Documentation. */ public class GcpLaunchStage { @@ -61,9 +62,9 @@ public class GcpLaunchStage { /** * Deprecated features are scheduled to be shut down and removed. For more information, see the - * “Deprecation Policy” section of our Terms of Service - * and the Google Cloud Platform Subject to the Deprecation Policy - * documentation. + * “Deprecation Policy” section of our Terms of + * Service and the Google Cloud Platform + * Subject to the Deprecation Policy documentation. */ @Retention(RetentionPolicy.RUNTIME) public @interface Deprecated {} diff --git a/google-cloud-core/src/main/java/com/google/cloud/Identity.java b/google-cloud-core/src/main/java/com/google/cloud/Identity.java index 68a8a5a7de..ba4537e83c 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Identity.java @@ -20,17 +20,17 @@ import com.google.api.core.ApiFunction; import com.google.common.base.CaseFormat; - import java.io.Serializable; import java.util.Objects; /** * An identity in a {@link Policy}. The following types of identities are permitted in IAM policies: + * *

      - *
    • Google account - *
    • Service account - *
    • Google group - *
    • Google Apps domain + *
    • Google account + *
    • Service account + *
    • Google group + *
    • Google Apps domain *
    * *

    There are also two special identities that represent all users and all Google-authenticated @@ -46,9 +46,7 @@ public final class Identity implements Serializable { private final Type type; private final String value; - /** - * The types of IAM identities. - */ + /** The types of IAM identities. */ public static final class Type extends StringEnumValue { private static final long serialVersionUID = 3809891273596003916L; @@ -64,73 +62,50 @@ public Type apply(String constant) { } }; - private static final StringEnumType type = new StringEnumType( - Type.class, - CONSTRUCTOR); + private static final StringEnumType type = new StringEnumType(Type.class, CONSTRUCTOR); - /** - * Represents anyone who is on the internet; with or without a Google account. - */ + /** Represents anyone who is on the internet; with or without a Google account. */ public static final Type ALL_USERS = type.createAndRegister("ALL_USERS"); - /** - * Represents anyone who is authenticated with a Google account or a service account. - */ - public static final Type ALL_AUTHENTICATED_USERS = type.createAndRegister("ALL_AUTHENTICATED_USERS"); + /** Represents anyone who is authenticated with a Google account or a service account. */ + public static final Type ALL_AUTHENTICATED_USERS = + type.createAndRegister("ALL_AUTHENTICATED_USERS"); - /** - * Represents a specific Google account. - */ + /** Represents a specific Google account. */ public static final Type USER = type.createAndRegister("USER"); - /** - * Represents a service account. - */ + /** Represents a service account. */ public static final Type SERVICE_ACCOUNT = type.createAndRegister("SERVICE_ACCOUNT"); - /** - * Represents a Google group. - */ + /** Represents a Google group. */ public static final Type GROUP = type.createAndRegister("GROUP"); - /** - * Represents all the users of a Google Apps domain name. - */ + /** Represents all the users of a Google Apps domain name. */ public static final Type DOMAIN = type.createAndRegister("DOMAIN"); - /** - * Represents owners of a Google Cloud Platform project. - */ + /** Represents owners of a Google Cloud Platform project. */ public static final Type PROJECT_OWNER = type.createAndRegister("PROJECT_OWNER"); - /** - * Represents editors of a Google Cloud Platform project. - */ + /** Represents editors of a Google Cloud Platform project. */ public static final Type PROJECT_EDITOR = type.createAndRegister("PROJECT_EDITOR"); - /** - * Represents viewers of a Google Cloud Platform project. - */ + /** Represents viewers of a Google Cloud Platform project. */ public static final Type PROJECT_VIEWER = type.createAndRegister("PROJECT_VIEWER"); /** - * Get the Type for the given String constant, and throw an exception if the constant is - * not recognized. + * Get the Type for the given String constant, and throw an exception if the constant is not + * recognized. */ public static Type valueOfStrict(String constant) { return type.valueOfStrict(constant); } - /** - * Get the Type for the given String constant, and allow unrecognized values. - */ + /** Get the Type for the given String constant, and allow unrecognized values. */ public static Type valueOf(String constant) { return type.valueOf(constant); } - /** - * Return the known values for Type. - */ + /** Return the known values for Type. */ public static Type[] values() { return type.values(); } @@ -141,20 +116,19 @@ private Identity(Type type, String value) { this.value = value; } - public Type getType() { return type; } - /** * Returns the string identifier for this identity. The value corresponds to: + * *

      - *
    • email address (for identities of type {@code USER}, {@code SERVICE_ACCOUNT}, and - * {@code GROUP}) + *
    • email address (for identities of type {@code USER}, {@code SERVICE_ACCOUNT}, and {@code + * GROUP}) *
    • domain (for identities of type {@code DOMAIN}) - *
    • {@code null} (for identities of type {@code ALL_USERS} and - * {@code ALL_AUTHENTICATED_USERS}) + *
    • {@code null} (for identities of type {@code ALL_USERS} and {@code + * ALL_AUTHENTICATED_USERS}) *
    */ public String getValue() { @@ -216,25 +190,28 @@ public static Identity group(String email) { public static Identity domain(String domain) { return new Identity(Type.DOMAIN, checkNotNull(domain)); } - + /** * Returns a new project owner identity. + * * @param projectId A Google Cloud Platform project ID. For example, my-sample-project. */ public static Identity projectOwner(String projectId) { return new Identity(Type.PROJECT_OWNER, checkNotNull(projectId)); } - + /** * Returns a new project editor identity. + * * @param projectId A Google Cloud Platform project ID. For example, my-sample-project. */ public static Identity projectEditor(String projectId) { return new Identity(Type.PROJECT_EDITOR, checkNotNull(projectId)); } - + /** * Returns a new project viewer identity. + * * @param projectId A Google Cloud Platform project ID. For example, my-sample-project. */ public static Identity projectViewer(String projectId) { @@ -282,7 +259,7 @@ public static Identity valueOf(String identityStr) { Type type = Type.valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, info[0])); if (info.length == 1) { return new Identity(type, null); - } else if (info.length == 2){ + } else if (info.length == 2) { return new Identity(type, info[1]); } else { throw new IllegalArgumentException("Illegal identity string: \"" + identityStr + "\""); diff --git a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java index 85d2418455..5c9550fe85 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -27,15 +27,15 @@ /** * Retrieves Google Cloud project-id and a limited set of instance attributes from Metadata server. + * * @see - * https://cloud.google.com/compute/docs/storing-retrieving-metadata + * https://cloud.google.com/compute/docs/storing-retrieving-metadata */ public class MetadataConfig { private static final String METADATA_URL = "http://metadata/computeMetadata/v1/"; - private MetadataConfig() { - } + private MetadataConfig() {} public static String getProjectId() { return getAttribute("project/project-id"); @@ -57,12 +57,12 @@ public static String getClusterName() { return getAttribute("instance/attributes/cluster-name"); } - public static String getContainerName(){ - return getAttribute("instance/attributes/container-name"); + public static String getContainerName() { + return getAttribute("instance/attributes/container-name"); } - public static String getNamespaceId(){ - return getAttribute("instance/attributes/namespace-id"); + public static String getNamespaceId() { + return getAttribute("instance/attributes/namespace-id"); } public static String getAttribute(String attributeName) { diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java index da9007eff0..a1fbe44b92 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java @@ -20,7 +20,6 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; - import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -33,9 +32,9 @@ * the resource's schema. Information in the labels field identifies the actual resource and its * attributes according to the schema. * - *

    For example, the monitored resource for Google Compute Engine VM instances has - * {@code gce_instance} type and specifies values for the labels {@code instance_id} and - * {@code zone} to identify particular VM instances. + *

    For example, the monitored resource for Google Compute Engine VM instances has {@code + * gce_instance} type and specifies values for the labels {@code instance_id} and {@code zone} to + * identify particular VM instances. */ public final class MonitoredResource implements Serializable { @@ -44,9 +43,7 @@ public final class MonitoredResource implements Serializable { private final String type; private final Map labels; - /** - * A builder for {@code MonitoredResource} objects. - */ + /** A builder for {@code MonitoredResource} objects. */ public static class Builder { private String type; @@ -61,18 +58,16 @@ public static class Builder { this.labels = new HashMap<>(monitoredResource.labels); } - /** - * Sets the monitored resource type. This value must match the one of - * {@link MonitoredResourceDescriptor#getType()} of a {@code MonitoredResourceDescriptor} object. - * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. + * Sets the monitored resource type. This value must match the one of {@link + * MonitoredResourceDescriptor#getType()} of a {@code MonitoredResourceDescriptor} object. For + * example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. */ public Builder setType(String type) { this.type = type; return this; } - /** * Sets the values for all the labels required by the corresponding monitored resource * descriptor (see {@link MonitoredResourceDescriptor#getLabels()}. For example, Google Compute @@ -83,17 +78,13 @@ public Builder setLabels(Map labels) { return this; } - /** - * Adds a label to the labels of the monitored resource. - */ + /** Adds a label to the labels of the monitored resource. */ public Builder addLabel(String key, String value) { this.labels.put(key, value); return this; } - /** - * Clears all the labels of the monitored resource. - */ + /** Clears all the labels of the monitored resource. */ public Builder clearLabels() { this.labels.clear(); return this; @@ -109,17 +100,15 @@ public MonitoredResource build() { this.labels = ImmutableMap.copyOf(builder.labels); } - /** - * Returns the monitored resource type. This value must match the one of - * {@link MonitoredResourceDescriptor#getType()} of a {@code MonitoredResourceDescriptor} object. - * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. + * Returns the monitored resource type. This value must match the one of {@link + * MonitoredResourceDescriptor#getType()} of a {@code MonitoredResourceDescriptor} object. For + * example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. */ public String getType() { return type; } - /** * Returns the values for all the labels required by the corresponding monitored resource * descriptor (see {@link MonitoredResourceDescriptor#getLabels()}. For example, Google Compute @@ -148,37 +137,24 @@ public boolean equals(Object obj) { @Override public String toString() { - return MoreObjects.toStringHelper(this) - .add("type", type) - .add("labels", labels) - .toString(); + return MoreObjects.toStringHelper(this).add("type", type).add("labels", labels).toString(); } public com.google.api.MonitoredResource toPb() { - return com.google.api.MonitoredResource.newBuilder() - .setType(type) - .putAllLabels(labels) - .build(); + return com.google.api.MonitoredResource.newBuilder().setType(type).putAllLabels(labels).build(); } - /** - * Returns a builder for this {@code MonitoredResource} object. - */ + /** Returns a builder for this {@code MonitoredResource} object. */ public Builder toBuilder() { return new Builder(this); } - - /** - * Returns a builder for {@code MonitoredResource} objects given the resource's type. - */ + /** Returns a builder for {@code MonitoredResource} objects given the resource's type. */ public static Builder newBuilder(String type) { return new Builder(type); } - /** - * Creates a {@code MonitoredResource} object given the resource's type and labels. - */ + /** Creates a {@code MonitoredResource} object given the resource's type and labels. */ public static MonitoredResource of(String type, Map labels) { return newBuilder(type).setLabels(labels).build(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java index d0301afb82..cfc24590d4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java @@ -23,7 +23,6 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; - import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -38,15 +37,17 @@ public class MonitoredResourceDescriptor implements Serializable { private static final long serialVersionUID = -3702077512777687441L; - public static final ApiFunction FROM_PB_FUNCTION = - new ApiFunction() { - @Override - public MonitoredResourceDescriptor apply( - com.google.api.MonitoredResourceDescriptor pb) { - return fromPb(pb); - } - }; + public static final ApiFunction< + com.google.api.MonitoredResourceDescriptor, MonitoredResourceDescriptor> + FROM_PB_FUNCTION = + new ApiFunction< + com.google.api.MonitoredResourceDescriptor, MonitoredResourceDescriptor>() { + @Override + public MonitoredResourceDescriptor apply( + com.google.api.MonitoredResourceDescriptor pb) { + return fromPb(pb); + } + }; private final String type; private final String name; @@ -62,14 +63,15 @@ public static class LabelDescriptor implements Serializable { private static final long serialVersionUID = -2811608103754481777L; private static final Function - FROM_PB_FUNCTION = new Function() { - @Override - public LabelDescriptor apply(com.google.api.LabelDescriptor descriptorPb) { - return fromPb(descriptorPb); - } - }; - private static final Function - TO_PB_FUNCTION = new Function() { + FROM_PB_FUNCTION = + new Function() { + @Override + public LabelDescriptor apply(com.google.api.LabelDescriptor descriptorPb) { + return fromPb(descriptorPb); + } + }; + private static final Function TO_PB_FUNCTION = + new Function() { @Override public com.google.api.LabelDescriptor apply(LabelDescriptor descriptor) { return descriptor.toPb(); @@ -80,9 +82,7 @@ public com.google.api.LabelDescriptor apply(LabelDescriptor descriptor) { private final ValueType valueType; private final String description; - /** - * Value types that can be used as label values. - */ + /** Value types that can be used as label values. */ public enum ValueType { STRING(com.google.api.LabelDescriptor.ValueType.STRING), BOOL(com.google.api.LabelDescriptor.ValueType.BOOL), @@ -118,23 +118,16 @@ static ValueType fromPb(com.google.api.LabelDescriptor.ValueType typePb) { this.description = description; } - - /** - * Returns the key associated to this label. - */ + /** Returns the key associated to this label. */ public String getKey() { return key; } - - /** - * Returns the type of data that can be assigned to this label. - */ + /** Returns the type of data that can be assigned to this label. */ public ValueType getValueType() { return valueType; } - /** * Returns the optional human-readable description for this label. If not set, this method * returns {@code null}. @@ -172,9 +165,8 @@ public String toString() { } com.google.api.LabelDescriptor toPb() { - com.google.api.LabelDescriptor.Builder builder = com.google.api.LabelDescriptor.newBuilder() - .setKey(key) - .setValueType(valueType.toPb()); + com.google.api.LabelDescriptor.Builder builder = + com.google.api.LabelDescriptor.newBuilder().setKey(key).setValueType(valueType.toPb()); if (description != null) { builder.setDescription(description); } @@ -186,8 +178,8 @@ static LabelDescriptor fromPb(com.google.api.LabelDescriptor descriptorPb) { if (descriptorPb.getDescription() != null && !descriptorPb.getDescription().equals("")) { description = descriptorPb.getDescription(); } - return new LabelDescriptor(descriptorPb.getKey(), - ValueType.fromPb(descriptorPb.getValueType()), description); + return new LabelDescriptor( + descriptorPb.getKey(), ValueType.fromPb(descriptorPb.getValueType()), description); } } @@ -236,7 +228,6 @@ MonitoredResourceDescriptor build() { this.labels = checkNotNull(builder.labels); } - /** * Returns the monitored resource type. For example, the type {@code cloudsql_database} represents * databases in Google Cloud SQL. @@ -245,7 +236,6 @@ public String getType() { return type; } - /** * Returns an optional name for the monitored resource descriptor. If not set, this method returns * {@code null}. @@ -254,7 +244,6 @@ public String getName() { return name; } - /** * Returns an optional concise name for the monitored resource type. This value might be displayed * in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method @@ -264,7 +253,6 @@ public String getDisplayName() { return displayName; } - /** * Returns an optional detailed description of the monitored resource type. This value might be * used in documentation. If not set, this method returns {@code null}. @@ -273,11 +261,10 @@ public String getDescription() { return description; } - /** * Returns a list of labels used to describe instances of this monitored resource type. For - * example, an individual Google Cloud SQL database is identified by values for the labels - * {@code database_id} and {@code region}. + * example, an individual Google Cloud SQL database is identified by values for the labels {@code + * database_id} and {@code region}. */ public List getLabels() { return labels; @@ -348,8 +335,8 @@ public static MonitoredResourceDescriptor fromPb( if (descriptorPb.getDescription() != null && !descriptorPb.getDescription().equals("")) { builder.setDescription(descriptorPb.getDescription()); } - builder.setLabels(Lists.transform(descriptorPb.getLabelsList(), - LabelDescriptor.FROM_PB_FUNCTION)); + builder.setLabels( + Lists.transform(descriptorPb.getLabelsList(), LabelDescriptor.FROM_PB_FUNCTION)); return builder.build(); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java index c95b6b62b3..72e0e858b4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/PageImpl.java @@ -108,7 +108,6 @@ public String getNextPageToken() { return cursor; } - @Override public Page getNextPage() { if (cursor == null || pageFetcher == null) { @@ -128,15 +127,14 @@ public boolean equals(Object obj) { return false; } PageImpl other = (PageImpl) obj; - return Objects.equals(cursor, other.cursor) - && Objects.equals(results, other.results); + return Objects.equals(cursor, other.cursor) && Objects.equals(results, other.results); } /** * Utility method to construct the options map for the next page request. * - * @param the value type that the page holds. Instances of {@code T} should be - * {@code Serializable} + * @param the value type that the page holds. Instances of {@code T} should be {@code + * Serializable} * @param pageTokenOption the key for the next page cursor option in the options map * @param cursor the cursor for the next page * @param optionMap the previous options map diff --git a/google-cloud-core/src/main/java/com/google/cloud/Policy.java b/google-cloud-core/src/main/java/com/google/cloud/Policy.java index 474e19fc2e..84067ec87e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Policy.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Policy.java @@ -28,7 +28,6 @@ import com.google.common.collect.Lists; import com.google.common.io.BaseEncoding; import com.google.protobuf.ByteString; - import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -60,8 +59,7 @@ public final class Policy implements Serializable { public abstract static class Marshaller { @InternalApi("This class should only be extended within google-cloud-java") - protected Marshaller() { - } + protected Marshaller() {} protected static final ApiFunction IDENTITY_VALUE_OF_FUNCTION = new ApiFunction() { @@ -89,19 +87,24 @@ public static class DefaultMarshaller extends Marshaller> bindings = new HashMap<>(); for (com.google.iam.v1.Binding bindingPb : policyPb.getBindingsList()) { - bindings.put(Role.of(bindingPb.getRole()), + bindings.put( + Role.of(bindingPb.getRole()), ImmutableSet.copyOf( - Lists.transform(bindingPb.getMembersList(), new Function() { - @Override - public Identity apply(String s) { - return IDENTITY_VALUE_OF_FUNCTION.apply(s); - } - }))); + Lists.transform( + bindingPb.getMembersList(), + new Function() { + @Override + public Identity apply(String s) { + return IDENTITY_VALUE_OF_FUNCTION.apply(s); + } + }))); } return newBuilder() .setBindings(bindings) - .setEtag(policyPb.getEtag().isEmpty() ? null - : BaseEncoding.base64().encode(policyPb.getEtag().toByteArray())) + .setEtag( + policyPb.getEtag().isEmpty() + ? null + : BaseEncoding.base64().encode(policyPb.getEtag().toByteArray())) .setVersion(policyPb.getVersion()) .build(); } @@ -114,12 +117,14 @@ protected com.google.iam.v1.Policy toPb(Policy policy) { com.google.iam.v1.Binding.Builder bindingBuilder = com.google.iam.v1.Binding.newBuilder(); bindingBuilder.setRole(binding.getKey().getValue()); bindingBuilder.addAllMembers( - Lists.transform(new ArrayList<>(binding.getValue()), new Function() { - @Override - public String apply(Identity identity) { - return IDENTITY_STR_VALUE_FUNCTION.apply(identity); - } - })); + Lists.transform( + new ArrayList<>(binding.getValue()), + new Function() { + @Override + public String apply(Identity identity) { + return IDENTITY_STR_VALUE_FUNCTION.apply(identity); + } + })); bindingPbList.add(bindingBuilder.build()); } policyBuilder.addAllBindings(bindingPbList); @@ -131,9 +136,7 @@ public String apply(Identity identity) { } } - /** - * A builder for {@code Policy} objects. - */ + /** A builder for {@code Policy} objects. */ public static class Builder { private final Map> bindings = new HashMap<>(); @@ -141,8 +144,7 @@ public static class Builder { private int version; @InternalApi("This class should only be extended within google-cloud-java") - protected Builder() { - } + protected Builder() {} @InternalApi("This class should only be extended within google-cloud-java") protected Builder(Policy policy) { @@ -151,7 +153,6 @@ protected Builder(Policy policy) { setVersion(policy.version); } - /** * Replaces the builder's map of bindings with the given map of bindings. * @@ -173,9 +174,7 @@ public final Builder setBindings(Map> bindings) { return this; } - /** - * Removes the role (and all identities associated with that role) from the policy. - */ + /** Removes the role (and all identities associated with that role) from the policy. */ public final Builder removeRole(Role role) { bindings.remove(role); return this; @@ -229,7 +228,7 @@ public final Builder removeIdentity(Role role, Identity first, Identity... other * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid * race conditions. An etag is returned in the response to getIamPolicy, and systems are * expected to put that etag in the request to setIamPolicy to ensure that their change will be - * applied to the same version of the policy. If no etag is provided in the call to + * applied to the same version of the policy. If no etag is provided in the call to * setIamPolicy, then the existing policy is overwritten blindly. */ public final Builder setEtag(String etag) { @@ -237,7 +236,6 @@ public final Builder setEtag(String etag) { return this; } - /** * Sets the version of the policy. The default version is 0, meaning only the "owner", "editor", * and "viewer" roles are permitted. If the version is 1, you may also use other roles. @@ -247,9 +245,7 @@ protected final Builder setVersion(int version) { return this; } - /** - * Creates a {@code Policy} object. - */ + /** Creates a {@code Policy} object. */ public final Policy build() { return new Policy(this); } @@ -265,38 +261,31 @@ private Policy(Builder builder) { this.version = builder.version; } - /** - * Returns a builder containing the properties of this IAM Policy. - */ + /** Returns a builder containing the properties of this IAM Policy. */ public Builder toBuilder() { return new Builder(this); } - - /** - * Returns the map of bindings that comprises the policy. - */ + /** Returns the map of bindings that comprises the policy. */ public Map> getBindings() { return bindings; } - /** * Returns the policy's etag. * *

    Etags are used for optimistic concurrency control as a way to help prevent simultaneous - * updates of a policy from overwriting each other. It is strongly suggested that systems make - * use of the etag in the read-modify-write cycle to perform policy updates in order to avoid - * race conditions. An etag is returned in the response to getIamPolicy, and systems are - * expected to put that etag in the request to setIamPolicy to ensure that their change will be - * applied to the same version of the policy. If no etag is provided in the call to - * setIamPolicy, then the existing policy is overwritten blindly. + * updates of a policy from overwriting each other. It is strongly suggested that systems make use + * of the etag in the read-modify-write cycle to perform policy updates in order to avoid race + * conditions. An etag is returned in the response to getIamPolicy, and systems are expected to + * put that etag in the request to setIamPolicy to ensure that their change will be applied to the + * same version of the policy. If no etag is provided in the call to setIamPolicy, then the + * existing policy is overwritten blindly. */ public String getEtag() { return etag; } - /** * Returns the version of the policy. The default version is 0, meaning only the "owner", * "editor", and "viewer" roles are permitted. If the version is 1, you may also use other roles. @@ -333,10 +322,7 @@ public boolean equals(Object obj) { && Objects.equals(version, other.getVersion()); } - - /** - * Returns a builder for {@code Policy} objects. - */ + /** Returns a builder for {@code Policy} objects. */ public static Builder newBuilder() { return new Builder(); } diff --git a/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java index dc30ae67d0..e0a8f5f50b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ReadChannel.java @@ -26,7 +26,6 @@ *

    Implementations of this class may buffer data internally to reduce remote calls. This * interface implements {@link Restorable} to allow saving the reader's state to continue reading * afterwards. - *

    */ public interface ReadChannel extends ReadableByteChannel, Closeable, Restorable { @@ -40,10 +39,9 @@ public interface ReadChannel extends ReadableByteChannel, Closeable, Restorable< void seek(long position) throws IOException; - /** - * Sets the minimum size that will be read by a single RPC. - * Read data will be locally buffered until consumed. + * Sets the minimum size that will be read by a single RPC. Read data will be locally buffered + * until consumed. */ void setChunkSize(int chunkSize); diff --git a/google-cloud-core/src/main/java/com/google/cloud/Restorable.java b/google-cloud-core/src/main/java/com/google/cloud/Restorable.java index d4b961d0a5..7feedf0c6e 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Restorable.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Restorable.java @@ -20,14 +20,16 @@ * Implementation of this interface can persist their state and restore from it. * *

    A typical capture usage: - *

     {@code
    + *
    + * 
    {@code
      * X restorableObj; // X instanceof Restorable
      * RestorableState state = restorableObj.capture();
      * .. persist state
      * }
    * *

    A typical restore usage: - *

     {@code
    + *
    + * 
    {@code
      * RestorableState state = ... // read from persistence
      * X restorableObj = state.restore();
      * ...
    diff --git a/google-cloud-core/src/main/java/com/google/cloud/RestorableState.java b/google-cloud-core/src/main/java/com/google/cloud/RestorableState.java
    index 8e539812c8..53a6458f1f 100644
    --- a/google-cloud-core/src/main/java/com/google/cloud/RestorableState.java
    +++ b/google-cloud-core/src/main/java/com/google/cloud/RestorableState.java
    @@ -27,8 +27,6 @@
      */
     public interface RestorableState> {
     
    -  /**
    -   * Returns an object whose internal state reflects the one saved in the invocation object.
    -   */
    +  /** Returns an object whose internal state reflects the one saved in the invocation object. */
       T restore();
     }
    diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java
    index dd6e4c6926..986fd35587 100644
    --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java
    +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java
    @@ -18,13 +18,12 @@
     
     import com.google.api.core.ApiClock;
     import com.google.api.core.BetaApi;
    -import com.google.api.gax.retrying.ExponentialPollAlgorithm;
    -import com.google.api.gax.retrying.ResultRetryAlgorithm;
    -import com.google.api.gax.retrying.RetrySettings;
    -
     import com.google.api.gax.retrying.DirectRetryingExecutor;
    +import com.google.api.gax.retrying.ExponentialPollAlgorithm;
     import com.google.api.gax.retrying.ExponentialRetryAlgorithm;
    +import com.google.api.gax.retrying.ResultRetryAlgorithm;
     import com.google.api.gax.retrying.RetryAlgorithm;
    +import com.google.api.gax.retrying.RetrySettings;
     import com.google.api.gax.retrying.RetryingExecutor;
     import com.google.api.gax.retrying.RetryingFuture;
     import com.google.api.gax.retrying.TimedRetryAlgorithm;
    @@ -50,7 +49,8 @@ public static  V runWithRetries(
           ResultRetryAlgorithm algorithm = (ResultRetryAlgorithm) resultRetryAlgorithm;
           return run(callable, new ExponentialRetryAlgorithm(retrySettings, clock), algorithm);
         } catch (Exception e) {
    -      //TODO: remove RetryHelperException, throw InterruptedException or ExecutionException#getCause() explicitly
    +      // TODO: remove RetryHelperException, throw InterruptedException or
    +      // ExecutionException#getCause() explicitly
           throw new RetryHelperException(e.getCause());
         }
       }
    @@ -59,20 +59,22 @@ public static  V poll(
           Callable callable,
           RetrySettings pollSettings,
           ResultRetryAlgorithm resultPollAlgorithm,
    -      ApiClock clock) throws ExecutionException, InterruptedException {
    -      return run(callable, new ExponentialPollAlgorithm(pollSettings, clock), resultPollAlgorithm);
    +      ApiClock clock)
    +      throws ExecutionException, InterruptedException {
    +    return run(callable, new ExponentialPollAlgorithm(pollSettings, clock), resultPollAlgorithm);
       }
     
       private static  V run(
           Callable callable,
           TimedRetryAlgorithm timedAlgorithm,
    -      ResultRetryAlgorithm resultAlgorithm) throws ExecutionException, InterruptedException {
    -      RetryAlgorithm retryAlgorithm = new RetryAlgorithm<>(resultAlgorithm, timedAlgorithm);
    -      RetryingExecutor executor = new DirectRetryingExecutor<>(retryAlgorithm);
    +      ResultRetryAlgorithm resultAlgorithm)
    +      throws ExecutionException, InterruptedException {
    +    RetryAlgorithm retryAlgorithm = new RetryAlgorithm<>(resultAlgorithm, timedAlgorithm);
    +    RetryingExecutor executor = new DirectRetryingExecutor<>(retryAlgorithm);
     
    -      RetryingFuture retryingFuture = executor.createFuture(callable);
    -      executor.submit(retryingFuture);
    -      return retryingFuture.get();
    +    RetryingFuture retryingFuture = executor.createFuture(callable);
    +    executor.submit(retryingFuture);
    +    return retryingFuture.get();
       }
     
       public static class RetryHelperException extends RuntimeException {
    diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java b/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java
    index fb5c0e8b4a..a1069b48a2 100644
    --- a/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java
    +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java
    @@ -19,9 +19,9 @@
     import static com.google.common.base.Preconditions.checkNotNull;
     
     import com.google.api.core.BetaApi;
    +import com.google.api.gax.retrying.RetrySettings;
     import java.io.Serializable;
     import org.threeten.bp.Duration;
    -import com.google.api.gax.retrying.RetrySettings;
     
     /**
      * This class represents an options wrapper around the {@link RetrySettings} class and is an
    diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java
    index 19988fd2ae..7151740d99 100644
    --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java
    +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceDefaults.java
    @@ -19,8 +19,9 @@
     import com.google.cloud.spi.ServiceRpcFactory;
     import java.io.Serializable;
     
    -public interface ServiceDefaults,
    -    OptionsT extends ServiceOptions> extends Serializable {
    +public interface ServiceDefaults<
    +        ServiceT extends Service, OptionsT extends ServiceOptions>
    +    extends Serializable {
       ServiceFactory getDefaultServiceFactory();
     
       ServiceRpcFactory getDefaultRpcFactory();
    diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java
    index 95eaeb44c6..3b8fefe52d 100644
    --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java
    +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceFactory.java
    @@ -19,8 +19,8 @@
     /**
      * A base interface for all service factories.
      *
    - * 

    Implementation must provide a public no-arg constructor. - * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. + *

    Implementation must provide a public no-arg constructor. Loading of a factory implementation + * is done via {@link java.util.ServiceLoader}. * * @param the service subclass * @param the {@code ServiceOptions} subclass corresponding to the service diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 99f23a8382..141c99857d 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -73,8 +73,9 @@ * @param the service subclass * @param the {@code ServiceOptions} subclass corresponding to the service */ -public abstract class ServiceOptions, - OptionsT extends ServiceOptions> implements Serializable { +public abstract class ServiceOptions< + ServiceT extends Service, OptionsT extends ServiceOptions> + implements Serializable { public static final String CREDENTIAL_ENV_NAME = "GOOGLE_APPLICATION_CREDENTIALS"; @@ -82,10 +83,10 @@ public abstract class ServiceOptions, private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; - private static final RetrySettings DEFAULT_RETRY_SETTINGS = getDefaultRetrySettingsBuilder() - .build(); - private static final RetrySettings NO_RETRY_SETTINGS = getDefaultRetrySettingsBuilder() - .setMaxAttempts(1).build(); + private static final RetrySettings DEFAULT_RETRY_SETTINGS = + getDefaultRetrySettingsBuilder().build(); + private static final RetrySettings NO_RETRY_SETTINGS = + getDefaultRetrySettingsBuilder().setMaxAttempts(1).build(); private static final long serialVersionUID = 9198896031667942014L; @@ -111,7 +112,8 @@ public abstract class ServiceOptions, * @param the {@code ServiceOptions} subclass corresponding to the service * @param the {@code ServiceOptions} builder */ - public abstract static class Builder, + public abstract static class Builder< + ServiceT extends Service, OptionsT extends ServiceOptions, B extends Builder> { @@ -147,19 +149,15 @@ protected B self() { return (B) this; } - - /** - * Sets the service factory. - */ + /** Sets the service factory. */ public B setServiceFactory(ServiceFactory serviceFactory) { this.serviceFactory = serviceFactory; return self(); } - /** - * Sets the service's clock. The clock is mainly used for testing purpose. {@link ApiClock} - * will be replaced by Java8's {@code java.time.Clock}. + * Sets the service's clock. The clock is mainly used for testing purpose. {@link ApiClock} will + * be replaced by Java8's {@code java.time.Clock}. * * @param clock the clock to set * @return the builder @@ -169,7 +167,6 @@ public B setClock(ApiClock clock) { return self(); } - /** * Sets the project ID. If no project ID is set, {@link #getDefaultProjectId()} will be used to * attempt getting the project ID from the environment. @@ -181,7 +178,6 @@ public B setProjectId(String projectId) { return self(); } - /** * Sets service host. * @@ -193,27 +189,25 @@ public B setHost(String host) { } /** - * Sets the service authentication credentials. If no credentials are set, - * {@link GoogleCredentials#getApplicationDefault()} will be used to attempt getting credentials - * from the environment. Use {@link NoCredentials#getInstance()} to skip authentication, this is + * Sets the service authentication credentials. If no credentials are set, {@link + * GoogleCredentials#getApplicationDefault()} will be used to attempt getting credentials from + * the environment. Use {@link NoCredentials#getInstance()} to skip authentication, this is * typically useful when using local service emulators. * * @param credentials authentication credentials, should not be {@code null} * @return the builder * @throws NullPointerException if {@code credentials} is {@code null}. To disable - * authentication use {@link NoCredentials#getInstance()} + * authentication use {@link NoCredentials#getInstance()} */ public B setCredentials(Credentials credentials) { this.credentials = checkNotNull(credentials); // set project id if available - if (this.projectId == null && - credentials instanceof ServiceAccountCredentials) { + if (this.projectId == null && credentials instanceof ServiceAccountCredentials) { this.projectId = ((ServiceAccountCredentials) credentials).getProjectId(); } return self(); } - /** * Sets configuration parameters for request retries. * @@ -224,7 +218,6 @@ public B setRetrySettings(RetrySettings retrySettings) { return self(); } - /** * Sets the factory for rpc services. * @@ -263,7 +256,8 @@ public B setHeaderProvider(HeaderProvider headerProvider) { } @InternalApi("This class should only be extended within google-cloud-java") - protected ServiceOptions(Class> serviceFactoryClass, + protected ServiceOptions( + Class> serviceFactoryClass, Class> rpcFactoryClass, Builder builder, ServiceDefaults serviceDefaults) { @@ -277,15 +271,19 @@ protected ServiceOptions(Class> ser host = firstNonNull(builder.host, getDefaultHost()); credentials = builder.credentials != null ? builder.credentials : defaultCredentials(); retrySettings = firstNonNull(builder.retrySettings, getDefaultRetrySettings()); - serviceFactory = firstNonNull(builder.serviceFactory, - getFromServiceLoader(serviceFactoryClass, serviceDefaults.getDefaultServiceFactory())); + serviceFactory = + firstNonNull( + builder.serviceFactory, + getFromServiceLoader(serviceFactoryClass, serviceDefaults.getDefaultServiceFactory())); serviceFactoryClassName = serviceFactory.getClass().getName(); - serviceRpcFactory = firstNonNull(builder.serviceRpcFactory, - getFromServiceLoader(rpcFactoryClass, serviceDefaults.getDefaultRpcFactory())); + serviceRpcFactory = + firstNonNull( + builder.serviceRpcFactory, + getFromServiceLoader(rpcFactoryClass, serviceDefaults.getDefaultRpcFactory())); serviceRpcFactoryClassName = serviceRpcFactory.getClass().getName(); clock = firstNonNull(builder.clock, CurrentMillisClock.getDefaultClock()); - transportOptions = firstNonNull(builder.transportOptions, - serviceDefaults.getDefaultTransportOptions()); + transportOptions = + firstNonNull(builder.transportOptions, serviceDefaults.getDefaultTransportOptions()); headerProvider = firstNonNull(builder.headerProvider, new NoHeaderProvider()); } @@ -307,12 +305,10 @@ private static GoogleCredentials defaultCredentials() { } } - protected String getDefaultHost() { return DEFAULT_HOST; } - protected String getDefaultProject() { return getDefaultProjectId(); } @@ -320,11 +316,12 @@ protected String getDefaultProject() { /** * Returns the default project ID, or {@code null} if no default project ID could be found. This * method returns the first available project ID among the following sources: + * *

      *
    1. The project ID specified by the GOOGLE_CLOUD_PROJECT environment variable *
    2. The App Engine project ID - *
    3. The project ID specified in the JSON credentials file pointed by the - * {@code GOOGLE_APPLICATION_CREDENTIALS} environment variable + *
    4. The project ID specified in the JSON credentials file pointed by the {@code + * GOOGLE_APPLICATION_CREDENTIALS} environment variable *
    5. The Google Cloud SDK project ID *
    6. The Compute Engine project ID *
    @@ -418,7 +415,7 @@ protected static String getAppEngineProjectId() { if (PlatformInformation.isOnGAEStandard7()) { projectId = getAppEngineProjectIdFromAppId(); } else { - //for GAE flex and standard Java 8 environment + // for GAE flex and standard Java 8 environment projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); if (projectId == null) { projectId = System.getenv("GCLOUD_PROJECT"); @@ -453,7 +450,9 @@ private static String getAppEngineProjectIdFromMetadataServer() throws IOExcepti HttpTransport netHttpTransport = new NetHttpTransport(); HttpRequestFactory requestFactory = netHttpTransport.createRequestFactory(); - HttpRequest request = requestFactory.buildGetRequest(url) + HttpRequest request = + requestFactory + .buildGetRequest(url) .setConnectTimeout(500) .setReadTimeout(500) .setHeaders(new HttpHeaders().set("Metadata-Flavor", "Google")); @@ -478,8 +477,8 @@ static String getServiceAccountProjectId(String credentialsPath) { try (InputStream credentialsStream = new FileInputStream(credentialsPath)) { JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); JsonObjectParser parser = new JsonObjectParser(jsonFactory); - GenericJson fileContents = parser.parseAndClose( - credentialsStream, Charsets.UTF_8, GenericJson.class); + GenericJson fileContents = + parser.parseAndClose(credentialsStream, Charsets.UTF_8, GenericJson.class); project = (String) fileContents.get("project_id"); } catch (IOException e) { // ignore @@ -488,7 +487,6 @@ static String getServiceAccountProjectId(String credentialsPath) { return project; } - /** * Returns a Service object for the current service. For instance, when using Google Cloud * Storage, it returns a Storage object. @@ -501,7 +499,6 @@ public ServiceT getService() { return service; } - /** * Returns a Service RPC object for the current service. For instance, when using Google Cloud * Storage, it returns a StorageRpc object. @@ -514,7 +511,6 @@ public ServiceRpc getRpc() { return rpc; } - /** * Returns the project ID. Return value can be null (for services that don't require a project * ID). @@ -523,24 +519,17 @@ public String getProjectId() { return projectId; } - - /** - * Returns the service host. - */ + /** Returns the service host. */ public String getHost() { return host; } - /** - * Returns the authentication credentials. - */ + /** Returns the authentication credentials. */ public Credentials getCredentials() { return credentials; } - /** - * Returns the authentication credentials. If required, credentials are scoped. - */ + /** Returns the authentication credentials. If required, credentials are scoped. */ public Credentials getScopedCredentials() { Credentials credentialsToReturn = credentials; if (credentials instanceof GoogleCredentials @@ -550,15 +539,11 @@ public Credentials getScopedCredentials() { return credentialsToReturn; } - - /** - * Returns configuration parameters for request retries. - */ + /** Returns configuration parameters for request retries. */ public RetrySettings getRetrySettings() { return retrySettings; } - /** * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to get * current time. @@ -567,9 +552,7 @@ public ApiClock getClock() { return clock; } - /** - * Returns the transport-specific options for this service. - */ + /** Returns the transport-specific options for this service. */ public TransportOptions getTransportOptions() { return transportOptions; } @@ -599,23 +582,17 @@ public String getApplicationName() { return sb.toString(); } - /** - * Returns the library's name, {@code gcloud-java}, as a string. - */ + /** Returns the library's name, {@code gcloud-java}, as a string. */ public static String getLibraryName() { return "gcloud-java"; } - /** - * Returns the library's name used by x-goog-api-client header as a string. - */ + /** Returns the library's name used by x-goog-api-client header as a string. */ public static String getGoogApiClientLibName() { return "gccl"; } - /** - * Returns the library's version as a string. - */ + /** Returns the library's version as a string. */ public String getLibraryVersion() { return GaxProperties.getLibraryVersion(this.getClass()); } @@ -643,8 +620,14 @@ public final String getUserAgent() { } protected int baseHashCode() { - return Objects.hash(projectId, host, credentials, retrySettings, serviceFactoryClassName, - serviceRpcFactoryClassName, clock); + return Objects.hash( + projectId, + host, + credentials, + retrySettings, + serviceFactoryClassName, + serviceRpcFactoryClassName, + clock); } protected boolean baseEquals(ServiceOptions other) { diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java index 6db7d6f9db..ce4bd18a6a 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceRpc.java @@ -16,6 +16,4 @@ package com.google.cloud; -public interface ServiceRpc { - -} +public interface ServiceRpc {} diff --git a/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java b/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java index ee54b3acdc..647e53f8e3 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java +++ b/google-cloud-core/src/main/java/com/google/cloud/StringEnumType.java @@ -39,13 +39,11 @@ public StringEnumType(Class clazz, ApiFunction constructor this.constructor = Preconditions.checkNotNull(constructor); } - /** - * Create a new constant and register it in the known values. - */ + /** Create a new constant and register it in the known values. */ public EnumT createAndRegister(String constant) { - EnumT instance = constructor.apply(constant); - knownValues.put(constant, instance); - return instance; + EnumT instance = constructor.apply(constant); + knownValues.put(constant, instance); + return instance; } /** @@ -62,9 +60,7 @@ public EnumT valueOfStrict(String constant) { } } - /** - * Get the enum object for the given String constant, and allow unrecognized values. - */ + /** Get the enum object for the given String constant, and allow unrecognized values. */ public EnumT valueOf(String constant) { if (constant == null || constant.isEmpty()) { throw new IllegalArgumentException("Empty enum constants not allowed."); @@ -77,9 +73,7 @@ public EnumT valueOf(String constant) { } } - /** - * Return the known values of this enum type. - */ + /** Return the known values of this enum type. */ public EnumT[] values() { Collection valueCollection = knownValues.values(); diff --git a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java index 9bfe3df815..2f1ae94218 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java +++ b/google-cloud-core/src/main/java/com/google/cloud/StringEnumValue.java @@ -21,16 +21,14 @@ /** * This represents a specific instance of a concept having a known set of acceptable String values, - * which can expand later due to new API features. Standard Java enums can't be used in such - * a context. + * which can expand later due to new API features. Standard Java enums can't be used in such a + * context. */ public abstract class StringEnumValue implements Serializable { private static final long serialVersionUID = 1501809419544297884L; private final String constant; - /** - * Don't create subclasses outside of google-cloud-java. - */ + /** Don't create subclasses outside of google-cloud-java. */ @InternalApi("This class should only be extended within google-cloud-java") protected StringEnumValue(String constant) { this.constant = Preconditions.checkNotNull(constant); diff --git a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java index 17e26d9c99..dc44f8abea 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -79,7 +79,7 @@ public static Timestamp ofTimeSecondsAndNanos(long seconds, int nanos) { */ public static Timestamp ofTimeMicroseconds(long microseconds) { long seconds = microseconds / 1_000_000; - int nanos = (int)(microseconds % 1_000_000 * 1000); + int nanos = (int) (microseconds % 1_000_000 * 1000); if (nanos < 0) { seconds--; nanos += 1_000_000_000; diff --git a/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java b/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java index 3626db0e37..e62fdddefc 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/TransportOptions.java @@ -17,8 +17,5 @@ import java.io.Serializable; -/** - * An abstraction for transport-specific options, e.g. for http1.1 vs grpc. - */ -public interface TransportOptions extends Serializable { -} +/** An abstraction for transport-specific options, e.g. for http1.1 vs grpc. */ +public interface TransportOptions extends Serializable {} diff --git a/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java index deb57b9259..947909bb66 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java @@ -29,15 +29,15 @@ public interface WriteChannel extends WritableByteChannel, Closeable, Restorable { /** - * Sets the minimum size that will be written by a single RPC. - * Written data will be buffered and only flushed upon reaching this size or closing the channel. + * Sets the minimum size that will be written by a single RPC. Written data will be buffered and + * only flushed upon reaching this size or closing the channel. */ void setChunkSize(int chunkSize); /** * Captures the write channel state so that it can be saved and restored afterwards. The original - * {@code WriteChannel} and the restored one should not both be used. Closing one channel - * causes the other channel to close; subsequent writes will fail. + * {@code WriteChannel} and the restored one should not both be used. Closing one channel causes + * the other channel to close; subsequent writes will fail. * * @return a {@link RestorableState} object that contains the write channel state and can restore * it afterwards. diff --git a/google-cloud-core/src/main/java/com/google/cloud/package-info.java b/google-cloud-core/src/main/java/com/google/cloud/package-info.java index d1212ad6bb..56d9be78d6 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/package-info.java +++ b/google-cloud-core/src/main/java/com/google/cloud/package-info.java @@ -14,7 +14,5 @@ * limitations under the License. */ -/** - * Core classes for the {@code google-cloud} library. - */ +/** Core classes for the {@code google-cloud} library. */ package com.google.cloud; diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index 841d7e3e07..00291f2b4b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -24,7 +24,6 @@ import com.google.common.io.CharStreams; import com.google.common.util.concurrent.SettableFuture; import com.google.common.util.concurrent.UncheckedExecutionException; - import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; @@ -59,9 +58,7 @@ import java.util.zip.ZipInputStream; import org.threeten.bp.Duration; -/** - * Utility class to start and stop a local service which is used by unit testing. - */ +/** Utility class to start and stop a local service which is used by unit testing. */ @InternalApi public abstract class BaseEmulatorHelper { @@ -88,9 +85,7 @@ protected BaseEmulatorHelper(String emulator, int port, String projectId) { */ protected abstract List getEmulatorRunners(); - /** - * Returns a logger. - */ + /** Returns a logger. */ protected abstract Logger getLogger(); /** @@ -108,8 +103,9 @@ protected final void startProcess(String blockUntilOutput) } } if (activeRunner != null) { - blockingProcessReader = BlockingProcessStreamReader.start(emulator, - activeRunner.getProcess().getInputStream(), blockUntilOutput, getLogger()); + blockingProcessReader = + BlockingProcessStreamReader.start( + emulator, activeRunner.getProcess().getInputStream(), blockUntilOutput, getLogger()); } else { // No available runner found. throw new IOException("No available emulator runner is found."); @@ -117,10 +113,11 @@ protected final void startProcess(String blockUntilOutput) } /** - * Waits for the local service's subprocess to terminate, - * and stop any possible thread listening for its output. + * Waits for the local service's subprocess to terminate, and stop any possible thread listening + * for its output. */ - protected final int waitForProcess(Duration timeout) throws IOException, InterruptedException, TimeoutException { + protected final int waitForProcess(Duration timeout) + throws IOException, InterruptedException, TimeoutException { if (activeRunner != null) { int exitCode = activeRunner.waitFor(timeout); activeRunner = null; @@ -133,23 +130,26 @@ protected final int waitForProcess(Duration timeout) throws IOException, Interru return 0; } - private static int waitForProcess(final Process process, Duration timeout) throws InterruptedException, TimeoutException { + private static int waitForProcess(final Process process, Duration timeout) + throws InterruptedException, TimeoutException { if (process == null) { return 0; } final SettableFuture exitValue = SettableFuture.create(); - Thread waiter = new Thread(new Runnable() { - @Override - public void run() { - try { - exitValue.set(process.waitFor()); - } catch (InterruptedException e) { - exitValue.setException(e); - } - } - }); + Thread waiter = + new Thread( + new Runnable() { + @Override + public void run() { + try { + exitValue.set(process.waitFor()); + } catch (InterruptedException e) { + exitValue.setException(e); + } + } + }); waiter.start(); try { @@ -164,38 +164,27 @@ public void run() { } } - /** - * Returns the port to which the local emulator is listening. - */ + /** Returns the port to which the local emulator is listening. */ public int getPort() { return port; } - /** - * Returns the project ID associated with the local emulator. - */ + /** Returns the project ID associated with the local emulator. */ public String getProjectId() { return projectId; } - /** - * Returns service options to access the local emulator. - */ + /** Returns service options to access the local emulator. */ public abstract T getOptions(); - /** - * Starts the local emulator. - */ + /** Starts the local emulator. */ public abstract void start() throws IOException, InterruptedException; - /** - * Stops the local emulator. - */ - public abstract void stop(Duration timeout) throws IOException, InterruptedException, TimeoutException; + /** Stops the local emulator. */ + public abstract void stop(Duration timeout) + throws IOException, InterruptedException, TimeoutException; - /** - * Resets the internal state of the emulator. - */ + /** Resets the internal state of the emulator. */ public abstract void reset() throws IOException; protected final String sendPostRequest(String request) throws IOException { @@ -225,9 +214,7 @@ protected static boolean isWindows() { return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"); } - /** - * Utility interface to start and run an emulator. - */ + /** Utility interface to start and run an emulator. */ protected interface EmulatorRunner { /** @@ -236,26 +223,17 @@ protected interface EmulatorRunner { */ boolean isAvailable(); - /** - * Starts the emulator associated to this runner. - */ + /** Starts the emulator associated to this runner. */ void start() throws IOException; - /** - * Wait for the emulator associated to this runner to terminate, - * returning the exit status. - */ + /** Wait for the emulator associated to this runner to terminate, returning the exit status. */ int waitFor(Duration timeout) throws InterruptedException, TimeoutException; - /** - * Returns the process associated to the emulator, if any. - */ + /** Returns the process associated to the emulator, if any. */ Process getProcess(); } - /** - * Utility class to start and run an emulator from the Google Cloud SDK. - */ + /** Utility class to start and run an emulator from the Google Cloud SDK. */ protected static class GcloudEmulatorRunner implements EmulatorRunner { private final List commandText; @@ -337,9 +315,7 @@ private Version getInstalledEmulatorVersion(String versionPrefix) } } - /** - * Utility class to start and run an emulator from a download URL. - */ + /** Utility class to start and run an emulator from a download URL. */ protected static class DownloadableEmulatorRunner implements EmulatorRunner { private final List commandText; @@ -349,8 +325,8 @@ protected static class DownloadableEmulatorRunner implements EmulatorRunner { private Process process; private static final Logger log = Logger.getLogger(DownloadableEmulatorRunner.class.getName()); - public DownloadableEmulatorRunner(List commandText, URL downloadUrl, - String md5CheckSum) { + public DownloadableEmulatorRunner( + List commandText, URL downloadUrl, String md5CheckSum) { this.commandText = commandText; this.md5CheckSum = md5CheckSum; this.downloadUrl = downloadUrl; @@ -370,23 +346,30 @@ public boolean isAvailable() { @Override public void start() throws IOException { - ExceptionHandler retryOnAnythingExceptionHandler = ExceptionHandler.newBuilder().retryOn(Exception.class).build(); - - Path emulatorPath = RetryHelper.runWithRetries(new Callable() { - @Override - public Path call() throws IOException { - return downloadEmulator(); - } - }, ServiceOptions.getDefaultRetrySettings(), retryOnAnythingExceptionHandler, + ExceptionHandler retryOnAnythingExceptionHandler = + ExceptionHandler.newBuilder().retryOn(Exception.class).build(); + + Path emulatorPath = + RetryHelper.runWithRetries( + new Callable() { + @Override + public Path call() throws IOException { + return downloadEmulator(); + } + }, + ServiceOptions.getDefaultRetrySettings(), + retryOnAnythingExceptionHandler, CurrentMillisClock.getDefaultClock()); - process = CommandWrapper.create() - .setCommand(commandText) - .setDirectory(emulatorPath) - // gcloud redirects all output to stderr while emulators' executables use either stdout - // or stderr with no apparent convention. To be able to properly intercept and block - // waiting for emulators to be ready we redirect everything to stdout - .setRedirectErrorStream() - .start(); + process = + CommandWrapper.create() + .setCommand(commandText) + .setDirectory(emulatorPath) + // gcloud redirects all output to stderr while emulators' executables use either + // stdout + // or stderr with no apparent convention. To be able to properly intercept and block + // waiting for emulators to be ready we redirect everything to stdout + .setRedirectErrorStream() + .start(); } @Override @@ -416,12 +399,13 @@ private Path downloadEmulator() throws IOException { log.fine("Unzipping emulator"); } ZipEntry entry = zipIn.getNextEntry(); - while (entry != null) { + while (entry != null) { File filePath = new File(emulatorFolder, entry.getName()); String canonicalEmulatorFolderPath = emulatorFolder.getCanonicalPath(); String canonicalFilePath = filePath.getCanonicalPath(); if (!canonicalFilePath.startsWith(canonicalEmulatorFolderPath + File.separator)) { - throw new IllegalStateException("Entry is outside of the target dir: " + entry.getName()); + throw new IllegalStateException( + "Entry is outside of the target dir: " + entry.getName()); } if (!entry.isDirectory()) { extractFile(zipIn, filePath); diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java index 6db3169ab0..90fbb764d5 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java @@ -19,7 +19,6 @@ import static com.google.common.base.MoreObjects.firstNonNull; import com.google.common.base.Strings; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -45,8 +44,8 @@ class BlockingProcessStreamReader extends Thread { private final String emulatorTag; private final Pattern logLinePattern; - private BlockingProcessStreamReader(String emulator, InputStream stream, String blockUntil, - Logger logger) throws IOException { + private BlockingProcessStreamReader( + String emulator, InputStream stream, String blockUntil, Logger logger) throws IOException { super("blocking-process-stream-reader"); setDaemon(true); errorReader = new BufferedReader(new InputStreamReader(stream)); @@ -66,7 +65,7 @@ public void run() { String previousLine = ""; String nextLine = ""; try { - for (;;) { + for (; ; ) { previousLine = nextLine; nextLine = errorReader.readLine(); if (nextLine == null) { @@ -131,8 +130,8 @@ private Level getLevel(String line) { } } - static BlockingProcessStreamReader start(String emulator, InputStream stream, String blockUntil, - Logger logger) throws IOException { + static BlockingProcessStreamReader start( + String emulator, InputStream stream, String blockUntil, Logger logger) throws IOException { BlockingProcessStreamReader thread = new BlockingProcessStreamReader(emulator, stream, blockUntil, logger); thread.start(); diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java b/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java index 7158c23b64..79f70150a5 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/CommandWrapper.java @@ -22,9 +22,7 @@ import java.util.ArrayList; import java.util.List; -/** - * Utility class that executes system commands on both Windows and Unix. - */ +/** Utility class that executes system commands on both Windows and Unix. */ class CommandWrapper { private final List prefix; diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java b/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java index c069bd99e4..dfdc076fdf 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/Version.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package com.google.cloud.testing; import static com.google.common.base.Preconditions.checkNotNull; @@ -23,9 +22,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -/** - * Simplified wrapper for emulator's versions. - */ +/** Simplified wrapper for emulator's versions. */ class Version implements Comparable { private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)$"); diff --git a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java index f871ab395a..241793b3be 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java @@ -22,25 +22,18 @@ import com.google.api.core.ApiFutures; import com.google.api.gax.paging.AsyncPage; import com.google.common.collect.ImmutableList; - -import org.junit.Test; - import java.util.concurrent.ExecutionException; +import org.junit.Test; public class AsyncPageImplTest { private static final ImmutableList VALUES1 = ImmutableList.of("1", "2"); private static final ImmutableList VALUES2 = ImmutableList.of("3", "4"); private static final ImmutableList VALUES3 = ImmutableList.of("5", "6"); - private static final ImmutableList ALL_VALUES = ImmutableList.builder() - .addAll(VALUES1) - .addAll(VALUES2) - .addAll(VALUES3) - .build(); - private static final ImmutableList SOME_VALUES = ImmutableList.builder() - .addAll(VALUES2) - .addAll(VALUES3) - .build(); + private static final ImmutableList ALL_VALUES = + ImmutableList.builder().addAll(VALUES1).addAll(VALUES2).addAll(VALUES3).build(); + private static final ImmutableList SOME_VALUES = + ImmutableList.builder().addAll(VALUES2).addAll(VALUES3).build(); private static class TestPageFetcher implements AsyncPageImpl.NextPageFetcher { private static final long serialVersionUID = 4703765400378593176L; @@ -67,7 +60,6 @@ public void testPage() { assertEquals(VALUES1, result.getValues()); } - @Test public void testPageAsync() throws ExecutionException, InterruptedException { final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2); @@ -78,7 +70,6 @@ public void testPageAsync() throws ExecutionException, InterruptedException { assertEquals(VALUES1, result.getValues()); } - @Test public void testIterateAll() { final AsyncPageImpl nextResult2 = new AsyncPageImpl<>(null, "c3", VALUES3); diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java index 84db30197b..5dcd1726bb 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java @@ -20,32 +20,27 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; -import org.junit.Test; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import org.junit.Test; /** - * Base class for serialization tests. To use this class in your tests override the - * {@code serializableObjects()} method to return all objects that must be serializable. Also - * override {@code restorableObjects()} method to return all restorable objects whose state must be - * tested for proper serialization. Both methods can return {@code null} if no such object needs to - * be tested. + * Base class for serialization tests. To use this class in your tests override the {@code + * serializableObjects()} method to return all objects that must be serializable. Also override + * {@code restorableObjects()} method to return all restorable objects whose state must be tested + * for proper serialization. Both methods can return {@code null} if no such object needs to be + * tested. */ public abstract class BaseSerializationTest { - /** - * Returns all objects for which correct serialization must be tested. - */ + /** Returns all objects for which correct serialization must be tested. */ protected abstract Serializable[] serializableObjects(); - /** - * Returns all restorable objects whose state must be tested for proper serialization. - */ + /** Returns all restorable objects whose state must be tested for proper serialization. */ protected abstract Restorable[] restorableObjects(); @Test diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index fed2faa883..1f6de6007b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -32,9 +32,7 @@ import java.util.Set; import org.junit.Test; -/** - * Tests for {@link BaseServiceException}. - */ +/** Tests for {@link BaseServiceException}. */ public class BaseServiceExceptionTest { private static final int CODE = 1; @@ -52,14 +50,17 @@ private static class CustomServiceException extends BaseServiceException { private static final long serialVersionUID = -195251309124875103L; public CustomServiceException(int code, String message, String reason, boolean idempotent) { - super(ExceptionData.from(code, message, reason, - BaseServiceException.isRetryable(code, reason, idempotent, RETRYABLE_ERRORS))); + super( + ExceptionData.from( + code, + message, + reason, + BaseServiceException.isRetryable(code, reason, idempotent, RETRYABLE_ERRORS))); } - private static final Set RETRYABLE_ERRORS = ImmutableSet - .of(new Error(CODE, REASON), - new Error(null, REASON), - new Error(CODE_NO_REASON, null)); + private static final Set RETRYABLE_ERRORS = + ImmutableSet.of( + new Error(CODE, REASON), new Error(null, REASON), new Error(CODE_NO_REASON, null)); } @Test @@ -84,8 +85,12 @@ public void testBaseServiceException() { serviceException = new BaseServiceException( ExceptionData.newBuilder() - .setMessage(MESSAGE).setCause(cause).setCode(CODE) - .setReason(REASON).setRetryable(RETRYABLE).setDebugInfo(DEBUG_INFO) + .setMessage(MESSAGE) + .setCause(cause) + .setCode(CODE) + .setReason(REASON) + .setRetryable(RETRYABLE) + .setDebugInfo(DEBUG_INFO) .setLocation(LOCATION) .build()); assertEquals(CODE, serviceException.getCode()); diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java index 985310f939..b5e5273420 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java @@ -38,6 +38,7 @@ public class BaseWriteChannelTest { private abstract static class CustomService implements Service {} + private abstract static class CustomServiceOptions extends ServiceOptions { @@ -59,25 +60,25 @@ protected CustomServiceOptions( private static final Random RANDOM = new Random(); private static BaseWriteChannel channel; - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule public ExpectedException thrown = ExpectedException.none(); @Before public void setUp() { - channel = new BaseWriteChannel(null, ENTITY, UPLOAD_ID) { - @Override - public RestorableState capture() { - return null; - } - - @Override - protected void flushBuffer(int length, boolean last) {} - - @Override - protected BaseState.Builder stateBuilder() { - return null; - } - }; + channel = + new BaseWriteChannel(null, ENTITY, UPLOAD_ID) { + @Override + public RestorableState capture() { + return null; + } + + @Override + protected void flushBuffer(int length, boolean last) {} + + @Override + protected BaseState.Builder stateBuilder() { + return null; + } + }; } @Test @@ -92,7 +93,6 @@ public void testConstructor() { assertEquals(DEFAULT_CHUNK_SIZE, channel.getChunkSize()); } - @Test public void testClose() throws IOException { channel.close(); diff --git a/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java b/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java index c3433016c7..42873f8643 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java @@ -21,15 +21,13 @@ import com.google.common.io.ByteStreams; import com.google.protobuf.ByteString; - -import org.junit.BeforeClass; -import org.junit.Test; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import org.junit.BeforeClass; +import org.junit.Test; public class ByteArrayTest { diff --git a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java index 31dbf6416b..5892cc718b 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java @@ -19,15 +19,13 @@ import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; +import com.google.common.testing.EqualsTester; import java.text.ParseException; import java.text.SimpleDateFormat; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import com.google.common.testing.EqualsTester; - /** Unit tests for {@link Date}. */ @RunWith(JUnit4.class) public class DateTest { diff --git a/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java index c668df83bd..96687cac33 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java @@ -22,24 +22,19 @@ import com.google.cloud.ExceptionHandler.Interceptor; import com.google.cloud.ExceptionHandler.Interceptor.RetryResult; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - import java.io.FileNotFoundException; import java.io.IOException; import java.nio.channels.ClosedByInterruptException; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicReference; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; -/** - * Tests for {@link ExceptionHandler}. - */ +/** Tests for {@link ExceptionHandler}. */ public class ExceptionHandlerTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void testVerifyCaller() { @@ -50,8 +45,7 @@ public Object call() throws IOException, InterruptedException { } } - class B extends A { - } + class B extends A {} class C extends A { @Override @@ -90,9 +84,10 @@ public Object call() throws Error { assertValidCallable(new E(), handler); assertInvalidCallable(new F(), handler); - handler = ExceptionHandler.newBuilder() - .retryOn(FileNotFoundException.class, NullPointerException.class) - .build(); + handler = + ExceptionHandler.newBuilder() + .retryOn(FileNotFoundException.class, NullPointerException.class) + .build(); assertInvalidCallable(new A(), handler); assertInvalidCallable(new B(), handler); assertValidCallable(new C(), handler); @@ -121,10 +116,13 @@ public void testShouldTry() { assertTrue(handler.shouldRetry(new ClosedByInterruptException(), null)); assertFalse(handler.shouldRetry(new RuntimeException(), null)); - ExceptionHandler.Builder builder = ExceptionHandler.newBuilder() - .retryOn(IOException.class, NullPointerException.class) - .abortOn(RuntimeException.class, ClosedByInterruptException.class, - InterruptedException.class); + ExceptionHandler.Builder builder = + ExceptionHandler.newBuilder() + .retryOn(IOException.class, NullPointerException.class) + .abortOn( + RuntimeException.class, + ClosedByInterruptException.class, + InterruptedException.class); handler = builder.build(); assertTrue(handler.shouldRetry(new IOException(), null)); @@ -135,18 +133,19 @@ public void testShouldTry() { final AtomicReference before = new AtomicReference<>(RetryResult.NO_RETRY); @SuppressWarnings("serial") - Interceptor interceptor = new Interceptor() { + Interceptor interceptor = + new Interceptor() { - @Override - public RetryResult afterEval(Exception exception, RetryResult retryResult) { - return retryResult == RetryResult.NO_RETRY ? RetryResult.RETRY : RetryResult.NO_RETRY; - } + @Override + public RetryResult afterEval(Exception exception, RetryResult retryResult) { + return retryResult == RetryResult.NO_RETRY ? RetryResult.RETRY : RetryResult.NO_RETRY; + } - @Override - public RetryResult beforeEval(Exception exception) { - return before.get(); - } - }; + @Override + public RetryResult beforeEval(Exception exception) { + return before.get(); + } + }; builder.addInterceptors(interceptor); handler = builder.build(); @@ -174,19 +173,19 @@ public RetryResult beforeEval(Exception exception) { @Test public void testNullRetryResultFromBeforeEval() { @SuppressWarnings("serial") - Interceptor interceptor = new Interceptor() { + Interceptor interceptor = + new Interceptor() { - @Override - public RetryResult beforeEval(Exception exception) { - return null; - } + @Override + public RetryResult beforeEval(Exception exception) { + return null; + } - @Override - public RetryResult afterEval(Exception exception, RetryResult retryResult) { - return RetryResult.CONTINUE_EVALUATION; - } - - }; + @Override + public RetryResult afterEval(Exception exception, RetryResult retryResult) { + return RetryResult.CONTINUE_EVALUATION; + } + }; ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build(); thrown.expect(NullPointerException.class); @@ -196,19 +195,19 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { @Test public void testNullRetryResultFromAfterEval() { @SuppressWarnings("serial") - Interceptor interceptor = new Interceptor() { - - @Override - public RetryResult beforeEval(Exception exception) { - return RetryResult.CONTINUE_EVALUATION; - } - - @Override - public RetryResult afterEval(Exception exception, RetryResult retryResult) { - return null; - } - - }; + Interceptor interceptor = + new Interceptor() { + + @Override + public RetryResult beforeEval(Exception exception) { + return RetryResult.CONTINUE_EVALUATION; + } + + @Override + public RetryResult afterEval(Exception exception, RetryResult retryResult) { + return null; + } + }; ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build(); thrown.expect(NullPointerException.class); diff --git a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java index 2048a54539..7b94ff5294 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/FieldSelectorHelperTest.java @@ -21,31 +21,32 @@ import com.google.cloud.FieldSelector.Helper; import com.google.common.collect.ImmutableList; - -import org.junit.Test; - import java.util.List; +import org.junit.Test; public class FieldSelectorHelperTest { - private static final FieldSelector FIELD1 = new FieldSelector() { - @Override - public String getSelector() { - return "field1"; - } - }; - private static final FieldSelector FIELD2 = new FieldSelector() { - @Override - public String getSelector() { - return "field2"; - } - }; - private static final FieldSelector FIELD3 = new FieldSelector() { - @Override - public String getSelector() { - return "field3"; - } - }; + private static final FieldSelector FIELD1 = + new FieldSelector() { + @Override + public String getSelector() { + return "field1"; + } + }; + private static final FieldSelector FIELD2 = + new FieldSelector() { + @Override + public String getSelector() { + return "field2"; + } + }; + private static final FieldSelector FIELD3 = + new FieldSelector() { + @Override + public String getSelector() { + return "field3"; + } + }; private static final String[] FIRST_LEVEL_FIELDS = {"firstLevel1", "firstLevel2"}; private static final List REQUIRED_FIELDS = ImmutableList.of(FIELD1, FIELD2); private static final String CONTAINER = "container"; @@ -72,8 +73,8 @@ public void testListSelector() { @Test public void testListSelectorWithExtraFields() { - String selector = Helper.listSelector(CONTAINER, REQUIRED_FIELDS, - new FieldSelector[]{FIELD3}, "field4"); + String selector = + Helper.listSelector(CONTAINER, REQUIRED_FIELDS, new FieldSelector[] {FIELD3}, "field4"); assertTrue(selector.startsWith("nextPageToken,container(")); assertTrue(selector.contains("field1")); assertTrue(selector.contains("field2")); @@ -85,8 +86,9 @@ public void testListSelectorWithExtraFields() { @Test public void testListSelectorWithFirstLevelFields() { - String selector = Helper.listSelector(FIRST_LEVEL_FIELDS, CONTAINER, REQUIRED_FIELDS, - new FieldSelector[]{FIELD3}, "field4"); + String selector = + Helper.listSelector( + FIRST_LEVEL_FIELDS, CONTAINER, REQUIRED_FIELDS, new FieldSelector[] {FIELD3}, "field4"); assertTrue(selector.contains("firstLevel1")); assertTrue(selector.contains("firstLevel2")); assertTrue(selector.contains("nextPageToken")); diff --git a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java index e4227019b3..6f419cbb67 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java @@ -40,21 +40,18 @@ public void testAllUsers() { assertNull(ALL_USERS.getValue()); } - @Test public void testAllAuthenticatedUsers() { assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS, ALL_AUTH_USERS.getType()); assertNull(ALL_AUTH_USERS.getValue()); } - @Test public void testUser() { assertEquals(Identity.Type.USER, USER.getType()); assertEquals("abc@gmail.com", USER.getValue()); } - @Test(expected = NullPointerException.class) public void testUserNullEmail() { Identity.user(null); @@ -66,7 +63,6 @@ public void testServiceAccount() { assertEquals("service-account@gmail.com", SERVICE_ACCOUNT.getValue()); } - @Test(expected = NullPointerException.class) public void testServiceAccountNullEmail() { Identity.serviceAccount(null); @@ -78,7 +74,6 @@ public void testGroup() { assertEquals("group@gmail.com", GROUP.getValue()); } - @Test(expected = NullPointerException.class) public void testGroupNullEmail() { Identity.group(null); @@ -90,7 +85,6 @@ public void testDomain() { assertEquals("google.com", DOMAIN.getValue()); } - @Test(expected = NullPointerException.class) public void testDomainNullId() { Identity.domain(null); diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java index 16c2924c84..b29896af48 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java @@ -22,10 +22,8 @@ import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor; import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor.ValueType; import com.google.common.collect.ImmutableList; - -import org.junit.Test; - import java.util.List; +import org.junit.Test; public class MonitoredResourceDescriptorTest { @@ -67,7 +65,6 @@ public void testLabelDescriptor() { assertNull(INT_LABEL_NO_DESCRIPTION.getDescription()); } - @Test public void testBuilder() { assertEquals(TYPE, RESOURCE_DESCRIPTOR.getType()); @@ -84,24 +81,23 @@ public void testBuilder() { assertEquals(ImmutableList.of(), resourceDescriptor.getLabels()); } - @Test public void testToAndFromPbLabelDescriptor() { compareLabelDescriptor(BOOLEAN_LABEL, LabelDescriptor.fromPb(BOOLEAN_LABEL.toPb())); compareLabelDescriptor(STRING_LABEL, LabelDescriptor.fromPb(STRING_LABEL.toPb())); compareLabelDescriptor(INT_LABEL, LabelDescriptor.fromPb(INT_LABEL.toPb())); - compareLabelDescriptor(INT_LABEL_NO_DESCRIPTION, - LabelDescriptor.fromPb(INT_LABEL_NO_DESCRIPTION.toPb())); + compareLabelDescriptor( + INT_LABEL_NO_DESCRIPTION, LabelDescriptor.fromPb(INT_LABEL_NO_DESCRIPTION.toPb())); } @Test public void testToAndFromPb() { - compareResourceDescriptor(RESOURCE_DESCRIPTOR, - MonitoredResourceDescriptor.fromPb(RESOURCE_DESCRIPTOR.toPb())); + compareResourceDescriptor( + RESOURCE_DESCRIPTOR, MonitoredResourceDescriptor.fromPb(RESOURCE_DESCRIPTOR.toPb())); MonitoredResourceDescriptor resourceDescriptor = MonitoredResourceDescriptor.newBuilder(TYPE).build(); - compareResourceDescriptor(resourceDescriptor, - MonitoredResourceDescriptor.fromPb(resourceDescriptor.toPb())); + compareResourceDescriptor( + resourceDescriptor, MonitoredResourceDescriptor.fromPb(resourceDescriptor.toPb())); } private void compareLabelDescriptor(LabelDescriptor expected, LabelDescriptor value) { @@ -113,8 +109,8 @@ private void compareLabelDescriptor(LabelDescriptor expected, LabelDescriptor va assertEquals(expected.toString(), value.toString()); } - private void compareResourceDescriptor(MonitoredResourceDescriptor expected, - MonitoredResourceDescriptor value) { + private void compareResourceDescriptor( + MonitoredResourceDescriptor expected, MonitoredResourceDescriptor value) { assertEquals(expected, value); assertEquals(expected.getType(), value.getType()); assertEquals(expected.getName(), value.getName()); diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java index 72c6a45dc0..6054a7aa34 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java @@ -19,56 +19,54 @@ import static org.junit.Assert.assertEquals; import com.google.common.collect.ImmutableMap; - -import org.junit.Test; - import java.util.Map; +import org.junit.Test; public class MonitoredResourceTest { private static final String TYPE = "cloudsql_database"; private static final Map LABELS = ImmutableMap.of("dataset-id", "myDataset", "zone", "myZone"); - private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.newBuilder(TYPE) - .setLabels(LABELS) - .build(); + private static final MonitoredResource MONITORED_RESOURCE = + MonitoredResource.newBuilder(TYPE).setLabels(LABELS).build(); @Test public void testBuilder() { assertEquals(TYPE, MONITORED_RESOURCE.getType()); assertEquals(LABELS, MONITORED_RESOURCE.getLabels()); - MonitoredResource monitoredResource = MonitoredResource.newBuilder(TYPE) - .addLabel("dataset-id", "myDataset") - .addLabel("zone", "myZone") - .build(); + MonitoredResource monitoredResource = + MonitoredResource.newBuilder(TYPE) + .addLabel("dataset-id", "myDataset") + .addLabel("zone", "myZone") + .build(); assertEquals(TYPE, monitoredResource.getType()); assertEquals(LABELS, monitoredResource.getLabels()); compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); - monitoredResource = MonitoredResource.newBuilder(TYPE) - .setType("global") - .addLabel("dataset-id", "myDataset") - .addLabel("zone", "myZone") - .clearLabels() - .build(); + monitoredResource = + MonitoredResource.newBuilder(TYPE) + .setType("global") + .addLabel("dataset-id", "myDataset") + .addLabel("zone", "myZone") + .clearLabels() + .build(); assertEquals("global", monitoredResource.getType()); assertEquals(ImmutableMap.of(), monitoredResource.getLabels()); } - @Test public void testToBuilder() { compareMonitoredResource(MONITORED_RESOURCE, MONITORED_RESOURCE.toBuilder().build()); - MonitoredResource monitoredResource = MONITORED_RESOURCE.toBuilder() - .setType("global") - .clearLabels() - .build(); + MonitoredResource monitoredResource = + MONITORED_RESOURCE.toBuilder().setType("global").clearLabels().build(); assertEquals("global", monitoredResource.getType()); assertEquals(ImmutableMap.of(), monitoredResource.getLabels()); - monitoredResource = monitoredResource.toBuilder() - .setType(TYPE) - .setLabels(ImmutableMap.of("dataset-id", "myDataset")) - .addLabel("zone", "myZone") - .build(); + monitoredResource = + monitoredResource + .toBuilder() + .setType(TYPE) + .setLabels(ImmutableMap.of("dataset-id", "myDataset")) + .addLabel("zone", "myZone") + .build(); compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); } @@ -82,8 +80,8 @@ public void testOf() { @Test public void testToAndFromPb() { - compareMonitoredResource(MONITORED_RESOURCE, - MonitoredResource.fromPb(MONITORED_RESOURCE.toPb())); + compareMonitoredResource( + MONITORED_RESOURCE, MonitoredResource.fromPb(MONITORED_RESOURCE.toPb())); MonitoredResource monitoredResource = MonitoredResource.of(TYPE, ImmutableMap.of()); compareMonitoredResource(monitoredResource, MonitoredResource.fromPb(monitoredResource.toPb())); diff --git a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java index 47d434ec2a..5e6a6782d6 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PageImplTest.java @@ -20,17 +20,14 @@ import com.google.api.gax.paging.Page; import com.google.common.collect.ImmutableList; - import org.junit.Test; public class PageImplTest { private static final ImmutableList VALUES = ImmutableList.of("1", "2"); private static final ImmutableList NEXT_VALUES = ImmutableList.of("3", "4"); - private static final ImmutableList ALL_VALUES = ImmutableList.builder() - .addAll(VALUES) - .addAll(NEXT_VALUES) - .build(); + private static final ImmutableList ALL_VALUES = + ImmutableList.builder().addAll(VALUES).addAll(NEXT_VALUES).build(); private static class TestPageFetcher implements PageImpl.NextPageFetcher { private static final long serialVersionUID = -8316752901403429976L; @@ -57,7 +54,6 @@ public void testPage() { assertEquals(VALUES, result.getValues()); } - @Test public void testIterateAll() { final PageImpl nextResult = new PageImpl<>(null, "c", NEXT_VALUES); diff --git a/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java b/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java index 48c8bbbc08..61d99223e4 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java @@ -26,13 +26,11 @@ import com.google.cloud.Policy.DefaultMarshaller; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; - -import org.junit.Test; - import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.junit.Test; public class PolicyTest { @@ -46,20 +44,23 @@ public class PolicyTest { private static final Role VIEWER = Role.viewer(); private static final Role EDITOR = Role.editor(); private static final Role OWNER = Role.owner(); - private static final Map> BINDINGS = ImmutableMap.of( - VIEWER, - ImmutableSet.of(USER, SERVICE_ACCOUNT, ALL_USERS), - EDITOR, - ImmutableSet.of(ALL_AUTH_USERS, GROUP, DOMAIN)); - private static final Policy SIMPLE_POLICY = Policy.newBuilder() - .addIdentity(VIEWER, USER, SERVICE_ACCOUNT, ALL_USERS) - .addIdentity(EDITOR, ALL_AUTH_USERS, GROUP, DOMAIN) - .build(); - private static final Policy FULL_POLICY = Policy.newBuilder() - .setBindings(SIMPLE_POLICY.getBindings()) - .setEtag("etag") - .setVersion(1) - .build(); + private static final Map> BINDINGS = + ImmutableMap.of( + VIEWER, + ImmutableSet.of(USER, SERVICE_ACCOUNT, ALL_USERS), + EDITOR, + ImmutableSet.of(ALL_AUTH_USERS, GROUP, DOMAIN)); + private static final Policy SIMPLE_POLICY = + Policy.newBuilder() + .addIdentity(VIEWER, USER, SERVICE_ACCOUNT, ALL_USERS) + .addIdentity(EDITOR, ALL_AUTH_USERS, GROUP, DOMAIN) + .build(); + private static final Policy FULL_POLICY = + Policy.newBuilder() + .setBindings(SIMPLE_POLICY.getBindings()) + .setEtag("etag") + .setVersion(1) + .build(); @Test public void testBuilder() { @@ -79,22 +80,26 @@ public void testBuilder() { assertEquals(ImmutableMap.of(VIEWER, BINDINGS.get(VIEWER)), policy.getBindings()); assertNull(policy.getEtag()); assertEquals(0, policy.getVersion()); - policy = policy.toBuilder() - .removeIdentity(VIEWER, USER, ALL_USERS) - .addIdentity(VIEWER, DOMAIN, GROUP) - .build(); - assertEquals(ImmutableMap.of(VIEWER, ImmutableSet.of(SERVICE_ACCOUNT, DOMAIN, GROUP)), + policy = + policy + .toBuilder() + .removeIdentity(VIEWER, USER, ALL_USERS) + .addIdentity(VIEWER, DOMAIN, GROUP) + .build(); + assertEquals( + ImmutableMap.of(VIEWER, ImmutableSet.of(SERVICE_ACCOUNT, DOMAIN, GROUP)), policy.getBindings()); assertNull(policy.getEtag()); assertEquals(0, policy.getVersion()); - policy = Policy.newBuilder() - .removeIdentity(VIEWER, USER) - .addIdentity(OWNER, USER, SERVICE_ACCOUNT) - .addIdentity(EDITOR, GROUP) - .removeIdentity(EDITOR, GROUP) - .build(); - assertEquals(ImmutableMap.of(OWNER, ImmutableSet.of(USER, SERVICE_ACCOUNT)), - policy.getBindings()); + policy = + Policy.newBuilder() + .removeIdentity(VIEWER, USER) + .addIdentity(OWNER, USER, SERVICE_ACCOUNT) + .addIdentity(EDITOR, GROUP) + .removeIdentity(EDITOR, GROUP) + .build(); + assertEquals( + ImmutableMap.of(OWNER, ImmutableSet.of(USER, SERVICE_ACCOUNT)), policy.getBindings()); assertNull(policy.getEtag()); assertEquals(0, policy.getVersion()); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java index 4ad000bb78..e1c906ca23 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java @@ -23,7 +23,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - import org.threeten.bp.Duration; public class RetryOptionTest { @@ -123,7 +122,6 @@ public void testMergeToSettings() { mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, RETRY_DELAY_MULTIPLIER); assertEquals(defRetrySettings, mergedRetrySettings); - defRetrySettings = defRetrySettings.toBuilder().setMaxAttempts(100).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, MAX_ATTEMPTS); assertEquals(defRetrySettings, mergedRetrySettings); diff --git a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java index 0101a5b6e2..d6fcdf8441 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/RoleTest.java @@ -39,7 +39,6 @@ public void testOf() { assertThat(Role.of(customRole).getValue()).isEqualTo(customRole); } - @Test public void testViewer() { assertThat(Role.viewer().getValue()).isEqualTo("roles/viewer"); diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 62030b168f..6c35c665b5 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -22,7 +22,6 @@ import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor.ValueType; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; - import java.io.Serializable; import org.threeten.bp.Duration; @@ -51,31 +50,31 @@ public class SerializationTest extends BaseSerializationTest { .build(); private static final String JSON_KEY = "{\n" - + " \"private_key_id\": \"somekeyid\",\n" - + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" - + "kAgEAAoIBAQC+K2hSuFpAdrJI\\nnCgcDz2M7t7bjdlsadsasad+fvRSW6TjNQZ3p5LLQY1kSZRqBqylRkzteMOyHg" - + "aR\\n0Pmxh3ILCND5men43j3h4eDbrhQBuxfEMalkG92sL+PNQSETY2tnvXryOvmBRwa/\\nQP/9dJfIkIDJ9Fw9N4" - + "Bhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nknddadwkwewcVxHFhcZJO+XWf6ofLUXpRwiTZakGMn8EE1uVa2" - + "LgczOjwWHGi99MFjxSer5m9\\n1tCa3/KEGKiS/YL71JvjwX3mb+cewlkcmweBKZHM2JPTk0ZednFSpVZMtycjkbLa" - + "\\ndYOS8V85AgMBewECggEBAKksaldajfDZDV6nGqbFjMiizAKJolr/M3OQw16K6o3/\\n0S31xIe3sSlgW0+UbYlF" - + "4U8KifhManD1apVSC3csafaspP4RZUHFhtBywLO9pR5c\\nr6S5aLp+gPWFyIp1pfXbWGvc5VY/v9x7ya1VEa6rXvL" - + "sKupSeWAW4tMj3eo/64ge\\nsdaceaLYw52KeBYiT6+vpsnYrEkAHO1fF/LavbLLOFJmFTMxmsNaG0tuiJHgjshB\\" - + "n82DpMCbXG9YcCgI/DbzuIjsdj2JC1cascSP//3PmefWysucBQe7Jryb6NQtASmnv\\nCdDw/0jmZTEjpe4S1lxfHp" - + "lAhHFtdgYTvyYtaLZiVVkCgYEA8eVpof2rceecw/I6\\n5ng1q3Hl2usdWV/4mZMvR0fOemacLLfocX6IYxT1zA1FF" - + "JlbXSRsJMf/Qq39mOR2\\nSpW+hr4jCoHeRVYLgsbggtrevGmILAlNoqCMpGZ6vDmJpq6ECV9olliDvpPgWOP+\\nm" - + "YPDreFBGxWvQrADNbRt2dmGsrsCgYEAyUHqB2wvJHFqdmeBsaacewzV8x9WgmeX\\ngUIi9REwXlGDW0Mz50dxpxcK" - + "CAYn65+7TCnY5O/jmL0VRxU1J2mSWyWTo1C+17L0\\n3fUqjxL1pkefwecxwecvC+gFFYdJ4CQ/MHHXU81Lwl1iWdF" - + "Cd2UoGddYaOF+KNeM\\nHC7cmqra+JsCgYEAlUNywzq8nUg7282E+uICfCB0LfwejuymR93CtsFgb7cRd6ak\\nECR" - + "8FGfCpH8ruWJINllbQfcHVCX47ndLZwqv3oVFKh6pAS/vVI4dpOepP8++7y1u\\ncoOvtreXCX6XqfrWDtKIvv0vjl" - + "HBhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nkndj5uNl5SiuVxHFhcZJO+XWf6ofLUregtevZakGMn8EE1uVa" - + "2AY7eafmoU/nZPT\\n00YB0TBATdCbn/nBSuKDESkhSg9s2GEKQZG5hBmL5uCMfo09z3SfxZIhJdlerreP\\nJ7gSi" - + "dI12N+EZxYd4xIJh/HFDgp7RRO87f+WJkofMQKBgGTnClK1VMaCRbJZPriw\\nEfeFCoOX75MxKwXs6xgrw4W//AYG" - + "GUjDt83lD6AZP6tws7gJ2IwY/qP7+lyhjEqN\\nHtfPZRGFkGZsdaksdlaksd323423d+15/UvrlRSFPNj1tWQmNKk" - + "XyRDW4IG1Oa2p\\nrALStNBx5Y9t0/LQnFI4w3aG\\n-----END PRIVATE KEY-----\\n\",\n" - + " \"client_email\": \"someclientid@developer.gserviceaccount.com\",\n" - + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" - + " \"type\": \"service_account\"\n" - + "}"; + + " \"private_key_id\": \"somekeyid\",\n" + + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" + + "kAgEAAoIBAQC+K2hSuFpAdrJI\\nnCgcDz2M7t7bjdlsadsasad+fvRSW6TjNQZ3p5LLQY1kSZRqBqylRkzteMOyHg" + + "aR\\n0Pmxh3ILCND5men43j3h4eDbrhQBuxfEMalkG92sL+PNQSETY2tnvXryOvmBRwa/\\nQP/9dJfIkIDJ9Fw9N4" + + "Bhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nknddadwkwewcVxHFhcZJO+XWf6ofLUXpRwiTZakGMn8EE1uVa2" + + "LgczOjwWHGi99MFjxSer5m9\\n1tCa3/KEGKiS/YL71JvjwX3mb+cewlkcmweBKZHM2JPTk0ZednFSpVZMtycjkbLa" + + "\\ndYOS8V85AgMBewECggEBAKksaldajfDZDV6nGqbFjMiizAKJolr/M3OQw16K6o3/\\n0S31xIe3sSlgW0+UbYlF" + + "4U8KifhManD1apVSC3csafaspP4RZUHFhtBywLO9pR5c\\nr6S5aLp+gPWFyIp1pfXbWGvc5VY/v9x7ya1VEa6rXvL" + + "sKupSeWAW4tMj3eo/64ge\\nsdaceaLYw52KeBYiT6+vpsnYrEkAHO1fF/LavbLLOFJmFTMxmsNaG0tuiJHgjshB\\" + + "n82DpMCbXG9YcCgI/DbzuIjsdj2JC1cascSP//3PmefWysucBQe7Jryb6NQtASmnv\\nCdDw/0jmZTEjpe4S1lxfHp" + + "lAhHFtdgYTvyYtaLZiVVkCgYEA8eVpof2rceecw/I6\\n5ng1q3Hl2usdWV/4mZMvR0fOemacLLfocX6IYxT1zA1FF" + + "JlbXSRsJMf/Qq39mOR2\\nSpW+hr4jCoHeRVYLgsbggtrevGmILAlNoqCMpGZ6vDmJpq6ECV9olliDvpPgWOP+\\nm" + + "YPDreFBGxWvQrADNbRt2dmGsrsCgYEAyUHqB2wvJHFqdmeBsaacewzV8x9WgmeX\\ngUIi9REwXlGDW0Mz50dxpxcK" + + "CAYn65+7TCnY5O/jmL0VRxU1J2mSWyWTo1C+17L0\\n3fUqjxL1pkefwecxwecvC+gFFYdJ4CQ/MHHXU81Lwl1iWdF" + + "Cd2UoGddYaOF+KNeM\\nHC7cmqra+JsCgYEAlUNywzq8nUg7282E+uICfCB0LfwejuymR93CtsFgb7cRd6ak\\nECR" + + "8FGfCpH8ruWJINllbQfcHVCX47ndLZwqv3oVFKh6pAS/vVI4dpOepP8++7y1u\\ncoOvtreXCX6XqfrWDtKIvv0vjl" + + "HBhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nkndj5uNl5SiuVxHFhcZJO+XWf6ofLUregtevZakGMn8EE1uVa" + + "2AY7eafmoU/nZPT\\n00YB0TBATdCbn/nBSuKDESkhSg9s2GEKQZG5hBmL5uCMfo09z3SfxZIhJdlerreP\\nJ7gSi" + + "dI12N+EZxYd4xIJh/HFDgp7RRO87f+WJkofMQKBgGTnClK1VMaCRbJZPriw\\nEfeFCoOX75MxKwXs6xgrw4W//AYG" + + "GUjDt83lD6AZP6tws7gJ2IwY/qP7+lyhjEqN\\nHtfPZRGFkGZsdaksdlaksd323423d+15/UvrlRSFPNj1tWQmNKk" + + "XyRDW4IG1Oa2p\\nrALStNBx5Y9t0/LQnFI4w3aG\\n-----END PRIVATE KEY-----\\n\",\n" + + " \"client_email\": \"someclientid@developer.gserviceaccount.com\",\n" + + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" + + " \"type\": \"service_account\"\n" + + "}"; @Override protected Serializable[] serializableObjects() { diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index cbb4dd04f1..3ce9ffd543 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -25,32 +25,29 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.api.core.ApiClock; -import com.google.api.core.CurrentMillisClock; -import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpRequest; +import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpTransport; -import com.google.api.client.http.LowLevelHttpResponse; import com.google.api.client.http.LowLevelHttpRequest; +import com.google.api.client.http.LowLevelHttpResponse; import com.google.api.client.testing.http.HttpTesting; import com.google.api.client.testing.http.MockHttpTransport; import com.google.api.client.testing.http.MockLowLevelHttpRequest; import com.google.api.client.testing.http.MockLowLevelHttpResponse; +import com.google.api.core.ApiClock; +import com.google.api.core.CurrentMillisClock; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; - +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import com.google.common.io.Files; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.Charset; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import com.google.common.io.Files; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -154,8 +151,7 @@ public class ServiceOptionsTest { TestServiceOptions.newBuilder().setProjectId("project-id").build(); private static final TestServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); private static final String LIBRARY_NAME = "gcloud-java"; - private static final Pattern APPLICATION_NAME_PATTERN = - Pattern.compile(LIBRARY_NAME + "/.*"); + private static final Pattern APPLICATION_NAME_PATTERN = Pattern.compile(LIBRARY_NAME + "/.*"); @Rule public ExpectedException thrown = ExpectedException.none(); @@ -191,8 +187,7 @@ public TestService create(TestServiceOptions options) { } } - public interface TestServiceRpcFactory - extends ServiceRpcFactory {} + public interface TestServiceRpcFactory extends ServiceRpcFactory {} private static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory { private static final TestServiceRpcFactory INSTANCE = new DefaultTestServiceRpcFactory(); @@ -209,8 +204,7 @@ private static class DefaultTestServiceRpc implements TestServiceRpc { DefaultTestServiceRpc(TestServiceOptions options) {} } - static class TestServiceOptions - extends ServiceOptions { + static class TestServiceOptions extends ServiceOptions { private static class Builder extends ServiceOptions.Builder { private Builder() {} @@ -226,12 +220,15 @@ protected TestServiceOptions build() { } private TestServiceOptions(Builder builder) { - super(TestServiceFactory.class, TestServiceRpcFactory.class, builder, + super( + TestServiceFactory.class, + TestServiceRpcFactory.class, + builder, new TestServiceDefaults()); } - private static class TestServiceDefaults implements - ServiceDefaults { + private static class TestServiceDefaults + implements ServiceDefaults { @Override public TestServiceFactory getDefaultServiceFactory() { @@ -280,8 +277,7 @@ public void testBuilder() { assertSame(TEST_CLOCK, OPTIONS.getClock()); assertEquals("host", OPTIONS.getHost()); assertEquals("project-id", OPTIONS.getProjectId()); - assertSame(ServiceOptions.getNoRetrySettings(), - OPTIONS.getRetrySettings()); + assertSame(ServiceOptions.getNoRetrySettings(), OPTIONS.getRetrySettings()); assertSame(CurrentMillisClock.getDefaultClock(), DEFAULT_OPTIONS.getClock()); assertEquals("https://www.googleapis.com", DEFAULT_OPTIONS.getHost()); assertSame(ServiceOptions.getDefaultRetrySettings(), DEFAULT_OPTIONS.getRetrySettings()); @@ -307,27 +303,28 @@ public void testBuilderNullCredentials() { @Test public void testBuilderServiceAccount_setsProjectId() { - TestServiceOptions options = TestServiceOptions.newBuilder() - .setCredentials(credentialsWithProjectId) - .build(); + TestServiceOptions options = + TestServiceOptions.newBuilder().setCredentials(credentialsWithProjectId).build(); assertEquals("someprojectid", options.getProjectId()); } @Test public void testBuilderServiceAccount_explicitSetProjectIdBefore() { - TestServiceOptions options = TestServiceOptions.newBuilder() - .setProjectId("override-project-id") - .setCredentials(credentialsWithProjectId) - .build(); + TestServiceOptions options = + TestServiceOptions.newBuilder() + .setProjectId("override-project-id") + .setCredentials(credentialsWithProjectId) + .build(); assertEquals("override-project-id", options.getProjectId()); } @Test public void testBuilderServiceAccount_explicitSetProjectIdAfter() { - TestServiceOptions options = TestServiceOptions.newBuilder() - .setCredentials(credentialsWithProjectId) - .setProjectId("override-project-id") - .build(); + TestServiceOptions options = + TestServiceOptions.newBuilder() + .setCredentials(credentialsWithProjectId) + .setProjectId("override-project-id") + .build(); assertEquals("override-project-id", options.getProjectId()); } @@ -374,7 +371,8 @@ public void testGetServiceAccountProjectId() throws Exception { credentialsFile.deleteOnExit(); Files.write("{\"project_id\":\"my-project-id\"}".getBytes(), credentialsFile); - assertEquals("my-project-id", ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); + assertEquals( + "my-project-id", ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); } @Test @@ -402,29 +400,32 @@ public void testResponseHeaderContainsMetaDataFlavor() throws Exception { } @Test - public void testResponseHeaderDoesNotContainMetaDataFlavor() throws Exception { + public void testResponseHeaderDoesNotContainMetaDataFlavor() throws Exception { Multimap headers = ArrayListMultimap.create(); HttpResponse httpResponse = createHttpResponseWithHeader(headers); - assertThat(ServiceOptions.headerContainsMetadataFlavor(httpResponse)).isFalse(); + assertThat(ServiceOptions.headerContainsMetadataFlavor(httpResponse)).isFalse(); } - private HttpResponse createHttpResponseWithHeader(final Multimap headers) throws Exception { - HttpTransport mockHttpTransport = new MockHttpTransport() { - @Override - public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { - return new MockLowLevelHttpRequest() { + private HttpResponse createHttpResponseWithHeader(final Multimap headers) + throws Exception { + HttpTransport mockHttpTransport = + new MockHttpTransport() { @Override - public LowLevelHttpResponse execute() throws IOException { - MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); - for (Map.Entry entry : headers.entries()) { - response.addHeader(entry.getKey(), entry.getValue()); - } - return response; + public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { + return new MockLowLevelHttpRequest() { + @Override + public LowLevelHttpResponse execute() throws IOException { + MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); + for (Map.Entry entry : headers.entries()) { + response.addHeader(entry.getKey(), entry.getValue()); + } + return response; + } + }; } }; - } - }; - HttpRequest request = mockHttpTransport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL); + HttpRequest request = + mockHttpTransport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL); return request.execute(); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java index 362ef4529c..6240e8b868 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java @@ -26,8 +26,7 @@ public class StringEnumTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); + @Rule public ExpectedException expectedException = ExpectedException.none(); public static class Letter extends StringEnumValue { private static final long serialVersionUID = -1717976087182628526L; @@ -44,9 +43,8 @@ public Letter apply(String constant) { } }; - private static final StringEnumType type = new StringEnumType( - Letter.class, - CONSTRUCTOR); + private static final StringEnumType type = + new StringEnumType(Letter.class, CONSTRUCTOR); public static final Letter A = type.createAndRegister("A"); public static final Letter B = type.createAndRegister("B"); @@ -56,16 +54,12 @@ public static Letter valueOfStrict(String constant) { return type.valueOfStrict(constant); } - /** - * Get the StorageClass for the given String constant, and allow unrecognized values. - */ + /** Get the StorageClass for the given String constant, and allow unrecognized values. */ public static Letter valueOf(String constant) { return type.valueOf(constant); } - /** - * Return the known values for StorageClass. - */ + /** Return the known values for StorageClass. */ public static Letter[] values() { return type.values(); } @@ -110,8 +104,8 @@ public void testEquals() { tester.addEqualityGroup(Letter.A, Letter.valueOf("A"), Letter.valueOfStrict("A")); tester.addEqualityGroup(Letter.B, Letter.valueOf("B"), Letter.valueOfStrict("B")); tester.addEqualityGroup(Letter.C, Letter.valueOf("C"), Letter.valueOfStrict("C")); - tester - .addEqualityGroup(Letter.valueOf("NonExistentLetter"), Letter.valueOf("NonExistentLetter")); + tester.addEqualityGroup( + Letter.valueOf("NonExistentLetter"), Letter.valueOf("NonExistentLetter")); } @Test diff --git a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java index c78f54627c..8a72abbee4 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java @@ -86,7 +86,7 @@ public void ofDate() { public void ofDatePreEpoch() { Timestamp timestamp = Timestamp.of(TEST_DATE_PRE_EPOCH); long expectedSeconds = TEST_TIME_MILLISECONDS_NEGATIVE / 1_000; - int expectedNanos = (int)(TEST_TIME_MILLISECONDS_NEGATIVE % 1_000 * 1000_000); + int expectedNanos = (int) (TEST_TIME_MILLISECONDS_NEGATIVE % 1_000 * 1000_000); if (expectedNanos < 0) { expectedSeconds--; expectedNanos += 1_000_000_000; diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java index 7cb4a4ab07..3a799e2044 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java @@ -20,7 +20,6 @@ import com.google.cloud.ServiceOptions; import com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner; import com.google.common.collect.ImmutableList; - import java.io.ByteArrayInputStream; import java.io.EOFException; import java.io.File; @@ -103,7 +102,8 @@ public void testEmulatorHelper() throws IOException, InterruptedException, Timeo } @Test - public void testEmulatorHelperDownloadWithRetries() throws IOException, InterruptedException, TimeoutException { + public void testEmulatorHelperDownloadWithRetries() + throws IOException, InterruptedException, TimeoutException { String mockExternalForm = "mockExternalForm"; String mockInputStream = "mockInputStream"; String mockProtocol = "mockProtocol"; @@ -114,31 +114,37 @@ public void testEmulatorHelperDownloadWithRetries() throws IOException, Interrup URLConnection mockURLConnection = EasyMock.mock(URLConnection.class); EasyMock.expect(mockURLStreamHandler.toExternalForm(EasyMock.anyObject(URL.class))) - .andReturn(mockExternalForm).anyTimes(); + .andReturn(mockExternalForm) + .anyTimes(); EasyMock.expect(mockURLConnection.getInputStream()) - .andReturn(new ByteArrayInputStream(mockInputStream.getBytes())).anyTimes(); + .andReturn(new ByteArrayInputStream(mockInputStream.getBytes())) + .anyTimes(); EasyMock.expect(mockURLStreamHandler.openConnection(EasyMock.anyObject(URL.class))) - .andThrow(new EOFException()).times(1); + .andThrow(new EOFException()) + .times(1); EasyMock.expect(mockURLStreamHandler.openConnection(EasyMock.anyObject(URL.class))) - .andReturn(mockURLConnection).times(1); + .andReturn(mockURLConnection) + .times(1); EasyMock.replay(mockURLStreamHandler, mockURLConnection); URL url = new URL(mockProtocol, null, 0, mockFile, mockURLStreamHandler); BaseEmulatorHelper.DownloadableEmulatorRunner runner = - new BaseEmulatorHelper.DownloadableEmulatorRunner(ImmutableList.of(mockCommandText), url, null); + new BaseEmulatorHelper.DownloadableEmulatorRunner( + ImmutableList.of(mockCommandText), url, null); File cachedFile = new File(System.getProperty("java.io.tmpdir"), mockExternalForm); - cachedFile.delete(); //Clear the cached version so we're always testing the download + cachedFile.delete(); // Clear the cached version so we're always testing the download runner.start(); EasyMock.verify(); - cachedFile.delete(); //Cleanup + cachedFile.delete(); // Cleanup } @Test - public void testEmulatorHelperMultipleRunners() throws IOException, InterruptedException, TimeoutException { + public void testEmulatorHelperMultipleRunners() + throws IOException, InterruptedException, TimeoutException { Process process = EasyMock.createStrictMock(Process.class); InputStream stream = new ByteArrayInputStream(BLOCK_UNTIL.getBytes(Charsets.UTF_8)); EmulatorRunner firstRunner = EasyMock.createStrictMock(EmulatorRunner.class); @@ -160,7 +166,8 @@ public void testEmulatorHelperMultipleRunners() throws IOException, InterruptedE } /** - * URLStreamHandler has a protected method which needs to be mocked, so we need our own implementation in this package + * URLStreamHandler has a protected method which needs to be mocked, so we need our own + * implementation in this package */ private class MockURLStreamHandler extends URLStreamHandler { @Override diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java index a2c854ffb9..56b406f963 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java @@ -21,41 +21,40 @@ import com.google.api.client.util.Charsets; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.Timeout; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Timeout; public class BlockingProcessStreamReaderTest { private static final String BLOCK_UNTIL = "Dev App Server is now running"; - private static final String OUTPUT = "First Line\n" - + "Second Line\n" - + BLOCK_UNTIL; - private static final String OUTPUT_WITH_LOGS = "First Line\n" - + BLOCK_UNTIL + "\n" - + "Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" - + "INFO: log line 1\n" - + "log line 2\n" - + "Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" - + "FINE: log line 3\n"; - private static final String TAGGED_OUTPUT_WITH_LOGS = "[emulator] First Line\n" - + "[emulator]" + BLOCK_UNTIL + "\n" - + "[emulator] Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" - + "[emulator] INFO: log line 1\n" - + "[emulator] log line 2\n" - + "[emulator] Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" - + "[emulator] FINE: log line 3\n"; - - - @Rule - public Timeout globalTimeout = Timeout.seconds(10); + private static final String OUTPUT = "First Line\n" + "Second Line\n" + BLOCK_UNTIL; + private static final String OUTPUT_WITH_LOGS = + "First Line\n" + + BLOCK_UNTIL + + "\n" + + "Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" + + "INFO: log line 1\n" + + "log line 2\n" + + "Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" + + "FINE: log line 3\n"; + private static final String TAGGED_OUTPUT_WITH_LOGS = + "[emulator] First Line\n" + + "[emulator]" + + BLOCK_UNTIL + + "\n" + + "[emulator] Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" + + "[emulator] INFO: log line 1\n" + + "[emulator] log line 2\n" + + "[emulator] Nov 08, 2016 2:05:44 PM io.netty.buffer.PooledByteBufAllocator \n" + + "[emulator] FINE: log line 3\n"; + + @Rule public Timeout globalTimeout = Timeout.seconds(10); private static final class TestLogger extends Logger { @@ -79,7 +78,8 @@ public void testForwardLogEntry() throws IOException, InterruptedException { TestLogger logger = new TestLogger(); InputStream stream = new ByteArrayInputStream(OUTPUT_WITH_LOGS.getBytes(Charsets.UTF_8)); BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, logger).join(); - assertEquals("[emulator] log line 1" + System.lineSeparator() + "[emulator] log line 2", + assertEquals( + "[emulator] log line 1" + System.lineSeparator() + "[emulator] log line 2", logger.getLogs().get(Level.INFO).iterator().next()); assertEquals("[emulator] log line 3", logger.getLogs().get(Level.FINE).iterator().next()); stream.close(); @@ -90,7 +90,8 @@ public void testForwardAlreadyTaggedLogs() throws IOException, InterruptedExcept TestLogger logger = new TestLogger(); InputStream stream = new ByteArrayInputStream(TAGGED_OUTPUT_WITH_LOGS.getBytes(Charsets.UTF_8)); BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, logger).join(); - assertEquals("[emulator] log line 1" + System.lineSeparator() + "[emulator] log line 2", + assertEquals( + "[emulator] log line 1" + System.lineSeparator() + "[emulator] log line 2", logger.getLogs().get(Level.INFO).iterator().next()); assertEquals("[emulator] log line 3", logger.getLogs().get(Level.FINE).iterator().next()); stream.close(); diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java index 51f38e70db..88b246c754 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/CommandWrapperTest.java @@ -22,13 +22,11 @@ import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableList; - -import org.junit.Test; - import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import org.junit.Test; public class CommandWrapperTest { diff --git a/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java b/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java index f55659a030..4e1d88f8a2 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/testing/VersionTest.java @@ -25,8 +25,7 @@ public class VersionTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void testFromString() { From 3201041f265a6382775293e12bb22d2dad3d837a Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Tue, 4 Dec 2018 14:58:41 -0800 Subject: [PATCH 551/663] Remove exclusions for guava-jdk5 and google-api-client (#4177) We've updated the apiary clients to versions that no longer need these exclusions. --- google-cloud-core-http/pom.xml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 9011826655..7acb0241f7 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -48,34 +48,16 @@ com.google.api-client google-api-client compile - - - guava-jdk5 - com.google.guava - - com.google.http-client google-http-client-appengine compile - - - guava-jdk5 - com.google.guava - - com.google.http-client google-http-client-jackson2 compile - - - guava-jdk5 - com.google.guava - - com.google.api From 7e3c47b2341f1d239b0b64b5e07b8b99b4fa6534 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 5 Dec 2018 14:09:06 -0800 Subject: [PATCH 552/663] Document purpose of test-jar and testlib dependencies (#4164) --- google-cloud-core-grpc/pom.xml | 2 ++ google-cloud-core-http/pom.xml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index f2aa520509..ce6a5b6b93 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -77,6 +77,8 @@ com.google.api gax-grpc + + com.google.truth truth diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 7acb0241f7..0dd0cce0e8 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -63,6 +63,8 @@ com.google.api gax-httpjson + + junit junit From fdc748b5fd475739c0ff81d683417084bf8612b9 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 6 Dec 2018 16:31:48 -0800 Subject: [PATCH 553/663] Release google-cloud-java v0.73.0 (#4191) * Release v0.73.0 * Fix version replacements * Move Spanner to GA section * Fix doclint option * Fix pom issues for Bigtable emulator --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ce6a5b6b93..4ccdb948cb 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.54.1-SNAPSHOT + 1.55.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.72.1-alpha-SNAPSHOT + 0.73.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 0dd0cce0e8..b715c2f1df 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.54.1-SNAPSHOT + 1.55.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.72.1-alpha-SNAPSHOT + 0.73.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 459a26379b..06a20f5712 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.54.0 + 1.55.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.54.0' +compile 'com.google.cloud:google-cloud-core:1.55.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.54.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.55.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 82fdd52412..67af43012c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.54.1-SNAPSHOT + 1.55.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.72.1-alpha-SNAPSHOT + 0.73.0-alpha google-cloud-core From 57849c933d604cda5155ba9a85fed1bba9a8f4bd Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 6 Dec 2018 16:38:05 -0800 Subject: [PATCH 554/663] Bump next snapshot (#4192) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4ccdb948cb..981a149b80 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.55.0 + 1.55.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.73.0-alpha + 0.73.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index b715c2f1df..5acdd035db 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.55.0 + 1.55.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.73.0-alpha + 0.73.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 67af43012c..ae54ad5346 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.55.0 + 1.55.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.73.0-alpha + 0.73.1-alpha-SNAPSHOT google-cloud-core From eebaf84a306fd5c6b243571c924ae7a4186fa473 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 13 Dec 2018 15:10:31 -0800 Subject: [PATCH 555/663] Release v0.74.0 (#4222) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 981a149b80..0c552771ea 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.55.1-SNAPSHOT + 1.56.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.73.1-alpha-SNAPSHOT + 0.74.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5acdd035db..a6516e9e76 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.55.1-SNAPSHOT + 1.56.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.73.1-alpha-SNAPSHOT + 0.74.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 06a20f5712..3f70ad35b7 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.55.0 + 1.56.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.55.0' +compile 'com.google.cloud:google-cloud-core:1.56.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.55.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.56.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index ae54ad5346..f118a9d07d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.55.1-SNAPSHOT + 1.56.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.73.1-alpha-SNAPSHOT + 0.74.0-alpha google-cloud-core From d7aa8ee8fcc19608f3fd5c5dfd0a9d4d02ce2d59 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 13 Dec 2018 16:26:54 -0800 Subject: [PATCH 556/663] Bump next snapshot (#4224) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0c552771ea..db0bf74005 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.56.0 + 1.56.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.74.0-alpha + 0.74.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index a6516e9e76..5409850a0c 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.56.0 + 1.56.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.74.0-alpha + 0.74.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f118a9d07d..f5bd1611e5 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.56.0 + 1.56.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.74.0-alpha + 0.74.1-alpha-SNAPSHOT google-cloud-core From 60bbcf8d36c72b7cc89ccdeaee67fec3955a361c Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 3 Jan 2019 17:15:46 -0500 Subject: [PATCH 557/663] Release v0.75.0 (#4282) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index db0bf74005..73c4a7d20d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.56.1-SNAPSHOT + 1.57.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.74.1-alpha-SNAPSHOT + 0.75.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5409850a0c..a13721620c 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.56.1-SNAPSHOT + 1.57.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.74.1-alpha-SNAPSHOT + 0.75.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 3f70ad35b7..ae80e0c2d7 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.56.0 + 1.57.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.56.0' +compile 'com.google.cloud:google-cloud-core:1.57.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.56.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.57.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f5bd1611e5..7463d98c38 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.56.1-SNAPSHOT + 1.57.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.74.1-alpha-SNAPSHOT + 0.75.0-alpha google-cloud-core From 1cdb510e972c58812b20bec9535405c6fad40aaf Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 3 Jan 2019 17:46:17 -0500 Subject: [PATCH 558/663] Bump next snapshot (#4286) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 73c4a7d20d..516a8c42f3 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.57.0 + 1.57.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.75.0-alpha + 0.75.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index a13721620c..b8b58c2b77 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.57.0 + 1.57.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.75.0-alpha + 0.75.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7463d98c38..85ae118201 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.57.0 + 1.57.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.75.0-alpha + 0.75.1-alpha-SNAPSHOT google-cloud-core From 2660d2dd8488d11a16ae42a72b74a2e34676a62b Mon Sep 17 00:00:00 2001 From: ajaaym <34161822+ajaaym@users.noreply.github.com> Date: Fri, 4 Jan 2019 13:30:59 -0500 Subject: [PATCH 559/663] Fix #4284 NPE for getZone (#4289) --- .../src/main/java/com/google/cloud/MetadataConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java index 5c9550fe85..7234046970 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -43,7 +43,7 @@ public static String getProjectId() { public static String getZone() { String zoneId = getAttribute("instance/zone"); - if (zoneId.contains("/")) { + if (zoneId != null && zoneId.contains("/")) { return zoneId.substring(zoneId.lastIndexOf('/') + 1); } return zoneId; From bc61ec67853205983bd228512f08bafa11138e03 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Mon, 7 Jan 2019 16:22:41 -0800 Subject: [PATCH 560/663] Release v0.76.0 (#4298) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 516a8c42f3..4fa4e48bf2 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.57.1-SNAPSHOT + 1.58.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.75.1-alpha-SNAPSHOT + 0.76.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index b8b58c2b77..0cea56cbed 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.57.1-SNAPSHOT + 1.58.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.75.1-alpha-SNAPSHOT + 0.76.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index ae80e0c2d7..df46bd8040 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.57.0 + 1.58.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.57.0' +compile 'com.google.cloud:google-cloud-core:1.58.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.57.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.58.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 85ae118201..55ea4e0355 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.57.1-SNAPSHOT + 1.58.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.75.1-alpha-SNAPSHOT + 0.76.0-alpha google-cloud-core From 72ed8fa4b7b41c97a0a5df384efd14aa237558c1 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Tue, 8 Jan 2019 08:50:39 -0800 Subject: [PATCH 561/663] Bump next snapshot (#4300) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4fa4e48bf2..8798734dde 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.58.0 + 1.58.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.76.0-alpha + 0.76.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 0cea56cbed..a5ea613021 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.58.0 + 1.58.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.76.0-alpha + 0.76.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 55ea4e0355..bfaf412be7 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.58.0 + 1.58.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.76.0-alpha + 0.76.1-alpha-SNAPSHOT google-cloud-core From bb9d1e44c816fdf0374c168fe85075df515cb377 Mon Sep 17 00:00:00 2001 From: ajaaym <34161822+ajaaym@users.noreply.github.com> Date: Wed, 9 Jan 2019 17:25:15 -0500 Subject: [PATCH 562/663] Fix #4269 update metata url to FQDN (#4278) --- .../src/main/java/com/google/cloud/MetadataConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java index 7234046970..81e95eda41 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -33,7 +33,7 @@ */ public class MetadataConfig { - private static final String METADATA_URL = "http://metadata/computeMetadata/v1/"; + private static final String METADATA_URL = "http://metadata.google.internal/computeMetadata/v1/"; private MetadataConfig() {} From e2f404e18a469ae841081a11c5447b250e7c75bc Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 10 Jan 2019 16:03:52 -0500 Subject: [PATCH 563/663] Release v0.77.0 (#4324) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 8798734dde..72ee09296a 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.58.1-SNAPSHOT + 1.59.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.76.1-alpha-SNAPSHOT + 0.77.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index a5ea613021..0c47863917 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.58.1-SNAPSHOT + 1.59.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.76.1-alpha-SNAPSHOT + 0.77.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index df46bd8040..74ee83bb2e 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.58.0 + 1.59.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.58.0' +compile 'com.google.cloud:google-cloud-core:1.59.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.58.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.59.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index bfaf412be7..29256c1d8c 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.58.1-SNAPSHOT + 1.59.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.76.1-alpha-SNAPSHOT + 0.77.0-alpha google-cloud-core From 921ed0573a3701489af700f2cda9e31981b9a004 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 10 Jan 2019 20:31:39 -0500 Subject: [PATCH 564/663] Bump next snapshot (#4325) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 72ee09296a..ead2eced0d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.59.0 + 1.59.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.77.0-alpha + 0.77.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 0c47863917..8d4e42653b 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.59.0 + 1.59.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.77.0-alpha + 0.77.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 29256c1d8c..242b8d07fc 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.59.0 + 1.59.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.77.0-alpha + 0.77.1-alpha-SNAPSHOT google-cloud-core From a5c4f226ddb1b2805b61c6d7f5f405902e7ce9fa Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 17 Jan 2019 13:26:07 -0800 Subject: [PATCH 565/663] Release google-cloud-java v0.78.0 (#4386) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ead2eced0d..b005a5be72 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.59.1-SNAPSHOT + 1.60.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.77.1-alpha-SNAPSHOT + 0.78.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 8d4e42653b..c2dbef6aec 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.59.1-SNAPSHOT + 1.60.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.77.1-alpha-SNAPSHOT + 0.78.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 74ee83bb2e..b92babe05c 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.59.0 + 1.60.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.59.0' +compile 'com.google.cloud:google-cloud-core:1.60.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.59.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.60.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 242b8d07fc..efdf6565aa 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.59.1-SNAPSHOT + 1.60.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.77.1-alpha-SNAPSHOT + 0.78.0-alpha google-cloud-core From 52184709d58bdf4a1b4723ee138d9d542c355cab Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 18 Jan 2019 10:02:52 -0800 Subject: [PATCH 566/663] Bump next snapshot (#4391) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index b005a5be72..6b180cf109 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.60.0 + 1.60.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.78.0-alpha + 0.78.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index c2dbef6aec..5918e5875e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.60.0 + 1.60.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.78.0-alpha + 0.78.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index efdf6565aa..6a3ce64ea9 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.60.0 + 1.60.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.78.0-alpha + 0.78.1-alpha-SNAPSHOT google-cloud-core From 8bf437749a15a67f96698e670dd60fee6bca632b Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 23 Jan 2019 15:28:46 -0500 Subject: [PATCH 567/663] Release v0.79.0 (#4402) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 6b180cf109..b008d4fefb 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.60.1-SNAPSHOT + 1.61.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.78.1-alpha-SNAPSHOT + 0.79.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5918e5875e..279a57d5c0 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.60.1-SNAPSHOT + 1.61.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.78.1-alpha-SNAPSHOT + 0.79.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index b92babe05c..754ab4d035 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.60.0 + 1.61.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.60.0' +compile 'com.google.cloud:google-cloud-core:1.61.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.60.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.61.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6a3ce64ea9..39ce3c600d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.60.1-SNAPSHOT + 1.61.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.78.1-alpha-SNAPSHOT + 0.79.0-alpha google-cloud-core From a6c8996bb7a9a5fe66d3e96b72359f0ff251e10e Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Wed, 23 Jan 2019 19:18:53 -0500 Subject: [PATCH 568/663] Removing some unused dependencies (#4385) * Removing some unused dependencies Also, reducing scope of auto-value to provided. * Restoring Firestore auto-value * Removing more instances of easymock. --- google-cloud-core-http/pom.xml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 279a57d5c0..243238dc84 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -35,11 +35,6 @@ google-http-client compile - - com.google.oauth-client - google-oauth-client - compile - com.google.guava guava @@ -54,11 +49,6 @@ google-http-client-appengine compile - - com.google.http-client - google-http-client-jackson2 - compile - com.google.api gax-httpjson @@ -85,11 +75,6 @@ truth test - - com.google.guava - guava-testlib - test - io.opencensus opencensus-api From b5cb1a3f1eb5ab5ff63f5039c5bc9cd14600b4f1 Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Wed, 23 Jan 2019 19:19:21 -0500 Subject: [PATCH 569/663] Removing non-deprecated uses of joda time. (#4351) * Removing non-deprecated uses of joda time. This works towards #3482 * Update pom.xml * Ran `mvn com.coveo:fmt-maven-plugin:format` * Fixing a bad merge --- google-cloud-core/pom.xml | 5 ----- .../src/main/java/com/google/cloud/Timestamp.java | 4 +--- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 39ce3c600d..51495db586 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -27,11 +27,6 @@ junit test - - joda-time - joda-time - compile - com.google.http-client google-http-client diff --git a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java index dc44f8abea..02bb981313 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -26,7 +26,6 @@ import org.threeten.bp.Instant; import org.threeten.bp.LocalDateTime; import org.threeten.bp.ZoneOffset; -import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.format.DateTimeFormatter; /** @@ -46,8 +45,7 @@ public final class Timestamp implements Comparable, Serializable { public static final Timestamp MAX_VALUE = new Timestamp(253402300799L, (int) TimeUnit.SECONDS.toNanos(1) - 1); - private static final DateTimeFormatter format = - DateTimeFormatter.ISO_LOCAL_DATE_TIME.withChronology(IsoChronology.INSTANCE); + private static final DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE_TIME; private final long seconds; private final int nanos; From 140bb5c06485c8c175183a38a1b16a9458648d19 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 24 Jan 2019 13:40:36 -0500 Subject: [PATCH 570/663] Bump next snapshot (#4405) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index b008d4fefb..8e994a683e 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.61.0 + 1.61.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.79.0-alpha + 0.79.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 243238dc84..dee2182fc5 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.61.0 + 1.61.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.79.0-alpha + 0.79.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 51495db586..f55944198f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.61.0 + 1.61.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.79.0-alpha + 0.79.1-alpha-SNAPSHOT google-cloud-core From 1ddf9730d631d5a0c1fee3d5a6aa4bf80cd7a9be Mon Sep 17 00:00:00 2001 From: elisheva-qlogic <43041115+elisheva-qlogic@users.noreply.github.com> Date: Fri, 25 Jan 2019 13:26:28 -0500 Subject: [PATCH 571/663] Fixing some deprecation warnings (#4390) * fixing some deprecation warnings * updated comment --- .../src/main/java/com/google/cloud/ServiceOptions.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 141c99857d..d08b14e715 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -349,7 +349,8 @@ private static String getActiveGoogleCloudConfig(File configDir) { String activeGoogleCloudConfig = null; try { activeGoogleCloudConfig = - Files.readFirstLine(new File(configDir, "active_config"), Charset.defaultCharset()); + Files.asCharSource(new File(configDir, "active_config"), Charset.defaultCharset()) + .readFirstLine(); } catch (IOException ex) { // ignore } From bc148add345bbda721644f197e29476579443c95 Mon Sep 17 00:00:00 2001 From: andrey-qlogic <44769745+andrey-qlogic@users.noreply.github.com> Date: Thu, 7 Feb 2019 17:25:24 +0300 Subject: [PATCH 572/663] 3534: Made HttpTransportOptions constructor public. (#4439) --- .../main/java/com/google/cloud/http/HttpTransportOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java index 6802e50549..2dbcb018f8 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java @@ -120,7 +120,7 @@ public Builder setReadTimeout(int readTimeout) { } } - private HttpTransportOptions(Builder builder) { + public HttpTransportOptions(Builder builder) { httpTransportFactory = firstNonNull( builder.httpTransportFactory, From 92deafc0ce8e6eff19ce6671807f68ec13afd57f Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 7 Feb 2019 15:05:30 -0500 Subject: [PATCH 573/663] Release v0.80.0 (#4465) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 8e994a683e..4d6b340a38 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.61.1-SNAPSHOT + 1.62.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.79.1-alpha-SNAPSHOT + 0.80.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index dee2182fc5..130d2089ea 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.61.1-SNAPSHOT + 1.62.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.79.1-alpha-SNAPSHOT + 0.80.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 754ab4d035..077683adc0 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.61.0 + 1.62.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.61.0' +compile 'com.google.cloud:google-cloud-core:1.62.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.61.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.62.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f55944198f..2dc3bd9a7f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.61.1-SNAPSHOT + 1.62.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.79.1-alpha-SNAPSHOT + 0.80.0-alpha google-cloud-core From 063596c3b402d4f7281011d93b287c2af58920a8 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 7 Feb 2019 18:53:34 -0500 Subject: [PATCH 574/663] Bump next snapshot (#4467) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4d6b340a38..6c62f3522b 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.62.0 + 1.62.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.80.0-alpha + 0.80.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 130d2089ea..cacb306965 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.62.0 + 1.62.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.80.0-alpha + 0.80.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2dc3bd9a7f..15dbae2f9a 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.62.0 + 1.62.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.80.0-alpha + 0.80.1-alpha-SNAPSHOT google-cloud-core From 8232385155241a0f873cd459ccb06eefd6171256 Mon Sep 17 00:00:00 2001 From: Drew Michel Date: Fri, 8 Feb 2019 18:13:01 -0500 Subject: [PATCH 575/663] Set connect/read timeout when calling the metadata service (#4413) Otherwise callers of these methods can be waiting indefinitely. --- .../src/main/java/com/google/cloud/MetadataConfig.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java index 81e95eda41..867b0253ac 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -34,6 +34,7 @@ public class MetadataConfig { private static final String METADATA_URL = "http://metadata.google.internal/computeMetadata/v1/"; + private static final int TIMEOUT_MS = 5000; private MetadataConfig() {} @@ -69,6 +70,8 @@ public static String getAttribute(String attributeName) { try { URL url = new URL(METADATA_URL + attributeName); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setConnectTimeout(TIMEOUT_MS); + connection.setReadTimeout(TIMEOUT_MS); connection.setRequestProperty("Metadata-Flavor", "Google"); InputStream input = connection.getInputStream(); if (connection.getResponseCode() == 200) { From 0321c6660e92c1f549e13464d093ef9e94e306d0 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 21 Feb 2019 14:22:33 -0500 Subject: [PATCH 576/663] Upgrade gax dependency to 1.40.0. (#4534) * Gax dependency upgrade * Gax dependency upgrade * code formatting fix * Moving google-http-client-apache dependency to storage. --- google-cloud-core/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 15dbae2f9a..de8ee5a1ef 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -37,7 +37,6 @@ - com.google.code.findbugs jsr305 From 1bc6f30b2e621eb827be684188ecae12b1308401 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 21 Feb 2019 13:49:42 -0800 Subject: [PATCH 577/663] Release google-cloud-java v0.81.0 (#4536) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 6c62f3522b..7e41769571 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.62.1-SNAPSHOT + 1.63.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.80.1-alpha-SNAPSHOT + 0.81.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index cacb306965..5be8fbc79d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.62.1-SNAPSHOT + 1.63.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.80.1-alpha-SNAPSHOT + 0.81.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 077683adc0..d1b6c66d0b 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.62.0 + 1.63.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.62.0' +compile 'com.google.cloud:google-cloud-core:1.63.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.62.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.63.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index de8ee5a1ef..fa933b896e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.62.1-SNAPSHOT + 1.63.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.80.1-alpha-SNAPSHOT + 0.81.0-alpha google-cloud-core From 17d591e57c2df6b187b8a441ff8b5bcfb96c2a5a Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Fri, 22 Feb 2019 11:43:45 -0800 Subject: [PATCH 578/663] bump next snapshot (#4547) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 7e41769571..47801cc57c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.63.0 + 1.63.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.81.0-alpha + 0.81.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5be8fbc79d..16541b4bee 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.63.0 + 1.63.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.81.0-alpha + 0.81.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index fa933b896e..b11f39571e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.63.0 + 1.63.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.81.0-alpha + 0.81.1-alpha-SNAPSHOT google-cloud-core From 17d3a40dfaef9672ab03aaa59ce3be3082b257be Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Thu, 28 Feb 2019 20:17:07 -0500 Subject: [PATCH 579/663] Using the latest version of truth (#4597) * Using a much newer version of truth * Upgrading annotations in google-api-grpc --- google-cloud-core/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b11f39571e..7955886b15 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -81,5 +81,10 @@ guava-testlib test + + org.checkerframework + checker-compat-qual + test + From 0b5f48186a65aa57b850a685315f5211aa9cb910 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Mon, 4 Mar 2019 12:45:50 -0700 Subject: [PATCH 580/663] Release google-cloud-java v0.82.0 (#4621) * Release v0.82.0 * Change KMS versions to 1.0.0. --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 47801cc57c..4c8a672272 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.63.1-SNAPSHOT + 1.64.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.81.1-alpha-SNAPSHOT + 0.82.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 16541b4bee..c25a9108fe 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.63.1-SNAPSHOT + 1.64.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.81.1-alpha-SNAPSHOT + 0.82.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index d1b6c66d0b..3842e8406a 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.63.0 + 1.64.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.63.0' +compile 'com.google.cloud:google-cloud-core:1.64.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.63.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.64.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7955886b15..6720283445 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.63.1-SNAPSHOT + 1.64.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.81.1-alpha-SNAPSHOT + 0.82.0-alpha google-cloud-core From af79ee1f014ea653d5792715f4a3543e76852609 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Mon, 4 Mar 2019 15:54:54 -0700 Subject: [PATCH 581/663] Bump next snapshot (#4623) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4c8a672272..333b70b15f 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.64.0 + 1.64.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.82.0-alpha + 0.82.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index c25a9108fe..3fc1dc1790 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.64.0 + 1.64.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.82.0-alpha + 0.82.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6720283445..953442ea6b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.64.0 + 1.64.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.82.0-alpha + 0.82.1-alpha-SNAPSHOT google-cloud-core From 2fd7d4027754dbe7d213aa4b43568a4744465fc4 Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Sun, 10 Mar 2019 20:33:15 +0530 Subject: [PATCH 582/663] Fix Timestamp.parseTimestamp. (#4656) * Fix parseTimestamp docs * Fix timestamp without timezone offset * Fix test cases related to timestamp.parseTimestamp * added test case * Fix timestampParser and added ZoneOffset in timestampParser --- .../src/main/java/com/google/cloud/Timestamp.java | 14 +++++++++++++- .../test/java/com/google/cloud/TimestampTest.java | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java index 02bb981313..618ef9c721 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -27,6 +27,8 @@ import org.threeten.bp.LocalDateTime; import org.threeten.bp.ZoneOffset; import org.threeten.bp.format.DateTimeFormatter; +import org.threeten.bp.format.DateTimeFormatterBuilder; +import org.threeten.bp.temporal.TemporalAccessor; /** * Represents a timestamp with nanosecond precision. Timestamps cover the range [0001-01-01, @@ -47,6 +49,15 @@ public final class Timestamp implements Comparable, Serializable { private static final DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE_TIME; + private static final DateTimeFormatter timestampParser = + new DateTimeFormatterBuilder() + .appendOptional(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + .optionalStart() + .appendOffsetId() + .optionalEnd() + .toFormatter() + .withZone(ZoneOffset.UTC); + private final long seconds; private final int nanos; @@ -170,7 +181,8 @@ public com.google.protobuf.Timestamp toProto() { * the timezone offset (always ends in "Z"). */ public static Timestamp parseTimestamp(String timestamp) { - Instant instant = Instant.parse(timestamp); + TemporalAccessor temporalAccessor = timestampParser.parse(timestamp); + Instant instant = Instant.from(temporalAccessor); return ofTimeSecondsAndNanos(instant.getEpochSecond(), instant.getNano()); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java index 8a72abbee4..db9ede84dc 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java @@ -185,6 +185,15 @@ public void parseTimestamp() { .isEqualTo(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0)); } + @Test + public void parseTimestampWithoutTimeZoneOffset() { + assertThat(Timestamp.parseTimestamp("0001-01-01T00:00:00")).isEqualTo(Timestamp.MIN_VALUE); + assertThat(Timestamp.parseTimestamp("9999-12-31T23:59:59.999999999")) + .isEqualTo(Timestamp.MAX_VALUE); + assertThat(Timestamp.parseTimestamp("2015-10-12T15:14:54")) + .isEqualTo(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0)); + } + @Test public void fromProto() { com.google.protobuf.Timestamp proto = From 4b99d2a4868349987bc55ef01688a158ad0ceebc Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Mon, 11 Mar 2019 12:15:31 -0700 Subject: [PATCH 583/663] Release google-cloud-java v0.83.0 (#4665) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 333b70b15f..184e765482 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.64.1-SNAPSHOT + 1.65.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.82.1-alpha-SNAPSHOT + 0.83.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 3fc1dc1790..1a02e26b6f 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.64.1-SNAPSHOT + 1.65.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.82.1-alpha-SNAPSHOT + 0.83.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 3842e8406a..80d63a0c70 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.64.0 + 1.65.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.64.0' +compile 'com.google.cloud:google-cloud-core:1.65.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.64.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.65.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 953442ea6b..32f5a326c1 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.64.1-SNAPSHOT + 1.65.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.82.1-alpha-SNAPSHOT + 0.83.0-alpha google-cloud-core From 6919a76819a63816419dfbc28ce82903c7b80349 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Tue, 12 Mar 2019 07:09:18 -0700 Subject: [PATCH 584/663] Bump next snapshot (#4666) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 184e765482..be975207cd 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.65.0 + 1.65.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.83.0-alpha + 0.83.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 1a02e26b6f..07756a0a3c 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.65.0 + 1.65.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.83.0-alpha + 0.83.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 32f5a326c1..8bb0aaf109 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.65.0 + 1.65.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.83.0-alpha + 0.83.1-alpha-SNAPSHOT google-cloud-core From bf6c2531305208053f307d1a378d2b5a12b319b4 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 21 Mar 2019 12:59:23 -0400 Subject: [PATCH 585/663] Release v0.84.0 (#4713) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index be975207cd..ec819e8628 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.65.1-SNAPSHOT + 1.66.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.83.1-alpha-SNAPSHOT + 0.84.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 07756a0a3c..fc1ec80819 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.65.1-SNAPSHOT + 1.66.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.83.1-alpha-SNAPSHOT + 0.84.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 80d63a0c70..4ab5644adc 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.65.0 + 1.66.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.65.0' +compile 'com.google.cloud:google-cloud-core:1.66.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.65.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.66.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 8bb0aaf109..c48a1fecd3 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.65.1-SNAPSHOT + 1.66.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.83.1-alpha-SNAPSHOT + 0.84.0-alpha google-cloud-core From 05d17705ca24e39b86b23646118c631f8d653d4d Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 21 Mar 2019 22:00:42 -0400 Subject: [PATCH 586/663] Bump next snapshot (#4715) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index ec819e8628..26536116c6 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.66.0 + 1.66.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.84.0-alpha + 0.84.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index fc1ec80819..6da91ed585 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.66.0 + 1.66.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.84.0-alpha + 0.84.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c48a1fecd3..1640c9324e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.66.0 + 1.66.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.84.0-alpha + 0.84.1-alpha-SNAPSHOT google-cloud-core From 2f5b423866b194c27ed0ce75da4885079c693f5a Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Fri, 29 Mar 2019 12:22:45 -0700 Subject: [PATCH 587/663] Release google-cloud-java v0.85.0 (#4820) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 26536116c6..71bd8a487d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.66.1-SNAPSHOT + 1.67.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.84.1-alpha-SNAPSHOT + 0.85.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 6da91ed585..1a216d6d0f 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.66.1-SNAPSHOT + 1.67.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.84.1-alpha-SNAPSHOT + 0.85.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 4ab5644adc..2d179d5b9f 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.66.0 + 1.67.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.66.0' +compile 'com.google.cloud:google-cloud-core:1.67.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.66.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.67.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 1640c9324e..b3c34a3449 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.66.1-SNAPSHOT + 1.67.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.84.1-alpha-SNAPSHOT + 0.85.0-alpha google-cloud-core From 94c30e1e98871ecbfd2597e0e1e0a8efc77ead6c Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Fri, 29 Mar 2019 15:59:26 -0700 Subject: [PATCH 588/663] Bump snapshot (#4821) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 71bd8a487d..a0d9328fed 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.67.0 + 1.67.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.85.0-alpha + 0.85.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 1a216d6d0f..e7462df4fa 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.67.0 + 1.67.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.85.0-alpha + 0.85.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b3c34a3449..e7e2afd8e2 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.67.0 + 1.67.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.85.0-alpha + 0.85.1-alpha-SNAPSHOT google-cloud-core From 431d2a53cdfc9c517b24d51532a820113934997d Mon Sep 17 00:00:00 2001 From: Ray Tsang Date: Tue, 2 Apr 2019 17:59:41 -0400 Subject: [PATCH 589/663] auto close input stream (#4878) --- .../src/main/java/com/google/cloud/MetadataConfig.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java index 867b0253ac..8f1bac04ca 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -73,10 +73,11 @@ public static String getAttribute(String attributeName) { connection.setConnectTimeout(TIMEOUT_MS); connection.setReadTimeout(TIMEOUT_MS); connection.setRequestProperty("Metadata-Flavor", "Google"); - InputStream input = connection.getInputStream(); - if (connection.getResponseCode() == 200) { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, UTF_8))) { - return reader.readLine(); + try (InputStream input = connection.getInputStream()) { + if (connection.getResponseCode() == 200) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, UTF_8))) { + return reader.readLine(); + } } } } catch (IOException ignore) { From cf37b34c738b8b087c23a4992dec5a0619f77c45 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 3 Apr 2019 14:23:54 -0400 Subject: [PATCH 590/663] Release v0.86.0 (#4899) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index a0d9328fed..2812eaaa90 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.67.1-SNAPSHOT + 1.68.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.85.1-alpha-SNAPSHOT + 0.86.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index e7462df4fa..742cae1550 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.67.1-SNAPSHOT + 1.68.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.85.1-alpha-SNAPSHOT + 0.86.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 2d179d5b9f..3f993afeb9 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.67.0 + 1.68.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.67.0' +compile 'com.google.cloud:google-cloud-core:1.68.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.67.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.68.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e7e2afd8e2..6cecda3047 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.67.1-SNAPSHOT + 1.68.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.85.1-alpha-SNAPSHOT + 0.86.0-alpha google-cloud-core From b4b07dbdb522123b71962815891685d21641d618 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 3 Apr 2019 17:25:41 -0400 Subject: [PATCH 591/663] Bump next snapshot (#4900) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 2812eaaa90..e01f6c5ee4 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.68.0 + 1.68.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.86.0-alpha + 0.86.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 742cae1550..a1222ebcb6 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.68.0 + 1.68.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.86.0-alpha + 0.86.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6cecda3047..b06449360e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.68.0 + 1.68.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.86.0-alpha + 0.86.1-alpha-SNAPSHOT google-cloud-core From 6930d5551ab37b1d2656296ea7a5cdebf5ff9a8c Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 4 Apr 2019 13:37:59 -0700 Subject: [PATCH 592/663] Release v0.87.0 (#4907) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index e01f6c5ee4..e82475e3d5 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.68.1-SNAPSHOT + 1.69.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.86.1-alpha-SNAPSHOT + 0.87.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index a1222ebcb6..240a5ac040 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.68.1-SNAPSHOT + 1.69.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.86.1-alpha-SNAPSHOT + 0.87.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 3f993afeb9..3b6e75fd39 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.68.0 + 1.69.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.68.0' +compile 'com.google.cloud:google-cloud-core:1.69.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.68.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.69.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b06449360e..051f48705f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.68.1-SNAPSHOT + 1.69.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.86.1-alpha-SNAPSHOT + 0.87.0-alpha google-cloud-core From 969c0e54a5b5972dff51b346213301f31a0408ca Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 4 Apr 2019 16:07:17 -0700 Subject: [PATCH 593/663] Bump next snapshot (#4908) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index e82475e3d5..94fe713363 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.69.0 + 1.69.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.87.0-alpha + 0.87.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 240a5ac040..85d0723032 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.69.0 + 1.69.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.87.0-alpha + 0.87.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 051f48705f..78640b671b 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.69.0 + 1.69.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.87.0-alpha + 0.87.1-alpha-SNAPSHOT google-cloud-core From 0cd4d46386c060be9adcc5df332698eaa7633c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Wed, 10 Apr 2019 16:06:48 +0200 Subject: [PATCH 594/663] google-cloud-core: Optimize Date.parseDate(String) (#4920) * optimized date parsing Date parsing using a regular expression is slower than a specific implementation for the only format that is supported. * removed IntParser and added test cases * check for invalid date/year/month/day --- .../src/main/java/com/google/cloud/Date.java | 22 +++--- .../test/java/com/google/cloud/DateTest.java | 79 ++++++++++++++++++- 2 files changed, 87 insertions(+), 14 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Date.java b/google-cloud-core/src/main/java/com/google/cloud/Date.java index 442e7dca0e..d7f3b71275 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Date.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Date.java @@ -21,15 +21,12 @@ import java.io.Serializable; import java.util.Calendar; import java.util.Objects; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** Represents a Date without time, such as 2017-03-17. Date is timezone independent. */ @BetaApi("This is going to be replaced with LocalDate from threetenbp") public final class Date implements Comparable, Serializable { // Date format "yyyy-mm-dd" - private static final Pattern FORMAT_REGEXP = Pattern.compile("(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)"); private static final long serialVersionUID = 8067099123096783929L; private final int year; private final int month; @@ -57,14 +54,19 @@ public static Date fromYearMonthDay(int year, int month, int dayOfMonth) { /** @param date Data in RFC 3339 date format (yyyy-mm-dd). */ public static Date parseDate(String date) { - Matcher matcher = FORMAT_REGEXP.matcher(date); - if (!matcher.matches()) { - throw new IllegalArgumentException("Invalid date: " + date); + Preconditions.checkNotNull(date); + final String invalidDate = "Invalid date: " + date; + Preconditions.checkArgument(date.length() == 10, invalidDate); + Preconditions.checkArgument(date.charAt(4) == '-', invalidDate); + Preconditions.checkArgument(date.charAt(7) == '-', invalidDate); + try { + int year = Integer.parseInt(date.substring(0, 4)); + int month = Integer.parseInt(date.substring(5, 7)); + int dayOfMonth = Integer.parseInt(date.substring(8, 10)); + return new Date(year, month, dayOfMonth); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(invalidDate, e); } - int year = Integer.parseInt(matcher.group(1)); - int month = Integer.parseInt(matcher.group(2)); - int dayOfMonth = Integer.parseInt(matcher.group(3)); - return new Date(year, month, dayOfMonth); } /** diff --git a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java index 5892cc718b..14b6a139d0 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java @@ -18,6 +18,7 @@ import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.fail; import com.google.common.testing.EqualsTester; import java.text.ParseException; @@ -34,10 +35,80 @@ public class DateTest { @Test public void parseDate() { - Date date = Date.parseDate("2016-09-18"); - assertThat(date.getYear()).isEqualTo(2016); - assertThat(date.getMonth()).isEqualTo(9); - assertThat(date.getDayOfMonth()).isEqualTo(18); + verifyDate("2016-09-18", 2016, 9, 18); + verifyDate("2000-01-01", 2000, 1, 1); + verifyDate("9999-12-31", 9999, 12, 31); + verifyDate("0001-01-01", 1, 1, 1); + verifyDate("2000-02-29", 2000, 2, 29); // This is a valid leap year. + verifyDate("1900-02-29", 1900, 2, 29); // This is NOT a valid leap year. + verifyDate("2001-02-29", 2001, 2, 29); // Also not a valid leap year. + verifyDate("2000-04-31", 2000, 4, 31); // Not a valid date. + } + + private void verifyDate(String input, int year, int month, int day) { + Date date = Date.parseDate(input); + assertThat(date.getYear()).isEqualTo(year); + assertThat(date.getMonth()).isEqualTo(month); + assertThat(date.getDayOfMonth()).isEqualTo(day); + } + + @Test + public void parseInvalidDates() { + parseInvalidDate("2016/09/18"); + parseInvalidDate("2016 09 18"); + parseInvalidDate("2016-9-18"); + parseInvalidDate("2016-09-18T10:00"); + parseInvalidDate(""); + parseInvalidDate("test"); + parseInvalidDate("aaaa-bb-cc"); + parseInvalidDate("aaaa-01-01"); + parseInvalidDate("2019-bb-01"); + parseInvalidDate("2019-01-cc"); + parseInvalidMonth("2000-13-01"); + parseInvalidMonth("2000-00-01"); + parseInvalidDay("2000-12-32"); + parseInvalidDay("2000-12-00"); + parseInvalidDate("10000-01-01"); + parseInvalidYear("0000-01-01"); + parseInvalidYear("-001-01-01"); + parseInvalidMonth("0001--1-01"); + parseInvalidDay("0001-01--1"); + } + + private void parseInvalidDate(String input) { + try { + Date.parseDate(input); + fail("Expected exception"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage()).contains("Invalid date"); + } + } + + private void parseInvalidYear(String input) { + try { + Date.parseDate(input); + fail("Expected exception"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage()).contains("Invalid year"); + } + } + + private void parseInvalidMonth(String input) { + try { + Date.parseDate(input); + fail("Expected exception"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage()).contains("Invalid month"); + } + } + + private void parseInvalidDay(String input) { + try { + Date.parseDate(input); + fail("Expected exception"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage()).contains("Invalid day"); + } } @Test From 9dc4d93447c63b4ce5994c68ecff92be458eedfc Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 17 Apr 2019 15:06:34 -0400 Subject: [PATCH 595/663] Release google-cloud-java v0.88.0 (#4971) * Release v0.88.0 * Change version numbers to 1.0.0 for Speech and Firestore. --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 94fe713363..46cfe66797 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.69.1-SNAPSHOT + 1.70.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.87.1-alpha-SNAPSHOT + 0.88.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 85d0723032..2d0486703e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.69.1-SNAPSHOT + 1.70.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.87.1-alpha-SNAPSHOT + 0.88.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 3b6e75fd39..c845e5b620 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.69.0 + 1.70.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.69.0' +compile 'com.google.cloud:google-cloud-core:1.70.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.69.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.70.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 78640b671b..bbcf2b3323 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.69.1-SNAPSHOT + 1.70.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.87.1-alpha-SNAPSHOT + 0.88.0-alpha google-cloud-core From 33f70050647495c66eb62c40befd17a60e551a5d Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 17 Apr 2019 20:57:30 -0400 Subject: [PATCH 596/663] Bump next snapshot (#4973) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 46cfe66797..d6a730378c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.70.0 + 1.70.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.88.0-alpha + 0.88.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 2d0486703e..55cb27f895 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.70.0 + 1.70.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.88.0-alpha + 0.88.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index bbcf2b3323..e47a3aa09f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.70.0 + 1.70.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.88.0-alpha + 0.88.1-alpha-SNAPSHOT google-cloud-core From 6577190af4c4a907fddaf1b75c36c32c4905ad82 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 24 Apr 2019 13:34:10 -0700 Subject: [PATCH 597/663] Release v0.89.0 (#5009) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d6a730378c..924c135114 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.70.1-SNAPSHOT + 1.71.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.88.1-alpha-SNAPSHOT + 0.89.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 55cb27f895..d6b37bc696 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.70.1-SNAPSHOT + 1.71.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.88.1-alpha-SNAPSHOT + 0.89.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index c845e5b620..4ccdac8543 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.70.0 + 1.71.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.70.0' +compile 'com.google.cloud:google-cloud-core:1.71.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.70.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.71.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e47a3aa09f..2d0d6b2882 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.70.1-SNAPSHOT + 1.71.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.88.1-alpha-SNAPSHOT + 0.89.0-alpha google-cloud-core From bb8ab31665cd1e3fda947d4ddc729a39a959fa90 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 24 Apr 2019 15:46:47 -0700 Subject: [PATCH 598/663] Bump next snapshot (#5011) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 924c135114..5219a802fa 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.71.0 + 1.71.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.89.0-alpha + 0.89.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index d6b37bc696..6c1b1ac17e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.71.0 + 1.71.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.89.0-alpha + 0.89.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 2d0d6b2882..c9356f4a29 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.71.0 + 1.71.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.89.0-alpha + 0.89.1-alpha-SNAPSHOT google-cloud-core From e4d65261e627540a44108a5bb94bd1822f84d160 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Wed, 1 May 2019 15:44:24 -0700 Subject: [PATCH 599/663] Release v0.90.0 (#5047) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 5219a802fa..5c15138c54 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.71.1-SNAPSHOT + 1.72.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.89.1-alpha-SNAPSHOT + 0.90.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 6c1b1ac17e..687899cfc2 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.71.1-SNAPSHOT + 1.72.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.89.1-alpha-SNAPSHOT + 0.90.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 4ccdac8543..1de2131db5 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.71.0 + 1.72.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.71.0' +compile 'com.google.cloud:google-cloud-core:1.72.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.71.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.72.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c9356f4a29..0dcfe8491f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.71.1-SNAPSHOT + 1.72.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.89.1-alpha-SNAPSHOT + 0.90.0-alpha google-cloud-core From 62635e934bd2247ae548e704e3c66b6beb7a6262 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 2 May 2019 08:02:53 -0700 Subject: [PATCH 600/663] Bump next snapshot (#5048) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 5c15138c54..a7c4e43150 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.72.0 + 1.72.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.90.0-alpha + 0.90.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 687899cfc2..93174e1d48 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.72.0 + 1.72.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.90.0-alpha + 0.90.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 0dcfe8491f..44ccc4b661 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.72.0 + 1.72.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.90.0-alpha + 0.90.1-alpha-SNAPSHOT google-cloud-core From 098ac8c980087014339b66161ed4accd491bcfa0 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Tue, 7 May 2019 14:16:26 -0400 Subject: [PATCH 601/663] Release google-cloud-java v0.91.0 (#5080) * Release v0.91.0 * Tasks GA --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index a7c4e43150..4e07b5053c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.72.1-SNAPSHOT + 1.73.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.90.1-alpha-SNAPSHOT + 0.91.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 93174e1d48..8c813bf5b5 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.72.1-SNAPSHOT + 1.73.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.90.1-alpha-SNAPSHOT + 0.91.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 1de2131db5..b53bd9a11c 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.72.0 + 1.73.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.72.0' +compile 'com.google.cloud:google-cloud-core:1.73.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.72.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.73.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 44ccc4b661..23c6865b38 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.72.1-SNAPSHOT + 1.73.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.90.1-alpha-SNAPSHOT + 0.91.0-alpha google-cloud-core From a97768ed06df6aece7d8846a4fd7591e84cd3a34 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Tue, 7 May 2019 16:53:13 -0400 Subject: [PATCH 602/663] Bump next snapshot (#5081) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4e07b5053c..879b5616d4 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.73.0 + 1.73.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.91.0-alpha + 0.91.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 8c813bf5b5..27f64b37d8 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.73.0 + 1.73.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.91.0-alpha + 0.91.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 23c6865b38..f9860f3aec 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.73.0 + 1.73.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.91.0-alpha + 0.91.1-alpha-SNAPSHOT google-cloud-core From fd2e1f1513b009e89c24bebe868292a112868615 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 15 May 2019 13:49:40 -0700 Subject: [PATCH 603/663] Release v0.92.0 (#5189) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 879b5616d4..208232e84e 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.73.1-SNAPSHOT + 1.74.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.91.1-alpha-SNAPSHOT + 0.92.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 27f64b37d8..27413dc4ba 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.73.1-SNAPSHOT + 1.74.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.91.1-alpha-SNAPSHOT + 0.92.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index b53bd9a11c..10c3832315 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.73.0 + 1.74.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.73.0' +compile 'com.google.cloud:google-cloud-core:1.74.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.73.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.74.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f9860f3aec..c39ef03b11 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.73.1-SNAPSHOT + 1.74.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.91.1-alpha-SNAPSHOT + 0.92.0-alpha google-cloud-core From 16e10f9a88a7027ce872f78e75782e4214621d3d Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 15 May 2019 19:41:53 -0700 Subject: [PATCH 604/663] Bump next snapshot (#5192) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 208232e84e..0f2f9104b9 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.74.0 + 1.74.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.92.0-alpha + 0.92.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 27413dc4ba..94a9ac33a3 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.74.0 + 1.74.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.92.0-alpha + 0.92.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c39ef03b11..fcacb5dc20 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.74.0 + 1.74.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.92.0-alpha + 0.92.1-alpha-SNAPSHOT google-cloud-core From 0ad35209ba0644ae5a8b66e642f4597298d11ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Fri, 17 May 2019 19:03:52 +0200 Subject: [PATCH 605/663] default executor used non-daemon threads (#5194) The default executor for GrpcTransportOptions created non-daemon threads possibly keeping applications alive after the main method has finished. This is the cause of #2315. --- .../java/com/google/cloud/grpc/GrpcTransportOptions.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java index b003607d97..841cc8218b 100644 --- a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/GrpcTransportOptions.java @@ -31,6 +31,7 @@ import com.google.cloud.NoCredentials; import com.google.cloud.ServiceOptions; import com.google.cloud.TransportOptions; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import io.grpc.internal.SharedResourceHolder; import io.grpc.internal.SharedResourceHolder.Resource; import java.io.IOException; @@ -54,7 +55,13 @@ public class GrpcTransportOptions implements TransportOptions { new Resource() { @Override public ScheduledExecutorService create() { - ScheduledThreadPoolExecutor service = new ScheduledThreadPoolExecutor(8); + ScheduledThreadPoolExecutor service = + new ScheduledThreadPoolExecutor( + 8, + new ThreadFactoryBuilder() + .setDaemon(true) + .setNameFormat("grpc-transport-%d") + .build()); service.setKeepAliveTime(5, TimeUnit.SECONDS); service.allowCoreThreadTimeOut(true); service.setRemoveOnCancelPolicy(true); From 24667e5c27ab71bd217d6667c1cb0affefe09b13 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Wed, 22 May 2019 13:51:31 -0700 Subject: [PATCH 606/663] Allow colons in Identity values (#5029) --- .../src/main/java/com/google/cloud/Identity.java | 2 +- .../src/test/java/com/google/cloud/IdentityTest.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/Identity.java b/google-cloud-core/src/main/java/com/google/cloud/Identity.java index ba4537e83c..a3aff1ade7 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/Identity.java +++ b/google-cloud-core/src/main/java/com/google/cloud/Identity.java @@ -255,7 +255,7 @@ public String strValue() { * policy identities to {@code Identity} objects. */ public static Identity valueOf(String identityStr) { - String[] info = identityStr.split(":"); + String[] info = identityStr.split(":", 2); Type type = Type.valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, info[0])); if (info.length == 1) { return new Identity(type, null); diff --git a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java index 6f419cbb67..8f8abb170c 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/IdentityTest.java @@ -141,16 +141,18 @@ public void testValueOfEmpty() { Identity.valueOf(""); } - @Test(expected = IllegalArgumentException.class) - public void testValueOfThreePart() { - Identity.valueOf("a:b:c"); - } - @Test public void testUnrecognizedToString() { assertEquals("a:b", Identity.valueOf("a:b").strValue()); } + @Test + public void testValueOfThreePart() { + Identity identity = Identity.valueOf("a:b:c"); + assertEquals("A", identity.getType().name()); + assertEquals("b:c", identity.getValue()); + } + private void compareIdentities(Identity expected, Identity actual) { assertEquals(expected, actual); assertEquals(expected.getType(), actual.getType()); From 806d56939a2c1f5f4e165fec236caf4edf0674aa Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 22 May 2019 16:10:33 -0700 Subject: [PATCH 607/663] Release v0.93.0 (#5211) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0f2f9104b9..acab03d09f 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.74.1-SNAPSHOT + 1.75.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.92.1-alpha-SNAPSHOT + 0.93.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 94a9ac33a3..084d9e4605 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.74.1-SNAPSHOT + 1.75.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.92.1-alpha-SNAPSHOT + 0.93.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 10c3832315..fbe37aca1d 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.74.0 + 1.75.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.74.0' +compile 'com.google.cloud:google-cloud-core:1.75.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.74.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.75.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index fcacb5dc20..03146ddbd4 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.74.1-SNAPSHOT + 1.75.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.92.1-alpha-SNAPSHOT + 0.93.0-alpha google-cloud-core From 6c06f00432899829375fa5f9ff062d4449762287 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 23 May 2019 09:54:41 -0700 Subject: [PATCH 608/663] Bump next snapshot (#5212) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index acab03d09f..0b5214946d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.75.0 + 1.75.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.93.0-alpha + 0.93.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 084d9e4605..73c3b074e6 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.75.0 + 1.75.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.93.0-alpha + 0.93.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 03146ddbd4..e176e885df 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.75.0 + 1.75.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.93.0-alpha + 0.93.1-alpha-SNAPSHOT google-cloud-core From d62eb107215f8224590b55678810078ad5c17124 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 29 May 2019 15:05:40 -0400 Subject: [PATCH 609/663] Release v0.94.0 (#5238) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0b5214946d..3fa00185fb 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.75.1-SNAPSHOT + 1.76.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.93.1-alpha-SNAPSHOT + 0.94.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 73c3b074e6..5d6ace9453 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.75.1-SNAPSHOT + 1.76.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.93.1-alpha-SNAPSHOT + 0.94.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index fbe37aca1d..cbb5af7114 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.75.0 + 1.76.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.75.0' +compile 'com.google.cloud:google-cloud-core:1.76.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.75.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.76.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e176e885df..d1768d626f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.75.1-SNAPSHOT + 1.76.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.93.1-alpha-SNAPSHOT + 0.94.0-alpha google-cloud-core From 09429f966eeb32bd060df986e45fd849573d825e Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 29 May 2019 17:43:39 -0400 Subject: [PATCH 610/663] Bump next snapshot (#5239) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 3fa00185fb..9d9f90a61a 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.76.0 + 1.76.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.94.0-alpha + 0.94.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5d6ace9453..437c01cd0a 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.76.0 + 1.76.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.94.0-alpha + 0.94.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d1768d626f..ddfa377fcd 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.76.0 + 1.76.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.94.0-alpha + 0.94.1-alpha-SNAPSHOT google-cloud-core From 2d6e6196f0fa5ca37dd6d0ed624aa23b5cec7fca Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 31 May 2019 14:30:08 -0700 Subject: [PATCH 611/663] Clean up test deprecation warnings for google-cloud-core (#5259) --- .../test/java/com/google/cloud/StringEnumTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java index 6240e8b868..716e124f53 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java @@ -84,17 +84,17 @@ public void testEnumInstances() { @Test public void testValueOf() { - assertThat(Letter.valueOf("A")).isSameAs(Letter.A); - assertThat(Letter.valueOf("B")).isSameAs(Letter.B); - assertThat(Letter.valueOf("C")).isSameAs(Letter.C); + assertThat(Letter.valueOf("A")).isSameInstanceAs(Letter.A); + assertThat(Letter.valueOf("B")).isSameInstanceAs(Letter.B); + assertThat(Letter.valueOf("C")).isSameInstanceAs(Letter.C); assertThat(Letter.valueOf("NonExistentLetter").toString()).isEqualTo("NonExistentLetter"); } @Test public void testValueOfStrict() { - assertThat(Letter.valueOfStrict("A")).isSameAs(Letter.A); - assertThat(Letter.valueOfStrict("B")).isSameAs(Letter.B); - assertThat(Letter.valueOfStrict("C")).isSameAs(Letter.C); + assertThat(Letter.valueOfStrict("A")).isSameInstanceAs(Letter.A); + assertThat(Letter.valueOfStrict("B")).isSameInstanceAs(Letter.B); + assertThat(Letter.valueOfStrict("C")).isSameInstanceAs(Letter.C); } @Test From af2679bfe0b367a01d77885449172984cf6a781a Mon Sep 17 00:00:00 2001 From: abhinav-qlogic <48669998+abhinav-qlogic@users.noreply.github.com> Date: Tue, 4 Jun 2019 21:16:59 +0530 Subject: [PATCH 612/663] deprecated warnings removed (#5304) --- google-cloud-core/src/main/java/com/google/cloud/ByteArray.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java index 24857f9f64..5841c541c4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ByteArray.java @@ -117,7 +117,7 @@ public final void copyTo(ByteBuffer target) { * @throws IndexOutOfBoundsException if the target is not large enough to hold the data */ public final void copyTo(byte[] target) { - byteString.copyTo(target, 0, 0, length()); + byteString.copyTo(target, 0); } /** Creates a {@code ByteArray} object given an array of bytes. The bytes are copied. */ From 3fee37faf27c5a08b019044a862b8ed42bbe9aeb Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 6 Jun 2019 14:00:07 -0700 Subject: [PATCH 613/663] Release google-cloud-java v0.95.0 (#5438) * Release v0.95.0 * Add missing files * Fix region replace tag for securitycenter in bom * Notification tests need to run from contrib folder now --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 9d9f90a61a..36f84be4ce 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.76.1-SNAPSHOT + 1.77.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.94.1-alpha-SNAPSHOT + 0.95.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 437c01cd0a..c00d491c4b 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.76.1-SNAPSHOT + 1.77.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.94.1-alpha-SNAPSHOT + 0.95.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index cbb5af7114..90c382e871 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.76.0 + 1.77.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.76.0' +compile 'com.google.cloud:google-cloud-core:1.77.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.76.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.77.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index ddfa377fcd..8fcc4fb120 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.76.1-SNAPSHOT + 1.77.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.94.1-alpha-SNAPSHOT + 0.95.0-alpha google-cloud-core From 13eb5aed8287fa736014ed4ee219ab53171cf13a Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 6 Jun 2019 15:03:53 -0700 Subject: [PATCH 614/663] Bump snapshot (#5441) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 36f84be4ce..541c4484c3 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.77.0 + 1.77.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.95.0-alpha + 0.95.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index c00d491c4b..96e27461b4 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.77.0 + 1.77.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.95.0-alpha + 0.95.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 8fcc4fb120..d9608a58d0 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.77.0 + 1.77.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.95.0-alpha + 0.95.1-alpha-SNAPSHOT google-cloud-core From e4ccabb24bd878fc694529d6d00027c4cd96333a Mon Sep 17 00:00:00 2001 From: abhinav-qlogic <48669998+abhinav-qlogic@users.noreply.github.com> Date: Fri, 7 Jun 2019 23:29:34 +0530 Subject: [PATCH 615/663] Http Core: fix deprecation warnings (#5407) --- .../test/java/com/google/cloud/http/CensusHttpModuleTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java b/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java index 7d2827bfb9..c04d0647fb 100644 --- a/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java +++ b/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java @@ -35,6 +35,7 @@ import io.opencensus.trace.TraceId; import io.opencensus.trace.TraceOptions; import io.opencensus.trace.Tracer; +import io.opencensus.trace.Tracestate; import io.opencensus.trace.Tracing; import io.opencensus.trace.propagation.TextFormat; import java.io.IOException; @@ -116,7 +117,8 @@ public void censusHttpExecuteInterceptorShouldInjectHeader() throws IOException SpanContext.create( TraceId.generateRandomId(random), SpanId.generateRandomId(random), - TraceOptions.DEFAULT); + TraceOptions.DEFAULT, + Tracestate.builder().build()); Span mockSpan = createMockBuilder(Span.class) .withConstructor(SpanContext.class, EnumSet.class) From 7bc51239bcad154c6e532c11262759e2dd56f2bf Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 13 Jun 2019 14:06:30 -0700 Subject: [PATCH 616/663] Release v0.96.0 (#5474) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 541c4484c3..814e73ddfb 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.77.1-SNAPSHOT + 1.78.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.95.1-alpha-SNAPSHOT + 0.96.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 96e27461b4..cf5fec4c80 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.77.1-SNAPSHOT + 1.78.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.95.1-alpha-SNAPSHOT + 0.96.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 90c382e871..29b01c10fb 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.77.0 + 1.78.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.77.0' +compile 'com.google.cloud:google-cloud-core:1.78.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.77.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.78.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d9608a58d0..c27b03f9b9 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.77.1-SNAPSHOT + 1.78.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.95.1-alpha-SNAPSHOT + 0.96.0-alpha google-cloud-core From 4f478b56580d6aec3dedbdf6df4966092f378338 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 14 Jun 2019 12:08:55 -0700 Subject: [PATCH 617/663] Bump next snapshot (#5496) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 814e73ddfb..aa80ae983d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.78.0 + 1.78.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.96.0-alpha + 0.96.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index cf5fec4c80..88465d30d3 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.78.0 + 1.78.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.96.0-alpha + 0.96.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c27b03f9b9..c54204c7a7 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.78.0 + 1.78.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.96.0-alpha + 0.96.1-alpha-SNAPSHOT google-cloud-core From 99c02f191cc3170cdee4710300e0cee32ee5fed6 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 20 Jun 2019 17:41:03 -0400 Subject: [PATCH 618/663] Release v0.97.0 (#5528) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index aa80ae983d..406e47c1d7 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.78.1-SNAPSHOT + 1.79.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.96.1-alpha-SNAPSHOT + 0.97.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 88465d30d3..c52131942e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.78.1-SNAPSHOT + 1.79.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.96.1-alpha-SNAPSHOT + 0.97.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 29b01c10fb..298ba4b917 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.78.0 + 1.79.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.78.0' +compile 'com.google.cloud:google-cloud-core:1.79.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.78.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.79.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c54204c7a7..9dfb58ce08 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.78.1-SNAPSHOT + 1.79.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.96.1-alpha-SNAPSHOT + 0.97.0-alpha google-cloud-core From 047c1ef79d4e98d9d7cd7aba9b862a21f394d652 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 21 Jun 2019 09:08:35 -0700 Subject: [PATCH 619/663] Bump next snapshot (#5530) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 406e47c1d7..bd7499d05b 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.79.0 + 1.79.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.97.0-alpha + 0.97.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index c52131942e..162452fc65 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.79.0 + 1.79.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.97.0-alpha + 0.97.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 9dfb58ce08..82667ac273 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.79.0 + 1.79.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.97.0-alpha + 0.97.1-alpha-SNAPSHOT google-cloud-core From 3bdae32b3653677d4390485ea31641eb940ab244 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Wed, 26 Jun 2019 15:13:35 -0700 Subject: [PATCH 620/663] Release v0.98.0 (#5572) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index bd7499d05b..843a2bc4cd 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.79.1-SNAPSHOT + 1.80.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.97.1-alpha-SNAPSHOT + 0.98.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 162452fc65..55edbb2937 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.79.1-SNAPSHOT + 1.80.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.97.1-alpha-SNAPSHOT + 0.98.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 298ba4b917..841cd664a1 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.79.0 + 1.80.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.79.0' +compile 'com.google.cloud:google-cloud-core:1.80.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.79.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.80.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 82667ac273..664a847468 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.79.1-SNAPSHOT + 1.80.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.97.1-alpha-SNAPSHOT + 0.98.0-alpha google-cloud-core From 40eb1366bb3d15604f38935eaa667373a7948fab Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 27 Jun 2019 12:10:33 -0700 Subject: [PATCH 621/663] Bump next snapshot (#5579) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 843a2bc4cd..c9f6710603 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.80.0 + 1.80.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.98.0-alpha + 0.98.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 55edbb2937..965201188c 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.80.0 + 1.80.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.98.0-alpha + 0.98.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 664a847468..71f9e59d15 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.80.0 + 1.80.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.98.0-alpha + 0.98.1-alpha-SNAPSHOT google-cloud-core From 5c897dcd8515221d59ace71c2a4f1fa770b3839a Mon Sep 17 00:00:00 2001 From: athakor <49403056+athakor@users.noreply.github.com> Date: Mon, 1 Jul 2019 23:48:12 +0530 Subject: [PATCH 622/663] cleanup unused dependency of contrib-google-cloud-core-grpc (#5618) --- google-cloud-core-grpc/pom.xml | 42 +--------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index c9f6710603..519225e10e 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -45,49 +45,9 @@ objenesis test - - com.google.protobuf - protobuf-java - - - com.google.protobuf - protobuf-java-util - - - io.grpc - grpc-protobuf - - - io.grpc - grpc-context - - - io.grpc - grpc-netty-shaded - - - io.grpc - grpc-stub - - - io.grpc - grpc-auth - com.google.api gax-grpc - - - - com.google.truth - truth - test - - - com.google.guava - guava-testlib - test - - + \ No newline at end of file From b63408fddfd192aee051c77b694ef678a3d38d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Mon, 1 Jul 2019 21:39:24 +0200 Subject: [PATCH 623/663] Spanner: Create new instance if existing Spanner is closed (#5200) * do not hand out a closed Spanner instance SpannerOptions caches any Spanner instance that has been created, and hands this cached instance out to all subsequent calls to SpannerOptions.getService(). This also included closed Spanner instances. The getService() method now returns an error if the Spanner instance has already been closed. * fix small merge error * create a new instance if the service/rpc is closed SpannerOptions.getService() and SpannerOptions.getRpc() should return a new instance instead of throwing an exception if the service/rpc object has been closed. * add test case to ensure correct caching behavior * use shouldRefreshService instead of createNewService * fix merge conflicts * added documentation to shouldRefresh... methods * removed overrides only for comments * fixed naming * added assertions for isClosed() * fixed formatting --- .../java/com/google/cloud/ServiceOptions.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index d08b14e715..d789585631 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -494,24 +494,40 @@ static String getServiceAccountProjectId(String credentialsPath) { */ @SuppressWarnings("unchecked") public ServiceT getService() { - if (service == null) { + if (shouldRefreshService(service)) { service = serviceFactory.create((OptionsT) this); } return service; } + /** + * @param cachedService The currently cached service object + * @return true if the currently cached service object should be refreshed. + */ + protected boolean shouldRefreshService(ServiceT cachedService) { + return cachedService == null; + } + /** * Returns a Service RPC object for the current service. For instance, when using Google Cloud * Storage, it returns a StorageRpc object. */ @SuppressWarnings("unchecked") public ServiceRpc getRpc() { - if (rpc == null) { + if (shouldRefreshRpc(rpc)) { rpc = serviceRpcFactory.create((OptionsT) this); } return rpc; } + /** + * @param cachedRpc The currently cached service object + * @return true if the currently cached service object should be refreshed. + */ + protected boolean shouldRefreshRpc(ServiceRpc cachedRpc) { + return cachedRpc == null; + } + /** * Returns the project ID. Return value can be null (for services that don't require a project * ID). From feeafe911f11f3003d84cc650a3bb50fdec23f49 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 3 Jul 2019 09:12:34 -0700 Subject: [PATCH 624/663] Release v0.99.0 (#5657) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 519225e10e..79bb9f3720 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.80.1-SNAPSHOT + 1.81.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.98.1-alpha-SNAPSHOT + 0.99.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 965201188c..ab7c8a908d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.80.1-SNAPSHOT + 1.81.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.98.1-alpha-SNAPSHOT + 0.99.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 841cd664a1..e0870cb568 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.80.0 + 1.81.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.80.0' +compile 'com.google.cloud:google-cloud-core:1.81.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.80.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.81.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 71f9e59d15..4efc6c82a4 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.80.1-SNAPSHOT + 1.81.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.98.1-alpha-SNAPSHOT + 0.99.0-alpha google-cloud-core From 2d1857abe8399b2c1cef2cf276b730c575d181b5 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Mon, 8 Jul 2019 11:16:23 -0700 Subject: [PATCH 625/663] Bump next snapshot (#5702) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 79bb9f3720..90f15f0574 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.81.0 + 1.81.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.99.0-alpha + 0.99.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index ab7c8a908d..dd50cfb176 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.81.0 + 1.81.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.99.0-alpha + 0.99.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 4efc6c82a4..b477ec59cc 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.81.0 + 1.81.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.99.0-alpha + 0.99.1-alpha-SNAPSHOT google-cloud-core From 275fe13da1a60597b753d86416e9830fd19195fb Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 10 Jul 2019 14:28:03 -0400 Subject: [PATCH 626/663] Release v0.100.0 (#5716) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 90f15f0574..6462a78d00 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.81.1-SNAPSHOT + 1.82.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.99.1-alpha-SNAPSHOT + 0.100.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index dd50cfb176..5ae4c08d14 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.81.1-SNAPSHOT + 1.82.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.99.1-alpha-SNAPSHOT + 0.100.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index e0870cb568..1124af3168 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.81.0 + 1.82.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.81.0' +compile 'com.google.cloud:google-cloud-core:1.82.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.81.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.82.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index b477ec59cc..d5c910e844 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.81.1-SNAPSHOT + 1.82.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.99.1-alpha-SNAPSHOT + 0.100.0-alpha google-cloud-core From 1fc1c39bcdfdb0b461789e61836dc3365bafd6d2 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 10 Jul 2019 17:01:45 -0400 Subject: [PATCH 627/663] Bump next snapshot (#5720) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 6462a78d00..d5b7d356cc 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.82.0 + 1.82.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.100.0-alpha + 0.100.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 5ae4c08d14..08f76f30f7 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.82.0 + 1.82.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.100.0-alpha + 0.100.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d5c910e844..c7c35e4e3e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.82.0 + 1.82.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.100.0-alpha + 0.100.1-alpha-SNAPSHOT google-cloud-core From a646b42a4c50a4f04c5f6916b411a96dbe4b7e89 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Thu, 18 Jul 2019 09:33:51 -0700 Subject: [PATCH 628/663] Release v0.101.0 (#5761) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d5b7d356cc..e169ed8e67 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.82.1-SNAPSHOT + 1.83.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.100.1-alpha-SNAPSHOT + 0.101.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 08f76f30f7..dd3591d5b4 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.82.1-SNAPSHOT + 1.83.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.100.1-alpha-SNAPSHOT + 0.101.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 1124af3168..51b7f56f71 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.82.0 + 1.83.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.82.0' +compile 'com.google.cloud:google-cloud-core:1.83.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.82.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.83.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index c7c35e4e3e..0b7309469d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.82.1-SNAPSHOT + 1.83.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.100.1-alpha-SNAPSHOT + 0.101.0-alpha google-cloud-core From 37ffd19ce4bfe80a4b647df0c2b13d3487650a94 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Tue, 23 Jul 2019 16:28:01 -0400 Subject: [PATCH 629/663] Bump next snapshot (#5812) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index e169ed8e67..fab6f56b78 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.83.0 + 1.83.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.101.0-alpha + 0.101.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index dd3591d5b4..74cddb2b5b 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.83.0 + 1.83.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.101.0-alpha + 0.101.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 0b7309469d..3368db2a75 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.83.0 + 1.83.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.101.0-alpha + 0.101.1-alpha-SNAPSHOT google-cloud-core From 4888856035c5a6997e6c7343534de0b64fd4c2ef Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 24 Jul 2019 14:46:17 -0700 Subject: [PATCH 630/663] Release v0.102.0 (#5852) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index fab6f56b78..d3ffbc0225 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.83.1-SNAPSHOT + 1.84.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.101.1-alpha-SNAPSHOT + 0.102.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 74cddb2b5b..0cbdf00448 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.83.1-SNAPSHOT + 1.84.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.101.1-alpha-SNAPSHOT + 0.102.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 51b7f56f71..09f57c714b 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.83.0 + 1.84.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.83.0' +compile 'com.google.cloud:google-cloud-core:1.84.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.83.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.84.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3368db2a75..f1a81a84ff 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.83.1-SNAPSHOT + 1.84.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.101.1-alpha-SNAPSHOT + 0.102.0-alpha google-cloud-core From e489da8b40aff08a6092d65a0af1d87edc208673 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 25 Jul 2019 07:11:16 -0700 Subject: [PATCH 631/663] Bump next snapshot (#5858) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d3ffbc0225..b3a9f5992d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.84.0 + 1.84.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.102.0-alpha + 0.102.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 0cbdf00448..c627bc6ba8 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.84.0 + 1.84.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.102.0-alpha + 0.102.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f1a81a84ff..3d27b537e8 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.84.0 + 1.84.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.102.0-alpha + 0.102.1-alpha-SNAPSHOT google-cloud-core From 7866565f1596c02273d905d0f942bbbcc51c323e Mon Sep 17 00:00:00 2001 From: athakor <49403056+athakor@users.noreply.github.com> Date: Wed, 31 Jul 2019 03:37:48 +0530 Subject: [PATCH 632/663] Core: Cleanup unused dependencies (#5617) * cleanup unused dependency of contrib-google-cloud-core * remove unused dependency of core * add the newline at the end of the file --- google-cloud-core/pom.xml | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3d27b537e8..34d11ad280 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -18,29 +18,11 @@ google-cloud-core - - com.google.guava - guava - junit junit test - - com.google.http-client - google-http-client - - - com.google.code.findbugs - jsr305 - - - - - com.google.code.findbugs - jsr305 - org.easymock easymock @@ -51,10 +33,6 @@ objenesis test - - com.google.api - api-common - com.google.api gax @@ -81,10 +59,5 @@ guava-testlib test - - org.checkerframework - checker-compat-qual - test - From 96dfa7676818a89e8e7f61cea33fd9ed170c555c Mon Sep 17 00:00:00 2001 From: athakor <49403056+athakor@users.noreply.github.com> Date: Wed, 31 Jul 2019 04:05:36 +0530 Subject: [PATCH 633/663] Core-http: Cleanup unused dependencies (#5686) --- google-cloud-core-http/pom.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index c627bc6ba8..cfbe034973 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -75,13 +75,5 @@ truth test - - io.opencensus - opencensus-api - - - io.opencensus - opencensus-contrib-http-util - From c09a747b5ed66fd0d9a0ba6436e58d6f6a42b891 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 31 Jul 2019 15:09:09 -0400 Subject: [PATCH 634/663] Release v0.103.0 (#5950) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index b3a9f5992d..b5e8f79706 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.84.1-SNAPSHOT + 1.85.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.102.1-alpha-SNAPSHOT + 0.103.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index cfbe034973..42a311d6c5 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.84.1-SNAPSHOT + 1.85.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.102.1-alpha-SNAPSHOT + 0.103.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 09f57c714b..30bd9a0cc4 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.84.0 + 1.85.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.84.0' +compile 'com.google.cloud:google-cloud-core:1.85.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.84.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.85.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 34d11ad280..f92b56a88a 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.84.1-SNAPSHOT + 1.85.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.102.1-alpha-SNAPSHOT + 0.103.0-alpha google-cloud-core From 0c8c0fd6d5c1520f5bd2c41c3f3e23ba1dec80e6 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 1 Aug 2019 13:21:29 -0400 Subject: [PATCH 635/663] Bump next snapshot (#5958) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index b5e8f79706..d40e3ce054 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.85.0 + 1.85.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.103.0-alpha + 0.103.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 42a311d6c5..80d30face7 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.85.0 + 1.85.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.103.0-alpha + 0.103.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f92b56a88a..0098e0084e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.85.0 + 1.85.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.103.0-alpha + 0.103.1-alpha-SNAPSHOT google-cloud-core From b4a9e7621eb4e97746d6e4b225df87183ae4472a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Mon, 5 Aug 2019 18:54:15 +0200 Subject: [PATCH 636/663] Spanner JDBC: Add Spanner JDBC driver to google-cloud-contrib (#6007) add Spanner JDBC driver to google-cloud-contrib --- .../java/com/google/cloud/ServiceOptions.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index d789585631..56f2d19595 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -45,7 +45,9 @@ import com.google.auth.oauth2.GoogleCredentials; import com.google.auth.oauth2.ServiceAccountCredentials; import com.google.cloud.spi.ServiceRpcFactory; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.io.Files; import java.io.BufferedReader; @@ -89,6 +91,7 @@ public abstract class ServiceOptions< getDefaultRetrySettingsBuilder().setMaxAttempts(1).build(); private static final long serialVersionUID = 9198896031667942014L; + protected final String clientLibToken; private final String projectId; private final String host; @@ -117,6 +120,8 @@ public abstract static class Builder< OptionsT extends ServiceOptions, B extends Builder> { + private final ImmutableSet allowedClientLibTokens = + ImmutableSet.of(ServiceOptions.getGoogApiClientLibName()); private String projectId; private String host; protected Credentials credentials; @@ -126,6 +131,7 @@ public abstract static class Builder< private ApiClock clock; private TransportOptions transportOptions; private HeaderProvider headerProvider; + private String clientLibToken = ServiceOptions.getGoogApiClientLibName(); @InternalApi("This class should only be extended within google-cloud-java") protected Builder() {} @@ -140,6 +146,7 @@ protected Builder(ServiceOptions options) { serviceRpcFactory = options.serviceRpcFactory; clock = options.clock; transportOptions = options.transportOptions; + clientLibToken = options.clientLibToken; } protected abstract ServiceOptions build(); @@ -253,6 +260,18 @@ public B setHeaderProvider(HeaderProvider headerProvider) { this.headerProvider = headerProvider; return self(); } + + @InternalApi + public B setClientLibToken(String clientLibToken) { + Preconditions.checkArgument( + getAllowedClientLibTokens().contains(clientLibToken), "Illegal client lib token"); + this.clientLibToken = clientLibToken; + return self(); + } + + protected Set getAllowedClientLibTokens() { + return allowedClientLibTokens; + } } @InternalApi("This class should only be extended within google-cloud-java") @@ -285,6 +304,7 @@ protected ServiceOptions( transportOptions = firstNonNull(builder.transportOptions, serviceDefaults.getDefaultTransportOptions()); headerProvider = firstNonNull(builder.headerProvider, new NoHeaderProvider()); + clientLibToken = builder.clientLibToken; } /** @@ -710,4 +730,8 @@ protected RetrySettings defaultRetrySettings() { public static T getFromServiceLoader(Class clazz, T defaultInstance) { return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance); } + + public String getClientLibToken() { + return clientLibToken; + } } From d8d2597551f419534eb3fa4e8c395f560fee24fe Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 7 Aug 2019 10:00:27 -0700 Subject: [PATCH 637/663] Release v0.104.0 (#6048) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index d40e3ce054..4d040f32bf 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.85.1-SNAPSHOT + 1.86.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.103.1-alpha-SNAPSHOT + 0.104.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 80d30face7..24a0be381d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.85.1-SNAPSHOT + 1.86.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.103.1-alpha-SNAPSHOT + 0.104.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 30bd9a0cc4..024174c09f 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -19,16 +19,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.85.0 + 1.86.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.85.0' +compile 'com.google.cloud:google-cloud-core:1.86.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.85.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.86.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 0098e0084e..3c394ecc56 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.85.1-SNAPSHOT + 1.86.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.103.1-alpha-SNAPSHOT + 0.104.0-alpha google-cloud-core From e356c56efa6088e83a3b14b08ed1c027899e8f7c Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 8 Aug 2019 12:07:43 -0700 Subject: [PATCH 638/663] Bump next snapshot (#6055) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 4d040f32bf..b9d945c469 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.86.0 + 1.86.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.104.0-alpha + 0.104.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 24a0be381d..3e2b8b2982 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.86.0 + 1.86.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.104.0-alpha + 0.104.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 3c394ecc56..70ad84211f 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.86.0 + 1.86.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.104.0-alpha + 0.104.1-alpha-SNAPSHOT google-cloud-core From 6b84bf70e4a13545066c24c22d2878f7d8480595 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 14 Aug 2019 10:05:25 -0700 Subject: [PATCH 639/663] Fix links to googleapis.dev from GitHub pages (#6070) --- google-cloud-core/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 024174c09f..9b04118b3b 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -7,8 +7,7 @@ This module provides common functionality required by service-specific modules o [![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg) [![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) -- [Homepage](https://googleapis.github.io/google-cloud-java/) -- [API Documentation](https://googleapis.github.io/google-cloud-java/apidocs/index.html?com/google/cloud/package-summary.html) +- [API Documentation](https://googleapis.dev/java/google-cloud-clients/latest/index.html?com/google/cloud/package-summary.html) Quickstart ---------- From 11a4e688b39fad1cc5bf7e2489da01b75a1a53b9 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 14 Aug 2019 15:10:32 -0400 Subject: [PATCH 640/663] Release v0.105.0 (#6077) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index b9d945c469..775700bc91 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.86.1-SNAPSHOT + 1.87.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.104.1-alpha-SNAPSHOT + 0.105.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 3e2b8b2982..eb329a960d 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.86.1-SNAPSHOT + 1.87.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.104.1-alpha-SNAPSHOT + 0.105.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 9b04118b3b..517cd49def 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -18,16 +18,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.86.0 + 1.87.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.86.0' +compile 'com.google.cloud:google-cloud-core:1.87.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.86.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.87.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 70ad84211f..d1d11cfafc 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.86.1-SNAPSHOT + 1.87.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.104.1-alpha-SNAPSHOT + 0.105.0-alpha google-cloud-core From 0f5613913c6c2995a91af9333a52a856d8fecded Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 14 Aug 2019 20:03:16 -0400 Subject: [PATCH 641/663] Bump next snapshot (#6079) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 775700bc91..588c23ba5d 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.87.0 + 1.87.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.105.0-alpha + 0.105.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index eb329a960d..17c24ff8b9 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.87.0 + 1.87.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.105.0-alpha + 0.105.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d1d11cfafc..d4b9af695a 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.87.0 + 1.87.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.105.0-alpha + 0.105.1-alpha-SNAPSHOT google-cloud-core From 2b6fd9c06fb04e798ad5291f3fe5ece1b154c426 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 22 Aug 2019 13:14:03 -0700 Subject: [PATCH 642/663] Release v0.106.0 (#6140) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 588c23ba5d..79420109d0 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.87.1-SNAPSHOT + 1.88.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.105.1-alpha-SNAPSHOT + 0.106.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 17c24ff8b9..bbc6630675 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.87.1-SNAPSHOT + 1.88.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.105.1-alpha-SNAPSHOT + 0.106.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 517cd49def..b2fda60f03 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -18,16 +18,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.87.0 + 1.88.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.87.0' +compile 'com.google.cloud:google-cloud-core:1.88.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.87.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.88.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d4b9af695a..f169f901e2 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.87.1-SNAPSHOT + 1.88.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.105.1-alpha-SNAPSHOT + 0.106.0-alpha google-cloud-core From 0fd0a2f72b8bd895ff11112b181b7057a1319c4b Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Mon, 26 Aug 2019 12:50:31 -0400 Subject: [PATCH 643/663] Bump next snapshot (#6162) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 79420109d0..f1d0a52636 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.88.0 + 1.88.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.106.0-alpha + 0.106.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index bbc6630675..4cc42b45e9 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.88.0 + 1.88.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.106.0-alpha + 0.106.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index f169f901e2..d0e9c92e03 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.88.0 + 1.88.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.106.0-alpha + 0.106.1-alpha-SNAPSHOT google-cloud-core From 7b976cab92e0f337e6475e17a116ec11e3f808a4 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 28 Aug 2019 19:39:57 -0400 Subject: [PATCH 644/663] Release v0.107.0 (#6188) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index f1d0a52636..7fa6fa2c48 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.88.1-SNAPSHOT + 1.89.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.106.1-alpha-SNAPSHOT + 0.107.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 4cc42b45e9..15c36f5b75 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.88.1-SNAPSHOT + 1.89.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.106.1-alpha-SNAPSHOT + 0.107.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index b2fda60f03..4abe253d10 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -18,16 +18,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.88.0 + 1.89.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.88.0' +compile 'com.google.cloud:google-cloud-core:1.89.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.88.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.89.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d0e9c92e03..99dfba0d68 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.88.1-SNAPSHOT + 1.89.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.106.1-alpha-SNAPSHOT + 0.107.0-alpha google-cloud-core From 8700b1fd821edd5fd257ffffd26469a190f700bf Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Thu, 29 Aug 2019 13:46:14 -0400 Subject: [PATCH 645/663] Bump next snapshot (#6194) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 7fa6fa2c48..7da7ef2aee 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.89.0 + 1.89.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.107.0-alpha + 0.107.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 15c36f5b75..6eabba0476 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.89.0 + 1.89.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.107.0-alpha + 0.107.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 99dfba0d68..db21d11a1e 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.89.0 + 1.89.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.107.0-alpha + 0.107.1-alpha-SNAPSHOT google-cloud-core From 50948ec638c1d615eb46507be2df6e3491c746b0 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 5 Sep 2019 11:11:12 -0700 Subject: [PATCH 646/663] Release google-cloud-java v0.108.0 (#6223) * Release v0.108.0 * Spanner JDBC to 1.0.0 --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/README.md | 6 +++--- google-cloud-core/pom.xml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 7da7ef2aee..f78f389fc2 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.89.1-SNAPSHOT + 1.90.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.107.1-alpha-SNAPSHOT + 0.108.0-alpha google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 6eabba0476..0d5d5d36a1 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.89.1-SNAPSHOT + 1.90.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.107.1-alpha-SNAPSHOT + 0.108.0-alpha google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 4abe253d10..fd2b536604 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -18,16 +18,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.89.0 + 1.90.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.89.0' +compile 'com.google.cloud:google-cloud-core:1.90.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.89.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.90.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index db21d11a1e..84fb88db47 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.89.1-SNAPSHOT + 1.90.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.107.1-alpha-SNAPSHOT + 0.108.0-alpha google-cloud-core From f09aa0f1e89c5b7f60e923457cb1dece4788635f Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 6 Sep 2019 08:52:12 -0700 Subject: [PATCH 647/663] Bump next snapshot (#6231) --- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index f78f389fc2..da06d875fb 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.90.0 + 1.90.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.108.0-alpha + 0.108.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index 0d5d5d36a1..dc4b39ae6e 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.90.0 + 1.90.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.108.0-alpha + 0.108.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 84fb88db47..fd281c6f49 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.90.0 + 1.90.1-SNAPSHOT jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-clients - 0.108.0-alpha + 0.108.1-alpha-SNAPSHOT google-cloud-core From 9193666096b7aec97387cc3f8cfd4c26b24959b8 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 6 Sep 2019 09:12:06 -0700 Subject: [PATCH 648/663] chore: add repo common files --- .github/ISSUE_TEMPLATE/bug_report.md | 51 +++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 21 +++++ .github/ISSUE_TEMPLATE/support_request.md | 7 ++ .github/PULL_REQUEST_TEMPLATE.md | 1 + .gitignore | 15 ++++ .kokoro/build.bat | 3 + .kokoro/build.sh | 54 +++++++++++++ .kokoro/common.cfg | 13 ++++ .kokoro/continuous/common.cfg | 24 ++++++ .kokoro/continuous/dependencies.cfg | 12 +++ .kokoro/continuous/integration.cfg | 7 ++ .kokoro/continuous/java11.cfg | 7 ++ .kokoro/continuous/java7.cfg | 7 ++ .kokoro/continuous/java8-osx.cfg | 3 + .kokoro/continuous/java8-win.cfg | 3 + .kokoro/continuous/java8.cfg | 7 ++ .kokoro/continuous/lint.cfg | 13 ++++ .kokoro/continuous/propose_release.cfg | 53 +++++++++++++ .kokoro/continuous/propose_release.sh | 29 +++++++ .kokoro/dependencies.sh | 27 +++++++ .kokoro/linkage-monitor.sh | 33 ++++++++ .kokoro/nightly/common.cfg | 24 ++++++ .kokoro/nightly/dependencies.cfg | 12 +++ .kokoro/nightly/integration.cfg | 7 ++ .kokoro/nightly/java11.cfg | 7 ++ .kokoro/nightly/java7.cfg | 7 ++ .kokoro/nightly/java8-osx.cfg | 3 + .kokoro/nightly/java8-win.cfg | 3 + .kokoro/nightly/java8.cfg | 7 ++ .kokoro/nightly/lint.cfg | 13 ++++ .kokoro/presubmit/common.cfg | 33 ++++++++ .kokoro/presubmit/dependencies.cfg | 12 +++ .kokoro/presubmit/integration.cfg | 7 ++ .kokoro/presubmit/java11.cfg | 7 ++ .kokoro/presubmit/java7.cfg | 7 ++ .kokoro/presubmit/java8-osx.cfg | 3 + .kokoro/presubmit/java8-win.cfg | 3 + .kokoro/presubmit/java8.cfg | 7 ++ .kokoro/presubmit/linkage-monitor.cfg | 12 +++ .kokoro/presubmit/lint.cfg | 13 ++++ .kokoro/release/bump_snapshot.cfg | 53 +++++++++++++ .kokoro/release/bump_snapshot.sh | 30 ++++++++ .kokoro/release/common.cfg | 49 ++++++++++++ .kokoro/release/common.sh | 50 ++++++++++++ .kokoro/release/drop.cfg | 9 +++ .kokoro/release/drop.sh | 32 ++++++++ .kokoro/release/promote.cfg | 10 +++ .kokoro/release/promote.sh | 34 +++++++++ .kokoro/release/publish_javadoc.cfg | 19 +++++ .kokoro/release/publish_javadoc.sh | 55 ++++++++++++++ .kokoro/release/snapshot.cfg | 6 ++ .kokoro/release/snapshot.sh | 30 ++++++++ .kokoro/release/stage.cfg | 44 +++++++++++ .kokoro/release/stage.sh | 41 ++++++++++ .kokoro/trampoline.sh | 24 ++++++ .repo-metadata.json | 9 +++ CODE_OF_CONDUCT.md | 93 +++++++++++++++++++++++ CONTRIBUTING.md | 28 +++++++ LICENSE | 5 +- README.md | 63 +++++++++++++++ codecov.yaml | 4 + java.header | 15 ++++ license-checks.xml | 10 +++ renovate.json | 29 +++++++ synth.metadata | 12 +++ synth.py | 27 +++++++ 66 files changed, 1356 insertions(+), 2 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/support_request.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .gitignore create mode 100644 .kokoro/build.bat create mode 100755 .kokoro/build.sh create mode 100644 .kokoro/common.cfg create mode 100644 .kokoro/continuous/common.cfg create mode 100644 .kokoro/continuous/dependencies.cfg create mode 100644 .kokoro/continuous/integration.cfg create mode 100644 .kokoro/continuous/java11.cfg create mode 100644 .kokoro/continuous/java7.cfg create mode 100644 .kokoro/continuous/java8-osx.cfg create mode 100644 .kokoro/continuous/java8-win.cfg create mode 100644 .kokoro/continuous/java8.cfg create mode 100644 .kokoro/continuous/lint.cfg create mode 100644 .kokoro/continuous/propose_release.cfg create mode 100755 .kokoro/continuous/propose_release.sh create mode 100755 .kokoro/dependencies.sh create mode 100755 .kokoro/linkage-monitor.sh create mode 100644 .kokoro/nightly/common.cfg create mode 100644 .kokoro/nightly/dependencies.cfg create mode 100644 .kokoro/nightly/integration.cfg create mode 100644 .kokoro/nightly/java11.cfg create mode 100644 .kokoro/nightly/java7.cfg create mode 100644 .kokoro/nightly/java8-osx.cfg create mode 100644 .kokoro/nightly/java8-win.cfg create mode 100644 .kokoro/nightly/java8.cfg create mode 100644 .kokoro/nightly/lint.cfg create mode 100644 .kokoro/presubmit/common.cfg create mode 100644 .kokoro/presubmit/dependencies.cfg create mode 100644 .kokoro/presubmit/integration.cfg create mode 100644 .kokoro/presubmit/java11.cfg create mode 100644 .kokoro/presubmit/java7.cfg create mode 100644 .kokoro/presubmit/java8-osx.cfg create mode 100644 .kokoro/presubmit/java8-win.cfg create mode 100644 .kokoro/presubmit/java8.cfg create mode 100644 .kokoro/presubmit/linkage-monitor.cfg create mode 100644 .kokoro/presubmit/lint.cfg create mode 100644 .kokoro/release/bump_snapshot.cfg create mode 100755 .kokoro/release/bump_snapshot.sh create mode 100644 .kokoro/release/common.cfg create mode 100755 .kokoro/release/common.sh create mode 100644 .kokoro/release/drop.cfg create mode 100755 .kokoro/release/drop.sh create mode 100644 .kokoro/release/promote.cfg create mode 100755 .kokoro/release/promote.sh create mode 100644 .kokoro/release/publish_javadoc.cfg create mode 100755 .kokoro/release/publish_javadoc.sh create mode 100644 .kokoro/release/snapshot.cfg create mode 100755 .kokoro/release/snapshot.sh create mode 100644 .kokoro/release/stage.cfg create mode 100755 .kokoro/release/stage.sh create mode 100644 .kokoro/trampoline.sh create mode 100644 .repo-metadata.json create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 README.md create mode 100644 codecov.yaml create mode 100644 java.header create mode 100644 license-checks.xml create mode 100644 renovate.json create mode 100644 synth.metadata create mode 100644 synth.py diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000000..d81d43b1a6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,51 @@ +--- +name: Bug report +about: Create a report to help us improve + +--- + +Thanks for stopping by to let us know something could be better! + +**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. + +Please run down the following list and make sure you've tried the usual "quick fixes": + + - Search the issues already opened: https://github.com/googleapis/google-cloud-core/issues + - Check for answers on StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform + +If you are still having issues, please include as much information as possible: + +#### Environment details + +1. Specify the API at the beginning of the title. For example, "BigQuery: ..."). + General, Core, and Other are also allowed as types +2. OS type and version: +3. Java version: +4. google-cloud-core version(s): + +#### Steps to reproduce + + 1. ? + 2. ? + +#### Code example + +```java +// example +``` + +#### Stack trace +``` +Any relevant stacktrace here. +``` + +#### External references such as API reference guides + +- ? + +#### Any additional information below + + +Following these steps guarantees the quickest resolution possible. + +Thanks! \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000000..754e30c68a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,21 @@ +--- +name: Feature request +about: Suggest an idea for this library + +--- + +Thanks for stopping by to let us know something could be better! + +**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. + +**Is your feature request related to a problem? Please describe.** +What the problem is. Example: I'm always frustrated when [...] + +**Describe the solution you'd like** +What you want to happen. + +**Describe alternatives you've considered** +Any alternative solutions or features you've considered. + +**Additional context** +Any other context or screenshots about the feature request. diff --git a/.github/ISSUE_TEMPLATE/support_request.md b/.github/ISSUE_TEMPLATE/support_request.md new file mode 100644 index 0000000000..9958690321 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/support_request.md @@ -0,0 +1,7 @@ +--- +name: Support request +about: If you have a support contract with Google, please create an issue in the Google Cloud Support console. + +--- + +**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000000..0bd0ee0620 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1 @@ +Fixes # (it's a good idea to open an issue first for context and/or discussion) \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..fadd6afc2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Maven +target/ + +# Eclipse +.classpath +.project +.settings + +# Intellij +*.iml +.idea/ + +# python utilities +*.pyc +__pycache__ diff --git a/.kokoro/build.bat b/.kokoro/build.bat new file mode 100644 index 0000000000..bcca1f45d0 --- /dev/null +++ b/.kokoro/build.bat @@ -0,0 +1,3 @@ +:: See documentation in type-shell-output.bat + +"C:\Program Files\Git\bin\bash.exe" github/java-core/.kokoro/build.sh diff --git a/.kokoro/build.sh b/.kokoro/build.sh new file mode 100755 index 0000000000..2ffb5ef7f0 --- /dev/null +++ b/.kokoro/build.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +## Get the directory of the build script +scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}")) +## cd to the parent directory, i.e. the root of the git repo +cd ${scriptDir}/.. + +# Print out Java version +java -version +echo ${JOB_TYPE} + +mvn install -B -V \ + -DskipTests=true \ + -Dmaven.javadoc.skip=true \ + -Dgcloud.download.skip=true \ + -T 1C + +# if GOOGLE_APPLICATION_CREDIENTIALS is specified as a relative path prepend Kokoro root directory onto it +if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTIALS}" != /* ]]; then + export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_ROOT}/src/${GOOGLE_APPLICATION_CREDENTIALS}) +fi + +case ${JOB_TYPE} in +test) + mvn test -B + bash ${KOKORO_GFILE_DIR}/codecov.sh + ;; +lint) + mvn com.coveo:fmt-maven-plugin:check + ;; +javadoc) + mvn javadoc:javadoc javadoc:test-javadoc + ;; +integration) + mvn -B ${INTEGRATION_TEST_ARGS} -DtrimStackTrace=false -fae verify + ;; +*) + ;; +esac \ No newline at end of file diff --git a/.kokoro/common.cfg b/.kokoro/common.cfg new file mode 100644 index 0000000000..054c30c8f7 --- /dev/null +++ b/.kokoro/common.cfg @@ -0,0 +1,13 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Download trampoline resources. These will be in ${KOKORO_GFILE_DIR} +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# All builds use the trampoline script to run in docker. +build_file: "java-core/.kokoro/trampoline.sh" + +# Tell the trampoline which build file to use. +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/build.sh" +} diff --git a/.kokoro/continuous/common.cfg b/.kokoro/continuous/common.cfg new file mode 100644 index 0000000000..af5a907dc4 --- /dev/null +++ b/.kokoro/continuous/common.cfg @@ -0,0 +1,24 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Build logs will be here +action { + define_artifacts { + regex: "**/*sponge_log.xml" + } +} + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Use the trampoline script to run in docker. +build_file: "java-core/.kokoro/trampoline.sh" + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/build.sh" +} + +env_vars: { + key: "JOB_TYPE" + value: "test" +} diff --git a/.kokoro/continuous/dependencies.cfg b/.kokoro/continuous/dependencies.cfg new file mode 100644 index 0000000000..895832a928 --- /dev/null +++ b/.kokoro/continuous/dependencies.cfg @@ -0,0 +1,12 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/dependencies.sh" +} diff --git a/.kokoro/continuous/integration.cfg b/.kokoro/continuous/integration.cfg new file mode 100644 index 0000000000..3b017fc80f --- /dev/null +++ b/.kokoro/continuous/integration.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} diff --git a/.kokoro/continuous/java11.cfg b/.kokoro/continuous/java11.cfg new file mode 100644 index 0000000000..709f2b4c73 --- /dev/null +++ b/.kokoro/continuous/java11.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java11" +} diff --git a/.kokoro/continuous/java7.cfg b/.kokoro/continuous/java7.cfg new file mode 100644 index 0000000000..cb24f44eea --- /dev/null +++ b/.kokoro/continuous/java7.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java7" +} diff --git a/.kokoro/continuous/java8-osx.cfg b/.kokoro/continuous/java8-osx.cfg new file mode 100644 index 0000000000..8b617e2594 --- /dev/null +++ b/.kokoro/continuous/java8-osx.cfg @@ -0,0 +1,3 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "java-core/.kokoro/build.sh" diff --git a/.kokoro/continuous/java8-win.cfg b/.kokoro/continuous/java8-win.cfg new file mode 100644 index 0000000000..1a6311a420 --- /dev/null +++ b/.kokoro/continuous/java8-win.cfg @@ -0,0 +1,3 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "java-core/.kokoro/build.bat" diff --git a/.kokoro/continuous/java8.cfg b/.kokoro/continuous/java8.cfg new file mode 100644 index 0000000000..3b017fc80f --- /dev/null +++ b/.kokoro/continuous/java8.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} diff --git a/.kokoro/continuous/lint.cfg b/.kokoro/continuous/lint.cfg new file mode 100644 index 0000000000..6d323c8ae7 --- /dev/null +++ b/.kokoro/continuous/lint.cfg @@ -0,0 +1,13 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. + +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} + +env_vars: { + key: "JOB_TYPE" + value: "lint" +} \ No newline at end of file diff --git a/.kokoro/continuous/propose_release.cfg b/.kokoro/continuous/propose_release.cfg new file mode 100644 index 0000000000..fc798ae888 --- /dev/null +++ b/.kokoro/continuous/propose_release.cfg @@ -0,0 +1,53 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Build logs will be here +action { + define_artifacts { + regex: "**/*sponge_log.xml" + } +} + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Use the trampoline script to run in docker. +build_file: "java-core/.kokoro/trampoline.sh" + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/continuous/propose_release.sh" +} + +# tokens used by release-please to keep an up-to-date release PR. +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "github-magic-proxy-key-release-please" + } + } +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "github-magic-proxy-token-release-please" + } + } +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "github-magic-proxy-url-release-please" + } + } +} diff --git a/.kokoro/continuous/propose_release.sh b/.kokoro/continuous/propose_release.sh new file mode 100755 index 0000000000..1fd8acb1bf --- /dev/null +++ b/.kokoro/continuous/propose_release.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +export NPM_CONFIG_PREFIX=/home/node/.npm-global + +if [ -f ${KOKORO_KEYSTORE_DIR}/73713_github-magic-proxy-url-release-please ]; then + # Groom the release PR as new commits are merged. + npx release-please release-pr --token=${KOKORO_KEYSTORE_DIR}/73713_github-magic-proxy-token-release-please \ + --repo-url=googleapis/java-core \ + --package-name="google-cloud-core" \ + --api-url=${KOKORO_KEYSTORE_DIR}/73713_github-magic-proxy-url-release-please \ + --proxy-key=${KOKORO_KEYSTORE_DIR}/73713_github-magic-proxy-key-release-please \ + --release-type=java-yoshi +fi diff --git a/.kokoro/dependencies.sh b/.kokoro/dependencies.sh new file mode 100755 index 0000000000..51e976d441 --- /dev/null +++ b/.kokoro/dependencies.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +cd github/java-core/ + +# Print out Java +java -version +echo $JOB_TYPE + +export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m" + +mvn install -DskipTests=true -B -V +mvn -B dependency:analyze -DfailOnWarning=true diff --git a/.kokoro/linkage-monitor.sh b/.kokoro/linkage-monitor.sh new file mode 100755 index 0000000000..ec3da4ec35 --- /dev/null +++ b/.kokoro/linkage-monitor.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail +# Display commands being run. +set -x + +cd github/java-core/ + +# Print out Java version +java -version +echo ${JOB_TYPE} + +mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dgcloud.download.skip=true -B -V + +# Kokoro job cloud-opensource-java/ubuntu/linkage-monitor-gcs creates this JAR +JAR=linkage-monitor-latest-all-deps.jar +curl -v -O "https://storage.googleapis.com/cloud-opensource-java-linkage-monitor/${JAR}" + +# Fails if there's new linkage errors compared with baseline +java -jar ${JAR} com.google.cloud:libraries-bom diff --git a/.kokoro/nightly/common.cfg b/.kokoro/nightly/common.cfg new file mode 100644 index 0000000000..af5a907dc4 --- /dev/null +++ b/.kokoro/nightly/common.cfg @@ -0,0 +1,24 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Build logs will be here +action { + define_artifacts { + regex: "**/*sponge_log.xml" + } +} + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Use the trampoline script to run in docker. +build_file: "java-core/.kokoro/trampoline.sh" + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/build.sh" +} + +env_vars: { + key: "JOB_TYPE" + value: "test" +} diff --git a/.kokoro/nightly/dependencies.cfg b/.kokoro/nightly/dependencies.cfg new file mode 100644 index 0000000000..895832a928 --- /dev/null +++ b/.kokoro/nightly/dependencies.cfg @@ -0,0 +1,12 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/dependencies.sh" +} diff --git a/.kokoro/nightly/integration.cfg b/.kokoro/nightly/integration.cfg new file mode 100644 index 0000000000..3b017fc80f --- /dev/null +++ b/.kokoro/nightly/integration.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} diff --git a/.kokoro/nightly/java11.cfg b/.kokoro/nightly/java11.cfg new file mode 100644 index 0000000000..709f2b4c73 --- /dev/null +++ b/.kokoro/nightly/java11.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java11" +} diff --git a/.kokoro/nightly/java7.cfg b/.kokoro/nightly/java7.cfg new file mode 100644 index 0000000000..cb24f44eea --- /dev/null +++ b/.kokoro/nightly/java7.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java7" +} diff --git a/.kokoro/nightly/java8-osx.cfg b/.kokoro/nightly/java8-osx.cfg new file mode 100644 index 0000000000..8b617e2594 --- /dev/null +++ b/.kokoro/nightly/java8-osx.cfg @@ -0,0 +1,3 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "java-core/.kokoro/build.sh" diff --git a/.kokoro/nightly/java8-win.cfg b/.kokoro/nightly/java8-win.cfg new file mode 100644 index 0000000000..1a6311a420 --- /dev/null +++ b/.kokoro/nightly/java8-win.cfg @@ -0,0 +1,3 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "java-core/.kokoro/build.bat" diff --git a/.kokoro/nightly/java8.cfg b/.kokoro/nightly/java8.cfg new file mode 100644 index 0000000000..3b017fc80f --- /dev/null +++ b/.kokoro/nightly/java8.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} diff --git a/.kokoro/nightly/lint.cfg b/.kokoro/nightly/lint.cfg new file mode 100644 index 0000000000..6d323c8ae7 --- /dev/null +++ b/.kokoro/nightly/lint.cfg @@ -0,0 +1,13 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. + +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} + +env_vars: { + key: "JOB_TYPE" + value: "lint" +} \ No newline at end of file diff --git a/.kokoro/presubmit/common.cfg b/.kokoro/presubmit/common.cfg new file mode 100644 index 0000000000..4ba4e252c5 --- /dev/null +++ b/.kokoro/presubmit/common.cfg @@ -0,0 +1,33 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Build logs will be here +action { + define_artifacts { + regex: "**/*sponge_log.xml" + } +} + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Use the trampoline script to run in docker. +build_file: "java-core/.kokoro/trampoline.sh" + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/build.sh" +} + +env_vars: { + key: "JOB_TYPE" + value: "test" +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "dpebot_codecov_token" + } + } +} diff --git a/.kokoro/presubmit/dependencies.cfg b/.kokoro/presubmit/dependencies.cfg new file mode 100644 index 0000000000..895832a928 --- /dev/null +++ b/.kokoro/presubmit/dependencies.cfg @@ -0,0 +1,12 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/dependencies.sh" +} diff --git a/.kokoro/presubmit/integration.cfg b/.kokoro/presubmit/integration.cfg new file mode 100644 index 0000000000..3b017fc80f --- /dev/null +++ b/.kokoro/presubmit/integration.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} diff --git a/.kokoro/presubmit/java11.cfg b/.kokoro/presubmit/java11.cfg new file mode 100644 index 0000000000..709f2b4c73 --- /dev/null +++ b/.kokoro/presubmit/java11.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java11" +} diff --git a/.kokoro/presubmit/java7.cfg b/.kokoro/presubmit/java7.cfg new file mode 100644 index 0000000000..cb24f44eea --- /dev/null +++ b/.kokoro/presubmit/java7.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java7" +} diff --git a/.kokoro/presubmit/java8-osx.cfg b/.kokoro/presubmit/java8-osx.cfg new file mode 100644 index 0000000000..8b617e2594 --- /dev/null +++ b/.kokoro/presubmit/java8-osx.cfg @@ -0,0 +1,3 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "java-core/.kokoro/build.sh" diff --git a/.kokoro/presubmit/java8-win.cfg b/.kokoro/presubmit/java8-win.cfg new file mode 100644 index 0000000000..1a6311a420 --- /dev/null +++ b/.kokoro/presubmit/java8-win.cfg @@ -0,0 +1,3 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "java-core/.kokoro/build.bat" diff --git a/.kokoro/presubmit/java8.cfg b/.kokoro/presubmit/java8.cfg new file mode 100644 index 0000000000..3b017fc80f --- /dev/null +++ b/.kokoro/presubmit/java8.cfg @@ -0,0 +1,7 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} diff --git a/.kokoro/presubmit/linkage-monitor.cfg b/.kokoro/presubmit/linkage-monitor.cfg new file mode 100644 index 0000000000..8703ea2a3e --- /dev/null +++ b/.kokoro/presubmit/linkage-monitor.cfg @@ -0,0 +1,12 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/linkage-monitor.sh" +} \ No newline at end of file diff --git a/.kokoro/presubmit/lint.cfg b/.kokoro/presubmit/lint.cfg new file mode 100644 index 0000000000..6d323c8ae7 --- /dev/null +++ b/.kokoro/presubmit/lint.cfg @@ -0,0 +1,13 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. + +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} + +env_vars: { + key: "JOB_TYPE" + value: "lint" +} \ No newline at end of file diff --git a/.kokoro/release/bump_snapshot.cfg b/.kokoro/release/bump_snapshot.cfg new file mode 100644 index 0000000000..a27810aacf --- /dev/null +++ b/.kokoro/release/bump_snapshot.cfg @@ -0,0 +1,53 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Build logs will be here +action { + define_artifacts { + regex: "**/*sponge_log.xml" + } +} + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Use the trampoline script to run in docker. +build_file: "java-core/.kokoro/trampoline.sh" + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/release/bump_snapshot.sh" +} + +# tokens used by release-please to keep an up-to-date release PR. +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "github-magic-proxy-key-release-please" + } + } +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "github-magic-proxy-token-release-please" + } + } +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "github-magic-proxy-url-release-please" + } + } +} diff --git a/.kokoro/release/bump_snapshot.sh b/.kokoro/release/bump_snapshot.sh new file mode 100755 index 0000000000..712ce36594 --- /dev/null +++ b/.kokoro/release/bump_snapshot.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +export NPM_CONFIG_PREFIX=/home/node/.npm-global + +if [ -f ${KOKORO_KEYSTORE_DIR}/73713_github-magic-proxy-url-release-please ]; then + # Groom the snapshot release PR immediately after publishing a release + npx release-please release-pr --token=${KOKORO_KEYSTORE_DIR}/73713_github-magic-proxy-token-release-please \ + --repo-url=googleapis/java-core \ + --package-name="google-cloud-core" \ + --api-url=${KOKORO_KEYSTORE_DIR}/73713_github-magic-proxy-url-release-please \ + --proxy-key=${KOKORO_KEYSTORE_DIR}/73713_github-magic-proxy-key-release-please \ + --snapshot \ + --release-type=java-auth-yoshi +fi diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg new file mode 100644 index 0000000000..4b5b862167 --- /dev/null +++ b/.kokoro/release/common.cfg @@ -0,0 +1,49 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Use the trampoline script to run in docker. +build_file: "java-core/.kokoro/trampoline.sh" + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 70247 + keyname: "maven-gpg-keyring" + } + } +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 70247 + keyname: "maven-gpg-passphrase" + } + } +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 70247 + keyname: "maven-gpg-pubkeyring" + } + } +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 70247 + keyname: "sonatype-credentials" + } + } +} diff --git a/.kokoro/release/common.sh b/.kokoro/release/common.sh new file mode 100755 index 0000000000..6e3f65999b --- /dev/null +++ b/.kokoro/release/common.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# Copyright 2018 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +# Get secrets from keystore and set and environment variables +setup_environment_secrets() { + export GPG_PASSPHRASE=$(cat ${KOKORO_KEYSTORE_DIR}/70247_maven-gpg-passphrase) + export GPG_TTY=$(tty) + export GPG_HOMEDIR=/gpg + mkdir $GPG_HOMEDIR + mv ${KOKORO_KEYSTORE_DIR}/70247_maven-gpg-pubkeyring $GPG_HOMEDIR/pubring.gpg + mv ${KOKORO_KEYSTORE_DIR}/70247_maven-gpg-keyring $GPG_HOMEDIR/secring.gpg + export SONATYPE_USERNAME=$(cat ${KOKORO_KEYSTORE_DIR}/70247_sonatype-credentials | cut -f1 -d'|') + export SONATYPE_PASSWORD=$(cat ${KOKORO_KEYSTORE_DIR}/70247_sonatype-credentials | cut -f2 -d'|') +} + +create_settings_xml_file() { + echo " + + + ossrh + ${SONATYPE_USERNAME} + ${SONATYPE_PASSWORD} + + + sonatype-nexus-staging + ${SONATYPE_USERNAME} + ${SONATYPE_PASSWORD} + + + sonatype-nexus-snapshots + ${SONATYPE_USERNAME} + ${SONATYPE_PASSWORD} + + +" > $1 +} \ No newline at end of file diff --git a/.kokoro/release/drop.cfg b/.kokoro/release/drop.cfg new file mode 100644 index 0000000000..211c014c2a --- /dev/null +++ b/.kokoro/release/drop.cfg @@ -0,0 +1,9 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/release/drop.sh" +} + +# Download staging properties file. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java/releases/java-core" \ No newline at end of file diff --git a/.kokoro/release/drop.sh b/.kokoro/release/drop.sh new file mode 100755 index 0000000000..5c4551efa2 --- /dev/null +++ b/.kokoro/release/drop.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Copyright 2018 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +# STAGING_REPOSITORY_ID must be set +if [ -z "${STAGING_REPOSITORY_ID}" ]; then + echo "Missing STAGING_REPOSITORY_ID environment variable" + exit 1 +fi + +source $(dirname "$0")/common.sh +pushd $(dirname "$0")/../../ + +setup_environment_secrets +create_settings_xml_file "settings.xml" + +mvn nexus-staging:drop -B \ + --settings=settings.xml \ + -DstagingRepositoryId=${STAGING_REPOSITORY_ID} diff --git a/.kokoro/release/promote.cfg b/.kokoro/release/promote.cfg new file mode 100644 index 0000000000..b3fc2015d6 --- /dev/null +++ b/.kokoro/release/promote.cfg @@ -0,0 +1,10 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/release/promote.sh" +} + +# Download staging properties file. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java/releases/java-core" + diff --git a/.kokoro/release/promote.sh b/.kokoro/release/promote.sh new file mode 100755 index 0000000000..1fa95fa537 --- /dev/null +++ b/.kokoro/release/promote.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Copyright 2018 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +# STAGING_REPOSITORY_ID must be set +if [ -z "${STAGING_REPOSITORY_ID}" ]; then + echo "Missing STAGING_REPOSITORY_ID environment variable" + exit 1 +fi + +source $(dirname "$0")/common.sh + +pushd $(dirname "$0")/../../ + +setup_environment_secrets +create_settings_xml_file "settings.xml" + +mvn nexus-staging:release -B \ + -DperformRelease=true \ + --settings=settings.xml \ + -DstagingRepositoryId=${STAGING_REPOSITORY_ID} diff --git a/.kokoro/release/publish_javadoc.cfg b/.kokoro/release/publish_javadoc.cfg new file mode 100644 index 0000000000..166868b690 --- /dev/null +++ b/.kokoro/release/publish_javadoc.cfg @@ -0,0 +1,19 @@ +# Format: //devtools/kokoro/config/proto/build.proto +env_vars: { + key: "STAGING_BUCKET" + value: "docs-staging" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/release/publish_javadoc.sh" +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "docuploader_service_account" + } + } +} diff --git a/.kokoro/release/publish_javadoc.sh b/.kokoro/release/publish_javadoc.sh new file mode 100755 index 0000000000..3eb587a7dc --- /dev/null +++ b/.kokoro/release/publish_javadoc.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# Copyright 2019 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +if [[ -z "${CREDENTIALS}" ]]; then + CREDENTIALS=${KOKORO_KEYSTORE_DIR}/73713_docuploader_service_account +fi + +if [[ -z "${STAGING_BUCKET}" ]]; then + echo "Need to set STAGING_BUCKET environment variable" + exit 1 +fi + +# work from the git root directory +pushd $(dirname "$0")/../../ + +# install docuploader package +python3 -m pip install gcp-docuploader + +# compile all packages +mvn clean install -B -DskipTests=true + +NAME=google-cloud-core +VERSION=$(grep ${NAME}: versions.txt | cut -d: -f3) + +# build the docs +mvn site -B + +pushd target/site/apidocs + +# create metadata +python3 -m docuploader create-metadata \ + --name ${NAME} \ + --version ${VERSION} \ + --language java + +# upload docs +python3 -m docuploader upload . \ + --credentials ${CREDENTIALS} \ + --staging-bucket ${STAGING_BUCKET} + +popd diff --git a/.kokoro/release/snapshot.cfg b/.kokoro/release/snapshot.cfg new file mode 100644 index 0000000000..d435702932 --- /dev/null +++ b/.kokoro/release/snapshot.cfg @@ -0,0 +1,6 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/release/snapshot.sh" +} \ No newline at end of file diff --git a/.kokoro/release/snapshot.sh b/.kokoro/release/snapshot.sh new file mode 100755 index 0000000000..bf738c56dd --- /dev/null +++ b/.kokoro/release/snapshot.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +source $(dirname "$0")/common.sh +MAVEN_SETTINGS_FILE=$(realpath $(dirname "$0")/../../)/settings.xml +pushd $(dirname "$0")/../../ + +setup_environment_secrets +create_settings_xml_file "settings.xml" + +mvn clean install deploy -B \ + --settings ${MAVEN_SETTINGS_FILE} \ + -DperformRelease=true \ + -Dgpg.executable=gpg \ + -Dgpg.passphrase=${GPG_PASSPHRASE} \ + -Dgpg.homedir=${GPG_HOMEDIR} \ No newline at end of file diff --git a/.kokoro/release/stage.cfg b/.kokoro/release/stage.cfg new file mode 100644 index 0000000000..7d8a196382 --- /dev/null +++ b/.kokoro/release/stage.cfg @@ -0,0 +1,44 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-core/.kokoro/release/stage.sh" +} + +# Need to save the properties file +action { + define_artifacts { + regex: "github/java-core/target/nexus-staging/staging/*.properties" + strip_prefix: "github/java-core" + } +} + +# Fetch the token needed for reporting release status to GitHub +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "yoshi-automation-github-key" + } + } +} + +# Fetch magictoken to use with Magic Github Proxy +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "releasetool-magictoken" + } + } +} + +# Fetch api key to use with Magic Github Proxy +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "magic-github-proxy-api-key" + } + } +} diff --git a/.kokoro/release/stage.sh b/.kokoro/release/stage.sh new file mode 100755 index 0000000000..b1b1b01c66 --- /dev/null +++ b/.kokoro/release/stage.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# Copyright 2018 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +# Start the releasetool reporter +python3 -m pip install gcp-releasetool +python3 -m releasetool publish-reporter-script > /tmp/publisher-script; source /tmp/publisher-script + +source $(dirname "$0")/common.sh +MAVEN_SETTINGS_FILE=$(realpath $(dirname "$0")/../../)/settings.xml +pushd $(dirname "$0")/../../ + +setup_environment_secrets +create_settings_xml_file "settings.xml" + +mvn clean install deploy -B \ + --settings ${MAVEN_SETTINGS_FILE} \ + -DperformRelease=true \ + -Dgpg.executable=gpg \ + -Dgpg.passphrase=${GPG_PASSPHRASE} \ + -Dgpg.homedir=${GPG_HOMEDIR} + +if [[ -n "${AUTORELEASE_PR}" ]] +then + mvn nexus-staging:release -B \ + -DperformRelease=true \ + --settings=settings.xml +fi \ No newline at end of file diff --git a/.kokoro/trampoline.sh b/.kokoro/trampoline.sh new file mode 100644 index 0000000000..ba17ce0146 --- /dev/null +++ b/.kokoro/trampoline.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Copyright 2018 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -eo pipefail +# Always run the cleanup script, regardless of the success of bouncing into +# the container. +function cleanup() { + chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh + ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh + echo "cleanup"; +} +trap cleanup EXIT +python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" diff --git a/.repo-metadata.json b/.repo-metadata.json new file mode 100644 index 0000000000..e3e884930d --- /dev/null +++ b/.repo-metadata.json @@ -0,0 +1,9 @@ +{ + "name": "google-cloud-core", + "name_pretty": "Google Cloud Core", + "release_level": "ga", + "language": "java", + "repo": "googleapis/java-core", + "repo_short": "java-core", + "distribution_name": "google-cloud-java" +} diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000..6b2238bb75 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,93 @@ +# Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviors that they deem inappropriate, threatening, +offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +This Code of Conduct also applies outside the project spaces when the Project +Steward has a reasonable belief that an individual's behavior may have a +negative impact on the project or its community. + +## Conflict Resolution + +We do not believe that all conflict is bad; healthy debate and disagreement +often yield positive results. However, it is never okay to be disrespectful or +to engage in behavior that violates the project’s code of conduct. + +If you see someone violating the code of conduct, you are encouraged to address +the behavior directly with those involved. Many issues can be resolved quickly +and easily, and this gives people more control over the outcome of their +dispute. If you are unable to resolve the matter for any reason, or if the +behavior is threatening or harassing, report it. We are dedicated to providing +an environment where participants feel welcome and safe. + +Reports should be directed to *[PROJECT STEWARD NAME(s) AND EMAIL(s)]*, the +Project Steward(s) for *[PROJECT NAME]*. It is the Project Steward’s duty to +receive and address reported violations of the code of conduct. They will then +work with a committee consisting of representatives from the Open Source +Programs Office and the Google Open Source Strategy team. If for any reason you +are uncomfortable reaching out the Project Steward, please email +opensource@google.com. + +We will investigate every complaint, but you may not receive a direct response. +We will use our discretion in determining when and how to follow up on reported +incidents, which may range from not taking action to permanent expulsion from +the project and project-sponsored spaces. We will notify the accused of the +report and provide them an opportunity to discuss it before any action is taken. +The identity of the reporter will be omitted from the details of the report +supplied to the accused. In potentially harmful situations, such as ongoing +harassment or threats to anyone's safety, we may take action without notice. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, +available at +https://www.contributor-covenant.org/version/1/4/code-of-conduct.html \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..ebbb59e531 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,28 @@ +# How to Contribute + +We'd love to accept your patches and contributions to this project. There are +just a few small guidelines you need to follow. + +## Contributor License Agreement + +Contributions to this project must be accompanied by a Contributor License +Agreement. You (or your employer) retain the copyright to your contribution; +this simply gives us permission to use and redistribute your contributions as +part of the project. Head over to to see +your current agreements on file or to sign a new one. + +You generally only need to submit a CLA once, so if you've already submitted one +(even if it was for a different project), you probably don't need to do it +again. + +## Code reviews + +All submissions, including submissions by project members, require review. We +use GitHub pull requests for this purpose. Consult +[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more +information on using pull requests. + +## Community Guidelines + +This project follows +[Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). \ No newline at end of file diff --git a/LICENSE b/LICENSE index 4eedc0116a..d645695673 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ -Apache License + + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -178,7 +179,7 @@ Apache License APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" + boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a diff --git a/README.md b/README.md new file mode 100644 index 0000000000..d65c275324 --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +# Google Cloud Java Client -- Core + +This module provides common functionality required by service-specific modules of this library. + +[![Kokoro CI][kokoro-badge]][kokoro-badge-link] +[![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg) + +- [API Documentation][api-docs] + +## Quickstart + +[//]: # ({x-version-update-start:google-cloud-core:released}) +If you are using Maven, add this to your pom.xml file +```xml + + com.google.cloud + google-cloud-core + 1.84.0 + +``` +If you are using Gradle, add this to your dependencies +```Groovy +compile 'com.google.cloud:google-cloud-core:1.84.0' +``` +If you are using SBT, add this to your dependencies +```Scala +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.84.0" +``` +[//]: # ({x-version-update-end}) + +## Java Versions + +Java 7 or above is required for using this client. + +## Contributing + +Contributions to this library are always welcome and highly encouraged. + +See [CONTRIBUTING][contributing] documentation for more information on how to get started. + +Please note that this project is released with a Contributor Code of Conduct. By participating in +this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more +information. + +## Versioning + +This library follows [Semantic Versioning][semver]. + +It is currently in major version one (``1.y.z``), which means that the public API should be +considered stable. + +## License + +Apache 2.0 - See [LICENSE][license] for more information. + +[contributing]: https://github.com/googleapis/java-core/blob/master/CONTRIBUTING.md +[code-of-conduct]: https://github.com/googleapis/java-core/blob/master/CODE_OF_CONDUCT.md +[license]: https://github.com/googleapis/java-core/blob/master/LICENSE +[semver]: http://semver.org/ +[cloud-platform]: https://cloud.google.com/ +[kokoro-badge]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/master.svg +[kokoro-badge-link]: (http://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/master.html) +[api-docs]: https://googleapis.dev/java/google-cloud-core/latest diff --git a/codecov.yaml b/codecov.yaml new file mode 100644 index 0000000000..5724ea9478 --- /dev/null +++ b/codecov.yaml @@ -0,0 +1,4 @@ +--- +codecov: + ci: + - source.cloud.google.com diff --git a/java.header b/java.header new file mode 100644 index 0000000000..3a9b503aa2 --- /dev/null +++ b/java.header @@ -0,0 +1,15 @@ +^/\*$ +^ \* Copyright \d\d\d\d,? Google (Inc\.|LLC)( All [rR]ights [rR]eserved\.)?$ +^ \*$ +^ \* Licensed under the Apache License, Version 2\.0 \(the "License"\);$ +^ \* you may not use this file except in compliance with the License\.$ +^ \* You may obtain a copy of the License at$ +^ \*$ +^ \*[ ]+https?://www.apache.org/licenses/LICENSE-2\.0$ +^ \*$ +^ \* Unless required by applicable law or agreed to in writing, software$ +^ \* distributed under the License is distributed on an "AS IS" BASIS,$ +^ \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.$ +^ \* See the License for the specific language governing permissions and$ +^ \* limitations under the License\.$ +^ \*/$ diff --git a/license-checks.xml b/license-checks.xml new file mode 100644 index 0000000000..6597fced80 --- /dev/null +++ b/license-checks.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000000..e3e4334dae --- /dev/null +++ b/renovate.json @@ -0,0 +1,29 @@ +{ + "extends": [ + "config:base" + ], + "ignoreDeps": [ + "com.google.api:gax-bom", + "com.google.guava:guava", + "com.google.guava:guava-testlib", + "com.google.protobuf:protobuf-java", + "com.google.protobuf:protobuf-java-util", + "io.opencensus:opencensus-api", + "io.opencensus:opencensus-contrib-grpc-util", + "io.opencensus:opencensus-contrib-http-util" + ], + "packageRules": [ + { + "packagePatterns": ["^io.grpc:grpc-"], + "groupName": "gRPC packages" + }, + { + "packagePatterns": ["^com.google.protobuf:protobuf-"], + "groupName": "Protobuf packages" + }, + { + "packagePatterns": ["^io.opencensus:opencensus-"], + "groupName": "OpenCensus packages" + } + ] +} \ No newline at end of file diff --git a/synth.metadata b/synth.metadata new file mode 100644 index 0000000000..97bbf24fdf --- /dev/null +++ b/synth.metadata @@ -0,0 +1,12 @@ +{ + "updateTime": "2019-09-06T16:09:54.850638Z", + "sources": [ + { + "template": { + "name": "java_library", + "origin": "synthtool.gcp", + "version": "2019.5.2" + } + } + ] +} \ No newline at end of file diff --git a/synth.py b/synth.py new file mode 100644 index 0000000000..b3e7b1e030 --- /dev/null +++ b/synth.py @@ -0,0 +1,27 @@ +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""This script is used to synthesize generated parts of this library.""" + +import synthtool as s +import synthtool.gcp as gcp +import logging +logging.basicConfig(level=logging.DEBUG) +common_templates = gcp.CommonTemplates() +templates = common_templates.java_library() +s.copy(templates, excludes=[ + '.gitignore', + 'README.md', +]) + From 19d79d64ae462dbc211c7177111b4b04199402e4 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 6 Sep 2019 09:30:08 -0700 Subject: [PATCH 649/663] docs: fix Kokoro badge link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d65c275324..b33fcfd7d8 100644 --- a/README.md +++ b/README.md @@ -59,5 +59,5 @@ Apache 2.0 - See [LICENSE][license] for more information. [semver]: http://semver.org/ [cloud-platform]: https://cloud.google.com/ [kokoro-badge]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/master.svg -[kokoro-badge-link]: (http://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/master.html) +[kokoro-badge-link]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/master.html [api-docs]: https://googleapis.dev/java/google-cloud-core/latest From 178d659bca6213abbec197cdfa1b84fdfd42fe12 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 6 Sep 2019 09:44:50 -0700 Subject: [PATCH 650/663] chore: add parent pom (#12) * chore: add parent pom * fix: dependency declarations --- google-cloud-core-grpc/pom.xml | 36 ++- google-cloud-core-http/pom.xml | 30 ++- google-cloud-core/pom.xml | 38 ++- pom.xml | 412 +++++++++++++++++++++++++++++++++ versions.txt | 4 + 5 files changed, 505 insertions(+), 15 deletions(-) create mode 100644 pom.xml create mode 100644 versions.txt diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index da06d875fb..0a6ff007e6 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -1,8 +1,9 @@ 4.0.0 + com.google.cloud google-cloud-core-grpc - 1.90.1-SNAPSHOT + 1.90.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -11,8 +12,8 @@ com.google.cloud - google-cloud-clients - 0.108.1-alpha-SNAPSHOT + google-cloud-core-parent + 1.90.1-SNAPSHOT google-cloud-core-grpc @@ -30,6 +31,31 @@ com.google.guava guava + + com.google.api + gax + + + com.google.api + gax-grpc + + + com.google.api + api-common + + + io.grpc + grpc-api + + + io.grpc + grpc-core + + + com.google.http-client + google-http-client + + junit junit @@ -45,9 +71,5 @@ objenesis test - - com.google.api - gax-grpc - \ No newline at end of file diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index dc4b39ae6e..cdfaf99fac 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -1,8 +1,9 @@ 4.0.0 + com.google.cloud google-cloud-core-http - 1.90.1-SNAPSHOT + 1.90.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -11,8 +12,8 @@ com.google.cloud - google-cloud-clients - 0.108.1-alpha-SNAPSHOT + google-cloud-core-parent + 1.90.1-SNAPSHOT google-cloud-core-http @@ -33,7 +34,6 @@ com.google.http-client google-http-client - compile com.google.guava @@ -42,17 +42,35 @@ com.google.api-client google-api-client - compile com.google.http-client google-http-client-appengine - compile + + + com.google.api + gax com.google.api gax-httpjson + + com.google.code.findbugs + jsr305 + + + io.opencensus + opencensus-api + + + io.opencensus + opencensus-contrib-http-util + + + com.google.api + api-common + diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index fd281c6f49..df8b1b364d 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -1,6 +1,7 @@ 4.0.0 + com.google.cloud google-cloud-core 1.90.1-SNAPSHOT jar @@ -11,8 +12,8 @@ com.google.cloud - google-cloud-clients - 0.108.1-alpha-SNAPSHOT + google-cloud-core-parent + 1.90.1-SNAPSHOT google-cloud-core @@ -49,6 +50,39 @@ com.google.api.grpc proto-google-iam-v1 + + org.threeten + threetenbp + + + com.google.api + api-common + + + com.google.auth + google-auth-library-credentials + + + com.google.auth + google-auth-library-oauth2-http + + + com.google.http-client + google-http-client + + + com.google.http-client + google-http-client-jackson2 + + + com.google.protobuf + protobuf-java + + + com.google.guava + guava + + com.google.truth truth diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000..28cfe9ddec --- /dev/null +++ b/pom.xml @@ -0,0 +1,412 @@ + + + 4.0.0 + com.google.cloud + google-cloud-core-parent + pom + 1.90.1-SNAPSHOT + Google Cloud Core Parent + https://github.com/googleapis/java-core + + Java idiomatic client for Google Cloud Platform services. + + + + com.google.cloud + google-cloud-shared-config + 0.1.0 + + + + + garrettjonesgoogle + Garrett Jones + garrettjones@google.com + Google + + Developer + + + + pongad + Michael Darakananda + pongad@google.com + Google + + Developer + + + + shinfan + Shin Fan + shinfan@google.com + Google + + Developer + + + + michaelbausor + Micheal Bausor + michaelbausor@google.com + Google + + Developer + + + + vam-google + Vadym Matsishevskyi + vam@google.com + Google + + Developer + + + + tswast + Tim Swast + tswast@google.com + Google + + Developer + + + + neozwu + Neo Wu + neowu@google.com + Google + + Developer + + + + lesv + Les Vogel + lesv@google.com + Google + + Developer + + + + schmidt_sebastian + Sebastian Schmidt + mrschmidt@google.com + Google + + Developer + + + + andreamlin + Andrea Lin + andrealin@google.com + + Developer + + + + hzyi-google + Hanzhen Yi + hzyi@google.com + + Developer + + + + + Google LLC + + + scm:git:git@github.com:googleapis/java-core.git + scm:git:git@github.com:googleapis/java-core.git + https://github.com/googleapis/java-core + HEAD + + + https://github.com/googleapis/java-core/issues + GitHub Issues + + + + sonatype-nexus-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-staging + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + Apache-2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + UTF-8 + UTF-8 + github + google-cloud-core-parent + + 1.48.1 + 1.8.1 + 1.16.0 + 0.12.0 + 0.17.1 + 1.30.2 + 1.31.0 + 1.23.0 + 3.9.1 + 0.23.0 + 1.3.2 + 28.0-android + 4.12 + 1.0 + 3.6 + 3.0.2 + 1.3.3 + 2.6 + 2.3.2 + 1.6.6 + 2.8.5 + + + + + + com.google.cloud + google-cloud-core + ${project.version} + + + + com.google.auth + google-auth-library-bom + ${google.auth.version} + pom + import + + + com.google.api + gax-bom + ${gax.version} + pom + import + + + com.google.http-client + google-http-client-bom + ${google.http.version} + pom + import + + + com.google.api-client + google-api-client-bom + ${google.api.version} + pom + import + + + io.grpc + grpc-bom + ${grpc.version} + pom + import + + + com.google.protobuf + protobuf-bom + ${protobuf.version} + pom + import + + + com.google.guava + guava-bom + ${guava.version} + pom + import + + + + com.google.api + api-common + ${google.api-common.version} + + + com.google.api.grpc + proto-google-common-protos + ${google.common-protos.version} + + + com.google.api.grpc + proto-google-iam-v1 + ${google.iam.version} + + + + + io.opencensus + opencensus-api + ${opencensus.version} + + + io.opencensus + opencensus-contrib-http-util + ${opencensus.version} + + + + javax.annotation + javax.annotation-api + ${annotations-api.version} + + + com.google.code.findbugs + jsr305 + ${findbugs.version} + + + org.threeten + threetenbp + ${threetenbp.version} + + + com.google.errorprone + error_prone_annotations + ${errorprone.version} + + + com.google.auto.value + auto-value-annotations + ${autovalue.version} + + + com.google.code.gson + gson + ${gson.version} + + + + + com.google.truth + truth + ${truth.version} + test + + + junit + junit + ${junit.version} + test + + + org.easymock + easymock + ${easymock.version} + test + + + org.objenesis + objenesis + ${objenesis.version} + test + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + org.objenesis:objenesis + + + + + + + + google-cloud-core + google-cloud-core-http + google-cloud-core-grpc + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + + index + dependency-info + team + ci-management + issue-management + licenses + scm + dependency-management + distribution-management + summary + modules + + + + + true + ${site.installationModule} + jar + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + + html + + aggregate + javadoc + + + + + none + protected + true + ${project.build.directory}/javadoc + + + Test helpers packages + com.google.cloud.testing + + + SPI packages + com.google.cloud.spi* + + + + + https://grpc.io/grpc-java/javadoc/ + https://developers.google.com/protocol-buffers/docs/reference/java/ + https://googleapis.dev/java/google-auth-library/latest/ + https://googleapis.dev/java/gax/latest/ + https://googleapis.github.io/api-common-java/${google.api-common.version}/apidocs/ + + + + + + diff --git a/versions.txt b/versions.txt new file mode 100644 index 0000000000..c7eb90abbb --- /dev/null +++ b/versions.txt @@ -0,0 +1,4 @@ +# Format: +# module:released-version:current-version + +google-cloud-core:1.90.0:1.90.1-SNAPSHOT \ No newline at end of file From 6e3ccf398ffa4b38ecab7a505e74c13bf27af871 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 6 Sep 2019 09:48:14 -0700 Subject: [PATCH 651/663] docs: fix README versions and CI Status table --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b33fcfd7d8..a16d6b37a9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ This module provides common functionality required by service-specific modules of this library. -[![Kokoro CI][kokoro-badge]][kokoro-badge-link] [![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg) - [API Documentation][api-docs] @@ -15,16 +14,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.84.0 + 1.90.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.84.0' +compile 'com.google.cloud:google-cloud-core:1.90.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.84.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.90.0" ``` [//]: # ({x-version-update-end}) @@ -53,11 +52,18 @@ considered stable. Apache 2.0 - See [LICENSE][license] for more information. +## CI Status + +Java Version | Status +------------ | ------ +Java 7 | [![Kokoro CI](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java7.svg)](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java7.html) +Java 8 | [![Kokoro CI](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java8.svg)](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java8.html) +Java 11 | [![Kokoro CI](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java11.svg)](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java11.html) + + [contributing]: https://github.com/googleapis/java-core/blob/master/CONTRIBUTING.md [code-of-conduct]: https://github.com/googleapis/java-core/blob/master/CODE_OF_CONDUCT.md [license]: https://github.com/googleapis/java-core/blob/master/LICENSE [semver]: http://semver.org/ [cloud-platform]: https://cloud.google.com/ -[kokoro-badge]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/master.svg -[kokoro-badge-link]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/master.html [api-docs]: https://googleapis.dev/java/google-cloud-core/latest From 3cb19a0ff0049bbbf3d788812687181a3784527d Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 6 Sep 2019 13:19:24 -0700 Subject: [PATCH 652/663] feat: add google-cloud-core-bom artifact (#13) * feat: add google-cloud-core-bom artifact * fix: skip checkstyle on bom * fix: bom version --- google-cloud-core-bom/pom.xml | 92 +++++++++++++++++++++++++++++++++++ google-cloud-core/README.md | 69 -------------------------- pom.xml | 1 + 3 files changed, 93 insertions(+), 69 deletions(-) create mode 100644 google-cloud-core-bom/pom.xml delete mode 100644 google-cloud-core/README.md diff --git a/google-cloud-core-bom/pom.xml b/google-cloud-core-bom/pom.xml new file mode 100644 index 0000000000..c0f18683a5 --- /dev/null +++ b/google-cloud-core-bom/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + com.google.cloud + google-cloud-core-bom + 1.90.1-SNAPSHOT + pom + + com.google.cloud + google-cloud-shared-config + 0.1.0 + + + Google Cloud Core + https://github.com/googleapis/java-core/tree/master/google-cloud-core-bom + + BOM for Google Cloud Core + + + + Google LLC + + + + + chingor13 + Jeff Ching + chingor@google.com + Google LLC + + Developer + + + + + + scm:git:https://github.com/googleapis/java-core.git + scm:git:git@github.com:googleapis/java-core.git + https://github.com/googleapis/java-core + + + + + sonatype-nexus-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-staging + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + + com.google.cloud + google-cloud-core + 1.90.1-SNAPSHOT + + + com.google.cloud + google-cloud-core-grpc + 1.90.1-SNAPSHOT + + + com.google.cloud + google-cloud-core-http + 1.90.1-SNAPSHOT + + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + true + + + + + diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md deleted file mode 100644 index fd2b536604..0000000000 --- a/google-cloud-core/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Google Cloud Java Client -- Core -========================================= - -This module provides common functionality required by service-specific modules of this library. - -[![Kokoro CI](http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/master.svg)](http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/master.html) -[![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg) -[![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) - -- [API Documentation](https://googleapis.dev/java/google-cloud-clients/latest/index.html?com/google/cloud/package-summary.html) - -Quickstart ----------- - -[//]: # ({x-version-update-start:google-cloud-core:released}) -If you are using Maven, add this to your pom.xml file -```xml - - com.google.cloud - google-cloud-core - 1.90.0 - -``` -If you are using Gradle, add this to your dependencies -```Groovy -compile 'com.google.cloud:google-cloud-core:1.90.0' -``` -If you are using SBT, add this to your dependencies -```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.90.0" -``` -[//]: # ({x-version-update-end}) - -Troubleshooting ---------------- - -To get help, follow the instructions in the [shared Troubleshooting document](https://github.com/googleapis/google-cloud-common/blob/master/troubleshooting/readme.md#troubleshooting). - -Java Versions -------------- - -Java 7 or above is required for using this client. - -Contributing ------------- - -Contributions to this library are always welcome and highly encouraged. - -See `google-cloud`'s [CONTRIBUTING] documentation and the [shared documentation](https://github.com/googleapis/google-cloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started. - -Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information. - -Versioning ----------- - -This library follows [Semantic Versioning](http://semver.org/). - -It is currently in major version one (``1.y.z``), which means that the public API should be considered stable. - -License -------- - -Apache 2.0 - See [LICENSE] for more information. - - -[CONTRIBUTING]:https://github.com/googleapis/google-cloud-java/blob/master/CONTRIBUTING.md -[code-of-conduct]:https://github.com/googleapis/google-cloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct -[LICENSE]: https://github.com/googleapis/google-cloud-java/blob/master/LICENSE -[cloud-platform]: https://cloud.google.com/ diff --git a/pom.xml b/pom.xml index 28cfe9ddec..546f7c3a72 100644 --- a/pom.xml +++ b/pom.xml @@ -338,6 +338,7 @@ google-cloud-core google-cloud-core-http google-cloud-core-grpc + google-cloud-core-bom From 6fd909380c61267a4236c107b492721a4c7c4934 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sat, 7 Sep 2019 17:09:10 +0300 Subject: [PATCH 653/663] chore(deps): update dependency com.google.cloud:google-cloud-shared-config to v0.1.1 (#15) --- google-cloud-core-bom/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core-bom/pom.xml b/google-cloud-core-bom/pom.xml index c0f18683a5..173f4008f7 100644 --- a/google-cloud-core-bom/pom.xml +++ b/google-cloud-core-bom/pom.xml @@ -8,7 +8,7 @@ com.google.cloud google-cloud-shared-config - 0.1.0 + 0.1.1 Google Cloud Core diff --git a/pom.xml b/pom.xml index 546f7c3a72..e93dc1ac11 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.google.cloud google-cloud-shared-config - 0.1.0 + 0.1.1 From 5f82559c6f39360e169d460f1e990d705c6cfeb6 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 10 Sep 2019 09:41:44 -0700 Subject: [PATCH 654/663] build: regenerate configs from templates (#16) --- .kokoro/presubmit/integration.cfg | 24 ++++++++++++++++++++++++ synth.metadata | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.kokoro/presubmit/integration.cfg b/.kokoro/presubmit/integration.cfg index 3b017fc80f..141f90c13c 100644 --- a/.kokoro/presubmit/integration.cfg +++ b/.kokoro/presubmit/integration.cfg @@ -5,3 +5,27 @@ env_vars: { key: "TRAMPOLINE_IMAGE" value: "gcr.io/cloud-devrel-kokoro-resources/java8" } + +env_vars: { + key: "JOB_TYPE" + value: "integration" +} + +env_vars: { + key: "GCLOUD_PROJECT" + value: "gcloud-devel" +} + +env_vars: { + key: "GOOGLE_APPLICATION_CREDENTIALS" + value: "keystore/73713_java_it_service_account" +} + +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "java_it_service_account" + } + } +} diff --git a/synth.metadata b/synth.metadata index 97bbf24fdf..3396e2f5a6 100644 --- a/synth.metadata +++ b/synth.metadata @@ -1,5 +1,5 @@ { - "updateTime": "2019-09-06T16:09:54.850638Z", + "updateTime": "2019-09-10T08:05:23.089681Z", "sources": [ { "template": { From 018d4d59baa889e20323da16ffc2cb90574e5a2e Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Tue, 10 Sep 2019 10:52:14 -0700 Subject: [PATCH 655/663] docs: update README with a better project description (#17) --- README.md | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a16d6b37a9..c1ca94e02c 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,13 @@ # Google Cloud Java Client -- Core -This module provides common functionality required by service-specific modules of this library. +A set of classes and utilities used in Google Cloud Java libraries. + +*Note*: This library is only meant to be consumed by other Google Libraries. [![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-core.svg) - [API Documentation][api-docs] -## Quickstart - -[//]: # ({x-version-update-start:google-cloud-core:released}) -If you are using Maven, add this to your pom.xml file -```xml - - com.google.cloud - google-cloud-core - 1.90.0 - -``` -If you are using Gradle, add this to your dependencies -```Groovy -compile 'com.google.cloud:google-cloud-core:1.90.0' -``` -If you are using SBT, add this to your dependencies -```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.90.0" -``` -[//]: # ({x-version-update-end}) - ## Java Versions Java 7 or above is required for using this client. @@ -58,6 +39,8 @@ Java Version | Status ------------ | ------ Java 7 | [![Kokoro CI](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java7.svg)](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java7.html) Java 8 | [![Kokoro CI](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java8.svg)](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java8.html) +Java 8 OSX | [![Kokoro CI](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java8-osx.svg)](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java8-osx.html) +Java 8 Windows | [![Kokoro CI](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java8-win.svg)](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java8-win.html) Java 11 | [![Kokoro CI](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java11.svg)](https://storage.googleapis.com/cloud-devrel-public/java/badges/java-core/java11.html) From 48511f2d558552eb5c835f12e77ed0df03e793b1 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 16 Sep 2019 10:02:40 -0700 Subject: [PATCH 656/663] chore: update renovate.json config from templates (#20) --- renovate.json | 26 ++++++++++++++------------ synth.metadata | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/renovate.json b/renovate.json index e3e4334dae..dae8a245c8 100644 --- a/renovate.json +++ b/renovate.json @@ -2,17 +2,18 @@ "extends": [ "config:base" ], - "ignoreDeps": [ - "com.google.api:gax-bom", - "com.google.guava:guava", - "com.google.guava:guava-testlib", - "com.google.protobuf:protobuf-java", - "com.google.protobuf:protobuf-java-util", - "io.opencensus:opencensus-api", - "io.opencensus:opencensus-contrib-grpc-util", - "io.opencensus:opencensus-contrib-http-util" - ], + "ignoreDeps": [], "packageRules": [ + { + "packagePatterns": ["*"], + "semanticCommitType": "chore" + }, + { + "depTypeList": [ + "dependencies" + ], + "semanticCommitType": "deps" + }, { "packagePatterns": ["^io.grpc:grpc-"], "groupName": "gRPC packages" @@ -25,5 +26,6 @@ "packagePatterns": ["^io.opencensus:opencensus-"], "groupName": "OpenCensus packages" } - ] -} \ No newline at end of file + ], + "semanticCommits": true +} diff --git a/synth.metadata b/synth.metadata index 3396e2f5a6..413f229e7d 100644 --- a/synth.metadata +++ b/synth.metadata @@ -1,5 +1,5 @@ { - "updateTime": "2019-09-10T08:05:23.089681Z", + "updateTime": "2019-09-12T08:11:37.122796Z", "sources": [ { "template": { From 4b21afa3641300c315b58af26366d35c6f6f82bb Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 16 Sep 2019 20:32:33 +0300 Subject: [PATCH 657/663] deps: update opencensus packages to v0.24.0 (#22) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e93dc1ac11..6cb5e2af4f 100644 --- a/pom.xml +++ b/pom.xml @@ -161,7 +161,7 @@ 1.31.0 1.23.0 3.9.1 - 0.23.0 + 0.24.0 1.3.2 28.0-android 4.12 From 0e44d6f828dd3bd5f5f2957e9f41bd0d3a8e938d Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 16 Sep 2019 20:55:01 +0300 Subject: [PATCH 658/663] chore(deps): update dependency com.google.http-client:google-http-client-bom to v1.32.0 (#19) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6cb5e2af4f..fb95d7890b 100644 --- a/pom.xml +++ b/pom.xml @@ -158,7 +158,7 @@ 0.12.0 0.17.1 1.30.2 - 1.31.0 + 1.32.0 1.23.0 3.9.1 0.24.0 From fcd67f819638ca445d7666b6232b4941ee601ff0 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 16 Sep 2019 21:34:39 +0300 Subject: [PATCH 659/663] deps: update dependency com.google.api-client:google-api-client-bom to v1.30.3 (#21) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fb95d7890b..ba12272f60 100644 --- a/pom.xml +++ b/pom.xml @@ -157,7 +157,7 @@ 1.16.0 0.12.0 0.17.1 - 1.30.2 + 1.30.3 1.32.0 1.23.0 3.9.1 From 2050aedc75019a256020aadbffab6bf35cf9b519 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 17 Sep 2019 16:46:07 -0700 Subject: [PATCH 660/663] build: enable release-please bot (#23) --- .github/.release-please.yml | 1 + synth.metadata | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .github/.release-please.yml diff --git a/.github/.release-please.yml b/.github/.release-please.yml new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/.github/.release-please.yml @@ -0,0 +1 @@ + diff --git a/synth.metadata b/synth.metadata index 413f229e7d..4d753071d0 100644 --- a/synth.metadata +++ b/synth.metadata @@ -1,5 +1,5 @@ { - "updateTime": "2019-09-12T08:11:37.122796Z", + "updateTime": "2019-09-17T08:01:41.230045Z", "sources": [ { "template": { From 596031009fc4d658e34e3561ad2225a8b440a216 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 19 Sep 2019 01:47:11 +0300 Subject: [PATCH 661/663] chore(deps): update dependency com.google.cloud:google-cloud-shared-config to v0.1.2 (#24) --- google-cloud-core-bom/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-core-bom/pom.xml b/google-cloud-core-bom/pom.xml index 173f4008f7..1f7aad66cb 100644 --- a/google-cloud-core-bom/pom.xml +++ b/google-cloud-core-bom/pom.xml @@ -8,7 +8,7 @@ com.google.cloud google-cloud-shared-config - 0.1.1 + 0.1.2 Google Cloud Core diff --git a/pom.xml b/pom.xml index ba12272f60..5281433d12 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.google.cloud google-cloud-shared-config - 0.1.1 + 0.1.2 From 061706db58b9cbb12fcae0e2c71691507b177b03 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 18 Sep 2019 16:15:34 -0700 Subject: [PATCH 662/663] build: enable release-please bot --- .github/{.release-please.yml => release-please.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{.release-please.yml => release-please.yml} (100%) diff --git a/.github/.release-please.yml b/.github/release-please.yml similarity index 100% rename from .github/.release-please.yml rename to .github/release-please.yml From 1bb69517527b784749b4ef17fe29ad25450ce58d Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2019 16:32:13 -0700 Subject: [PATCH 663/663] chore: release 1.91.0 (#25) * created CHANGELOG.md [ci skip] * updated README.md [ci skip] * updated versions.txt [ci skip] * updated google-cloud-core-grpc/pom.xml [ci skip] * updated google-cloud-core-http/pom.xml [ci skip] * updated google-cloud-core/pom.xml [ci skip] * updated google-cloud-core-bom/pom.xml [ci skip] * updated pom.xml [ci skip] --- CHANGELOG.md | 21 +++++++++++++++++++++ google-cloud-core-bom/pom.xml | 8 ++++---- google-cloud-core-grpc/pom.xml | 4 ++-- google-cloud-core-http/pom.xml | 4 ++-- google-cloud-core/pom.xml | 4 ++-- pom.xml | 2 +- versions.txt | 2 +- 7 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000..d622ee88bd --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,21 @@ +# Changelog + +## [1.91.0](https://www.github.com/googleapis/java-core/compare/v1.90.0...v1.91.0) (2019-09-18) + + +### Dependencies + +* update dependency com.google.api-client:google-api-client-bom to v1.30.3 ([#21](https://www.github.com/googleapis/java-core/issues/21)) ([fcd67f8](https://www.github.com/googleapis/java-core/commit/fcd67f8)) +* update opencensus packages to v0.24.0 ([#22](https://www.github.com/googleapis/java-core/issues/22)) ([4b21afa](https://www.github.com/googleapis/java-core/commit/4b21afa)) + + +### Documentation + +* fix Kokoro badge link ([19d79d6](https://www.github.com/googleapis/java-core/commit/19d79d6)) +* fix README versions and CI Status table ([6e3ccf3](https://www.github.com/googleapis/java-core/commit/6e3ccf3)) +* update README with a better project description ([#17](https://www.github.com/googleapis/java-core/issues/17)) ([018d4d5](https://www.github.com/googleapis/java-core/commit/018d4d5)) + + +### Features + +* add google-cloud-core-bom artifact ([#13](https://www.github.com/googleapis/java-core/issues/13)) ([3cb19a0](https://www.github.com/googleapis/java-core/commit/3cb19a0)) diff --git a/google-cloud-core-bom/pom.xml b/google-cloud-core-bom/pom.xml index 1f7aad66cb..b5514736f7 100644 --- a/google-cloud-core-bom/pom.xml +++ b/google-cloud-core-bom/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-core-bom - 1.90.1-SNAPSHOT + 1.91.0 pom com.google.cloud @@ -63,17 +63,17 @@ com.google.cloud google-cloud-core - 1.90.1-SNAPSHOT + 1.91.0 com.google.cloud google-cloud-core-grpc - 1.90.1-SNAPSHOT + 1.91.0 com.google.cloud google-cloud-core-http - 1.90.1-SNAPSHOT + 1.91.0 diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 0a6ff007e6..c592d4720c 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-core-grpc - 1.90.1-SNAPSHOT + 1.91.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -13,7 +13,7 @@ com.google.cloud google-cloud-core-parent - 1.90.1-SNAPSHOT + 1.91.0 google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index cdfaf99fac..9740de7202 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-core-http - 1.90.1-SNAPSHOT + 1.91.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -13,7 +13,7 @@ com.google.cloud google-cloud-core-parent - 1.90.1-SNAPSHOT + 1.91.0 google-cloud-core-http diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index df8b1b364d..97737acf41 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-core - 1.90.1-SNAPSHOT + 1.91.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -13,7 +13,7 @@ com.google.cloud google-cloud-core-parent - 1.90.1-SNAPSHOT + 1.91.0 google-cloud-core diff --git a/pom.xml b/pom.xml index 5281433d12..116100ab60 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-core-parent pom - 1.90.1-SNAPSHOT + 1.91.0 Google Cloud Core Parent https://github.com/googleapis/java-core diff --git a/versions.txt b/versions.txt index c7eb90abbb..a4990a4eb7 100644 --- a/versions.txt +++ b/versions.txt @@ -1,4 +1,4 @@ # Format: # module:released-version:current-version -google-cloud-core:1.90.0:1.90.1-SNAPSHOT \ No newline at end of file +google-cloud-core:1.91.0:1.91.0 \ No newline at end of file