Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit de5bc13

Browse files
Regenerating longrunning, updating status codes, other cleanup (#399)
1 parent 3bf9c42 commit de5bc13

8 files changed

Lines changed: 85 additions & 92 deletions

File tree

gax-grpc/src/main/java/com/google/longrunning/OperationsClient.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@
8686
* these names, this class includes a format method for each type of name, and additionally a parse
8787
* method to extract the individual identifiers contained within names that are returned.
8888
*
89-
* <p>This class can be customized by passing in a custom instance of OperationsSettings to {@link
90-
* #of(OperationsSettings)}. For example:
89+
* <p>This class can be customized by passing in a custom instance of OperationsSettings to of().
90+
* For example:
91+
*
92+
* <p>To customize credentials:
9193
*
9294
* <pre>
9395
* <code>
@@ -110,7 +112,7 @@ public class OperationsClient implements BackgroundResource {
110112
* Constructs an instance of OperationsClient, using the given settings. The channels are created
111113
* based on the settings passed in, or defaults for any settings that are not set.
112114
*
113-
* @deprecated Use {@link #of(OperationsSettings)} instead.
115+
* @deprecated Use of(OperationsSettings) instead.
114116
*/
115117
@Deprecated
116118
public static final OperationsClient create(OperationsSettings settings) throws IOException {
@@ -121,7 +123,7 @@ public static final OperationsClient create(OperationsSettings settings) throws
121123
* Constructs an instance of OperationsClient, using the given stub for making calls. This is for
122124
* advanced usage - prefer to use OperationsSettings}.
123125
*
124-
* @deprecated Use {@link #of(OperationsStub)} instead.
126+
* @deprecated Use of(OperationsStub) instead.
125127
*/
126128
@Deprecated
127129
public static final OperationsClient create(OperationsStub stub) {
@@ -147,7 +149,7 @@ public static final OperationsClient of(OperationsStub stub) {
147149

148150
/**
149151
* Constructs an instance of OperationsClient, using the given settings. This is protected so that
150-
* it easy to make a subclass, but otherwise, the static factory methods should be preferred.
152+
* it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
151153
*/
152154
protected OperationsClient(OperationsSettings settings) throws IOException {
153155
this.settings = settings;
@@ -163,6 +165,7 @@ public final OperationsSettings getSettings() {
163165
return settings;
164166
}
165167

168+
@BetaApi
166169
public OperationsStub getStub() {
167170
return stub;
168171
}

gax-grpc/src/main/java/com/google/longrunning/OperationsSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static Builder defaultBuilder() {
154154
}
155155

156156
/**
157-
* Returns a builder for this class with recommened defaults for API methods, and the given
157+
* Returns a builder for this class with recommended defaults for API methods, and the given
158158
* ClientContext used for executor/transport/credentials.
159159
*/
160160
@Deprecated

gax-grpc/src/main/java/com/google/longrunning/stub/GrpcOperationsStub.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
import javax.annotation.Generated;
5454

5555
// AUTO-GENERATED DOCUMENTATION AND CLASS
56+
/**
57+
* gRPC stub implementation for Google Long Running Operations API.
58+
*
59+
* <p>This class is for advanced usage and reflects the underlying API directly.
60+
*/
5661
@Generated("by GAPIC v0.0.5")
5762
@BetaApi
5863
public class GrpcOperationsStub extends OperationsStub {
@@ -93,6 +98,7 @@ public class GrpcOperationsStub extends OperationsStub {
9398
ProtoUtils.marshaller(DeleteOperationRequest.getDefaultInstance()))
9499
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
95100
.build();
101+
96102
private final BackgroundResource backgroundResources;
97103

98104
private final UnaryCallable<GetOperationRequest, Operation> getOperationCallable;
@@ -102,13 +108,13 @@ public class GrpcOperationsStub extends OperationsStub {
102108
private final UnaryCallable<CancelOperationRequest, Empty> cancelOperationCallable;
103109
private final UnaryCallable<DeleteOperationRequest, Empty> deleteOperationCallable;
104110

105-
/** @deprecated Use {@link #of(OperationsSettings)} instead. */
111+
/** @deprecated Use of(OperationsSettings) instead. */
106112
@Deprecated
107113
public static final GrpcOperationsStub create(OperationsSettings settings) throws IOException {
108114
return of(settings);
109115
}
110116

111-
/** @deprecated Use {@link #of(ClientContext)} instead. */
117+
/** @deprecated Use of(ClientContext) instead. */
112118
@Deprecated
113119
public static final GrpcOperationsStub create(ClientContext clientContext) throws IOException {
114120
return of(clientContext);
@@ -124,42 +130,45 @@ public static final GrpcOperationsStub of(ClientContext clientContext) throws IO
124130

125131
/**
126132
* Constructs an instance of GrpcOperationsStub, using the given settings. This is protected so
127-
* that it easy to make a subclass, but otherwise, the static factory methods should be preferred.
133+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
134+
* preferred.
128135
*/
129136
protected GrpcOperationsStub(OperationsSettings settings, ClientContext clientContext)
130137
throws IOException {
131138

132-
GrpcCallSettings<GetOperationRequest, Operation> getOperationGrpcSettings =
139+
GrpcCallSettings<GetOperationRequest, Operation> getOperationTransportSettings =
133140
GrpcCallSettings.<GetOperationRequest, Operation>newBuilder()
134141
.setMethodDescriptor(getOperationMethodDescriptor)
135142
.build();
143+
GrpcCallSettings<ListOperationsRequest, ListOperationsResponse>
144+
listOperationsTransportSettings =
145+
GrpcCallSettings.<ListOperationsRequest, ListOperationsResponse>newBuilder()
146+
.setMethodDescriptor(listOperationsMethodDescriptor)
147+
.build();
148+
GrpcCallSettings<CancelOperationRequest, Empty> cancelOperationTransportSettings =
149+
GrpcCallSettings.<CancelOperationRequest, Empty>newBuilder()
150+
.setMethodDescriptor(cancelOperationMethodDescriptor)
151+
.build();
152+
GrpcCallSettings<DeleteOperationRequest, Empty> deleteOperationTransportSettings =
153+
GrpcCallSettings.<DeleteOperationRequest, Empty>newBuilder()
154+
.setMethodDescriptor(deleteOperationMethodDescriptor)
155+
.build();
156+
136157
this.getOperationCallable =
137158
GrpcCallableFactory.createUnaryCallable(
138-
getOperationGrpcSettings, settings.getOperationSettings(), clientContext);
139-
GrpcCallSettings<ListOperationsRequest, ListOperationsResponse> listOperationsGrpcSettings =
140-
GrpcCallSettings.<ListOperationsRequest, ListOperationsResponse>newBuilder()
141-
.setMethodDescriptor(listOperationsMethodDescriptor)
142-
.build();
159+
getOperationTransportSettings, settings.getOperationSettings(), clientContext);
143160
this.listOperationsCallable =
144161
GrpcCallableFactory.createUnaryCallable(
145-
listOperationsGrpcSettings, settings.listOperationsSettings(), clientContext);
162+
listOperationsTransportSettings, settings.listOperationsSettings(), clientContext);
146163
this.listOperationsPagedCallable =
147164
GrpcCallableFactory.createPagedCallable(
148-
listOperationsGrpcSettings, settings.listOperationsSettings(), clientContext);
149-
GrpcCallSettings<CancelOperationRequest, Empty> cancelOperationGrpcSettings =
150-
GrpcCallSettings.<CancelOperationRequest, Empty>newBuilder()
151-
.setMethodDescriptor(cancelOperationMethodDescriptor)
152-
.build();
165+
listOperationsTransportSettings, settings.listOperationsSettings(), clientContext);
153166
this.cancelOperationCallable =
154167
GrpcCallableFactory.createUnaryCallable(
155-
cancelOperationGrpcSettings, settings.cancelOperationSettings(), clientContext);
156-
GrpcCallSettings<DeleteOperationRequest, Empty> deleteOperationGrpcSettings =
157-
GrpcCallSettings.<DeleteOperationRequest, Empty>newBuilder()
158-
.setMethodDescriptor(deleteOperationMethodDescriptor)
159-
.build();
168+
cancelOperationTransportSettings, settings.cancelOperationSettings(), clientContext);
160169
this.deleteOperationCallable =
161170
GrpcCallableFactory.createUnaryCallable(
162-
deleteOperationGrpcSettings, settings.deleteOperationSettings(), clientContext);
171+
deleteOperationTransportSettings, settings.deleteOperationSettings(), clientContext);
163172

164173
backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources());
165174
}
@@ -185,10 +194,6 @@ public UnaryCallable<DeleteOperationRequest, Empty> deleteOperationCallable() {
185194
return deleteOperationCallable;
186195
}
187196

188-
/**
189-
* Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
190-
* cancelled.
191-
*/
192197
@Override
193198
public final void close() throws Exception {
194199
shutdown();

gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStub.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
import javax.annotation.Generated;
4545

4646
// AUTO-GENERATED DOCUMENTATION AND CLASS
47+
/**
48+
* Base stub class for Google Long Running Operations API.
49+
*
50+
* <p>This class is for advanced usage and reflects the underlying API directly.
51+
*/
4752
@Generated("by GAPIC v0.0.5")
4853
@BetaApi
4954
public abstract class OperationsStub implements BackgroundResource {

gax-grpc/src/test/java/com/google/longrunning/OperationsClientTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void setUp() throws IOException {
7575
OperationsSettings settings =
7676
OperationsSettings.newBuilder()
7777
.setTransportChannelProvider(serviceHelper.createChannelProvider())
78-
.setCredentialsProvider(new NoCredentialsProvider())
78+
.setCredentialsProvider(NoCredentialsProvider.of())
7979
.build();
8080
client = OperationsClient.of(settings);
8181
}
@@ -117,7 +117,7 @@ public void getOperationExceptionTest() throws Exception {
117117
client.getOperation(name);
118118
Assert.fail("No exception raised");
119119
} catch (InvalidArgumentException e) {
120-
// expected
120+
// Expected exception
121121
}
122122
}
123123

@@ -164,7 +164,7 @@ public void listOperationsExceptionTest() throws Exception {
164164
client.listOperations(name, filter);
165165
Assert.fail("No exception raised");
166166
} catch (InvalidArgumentException e) {
167-
// expected
167+
// Expected exception
168168
}
169169
}
170170

@@ -197,7 +197,7 @@ public void cancelOperationExceptionTest() throws Exception {
197197
client.cancelOperation(name);
198198
Assert.fail("No exception raised");
199199
} catch (InvalidArgumentException e) {
200-
// expected
200+
// Expected exception
201201
}
202202
}
203203

@@ -230,7 +230,7 @@ public void deleteOperationExceptionTest() throws Exception {
230230
client.deleteOperation(name);
231231
Assert.fail("No exception raised");
232232
} catch (InvalidArgumentException e) {
233-
// expected
233+
// Expected exception
234234
}
235235
}
236236
}

gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonStatusCode.java

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static HttpJsonStatusCode of(int httpStatus, String errorMessage) {
5252
}
5353

5454
public static HttpJsonStatusCode of(StatusCode.Code statusCode) {
55-
return new HttpJsonStatusCode(statusCodeToHttpStatus(statusCode), statusCode);
55+
return new HttpJsonStatusCode(statusCode.getHttpStatusCode(), statusCode);
5656
}
5757

5858
static StatusCode.Code httpStatusToStatusCode(int httpStatus, String errorMessage) {
@@ -90,6 +90,8 @@ static StatusCode.Code httpStatusToStatusCode(int httpStatus, String errorMessag
9090
} else {
9191
return Code.INTERNAL;
9292
}
93+
case 501:
94+
return Code.UNIMPLEMENTED;
9395
case 503:
9496
return Code.UNAVAILABLE;
9597
case 504:
@@ -99,44 +101,6 @@ static StatusCode.Code httpStatusToStatusCode(int httpStatus, String errorMessag
99101
}
100102
}
101103

102-
static int statusCodeToHttpStatus(StatusCode.Code statusCode) {
103-
switch (statusCode) {
104-
case CANCELLED:
105-
return 499;
106-
case NOT_FOUND:
107-
return 404;
108-
case UNKNOWN:
109-
return 500;
110-
case INVALID_ARGUMENT:
111-
return 400;
112-
case DEADLINE_EXCEEDED:
113-
return 504;
114-
case ALREADY_EXISTS:
115-
return 409;
116-
case PERMISSION_DENIED:
117-
return 403;
118-
case RESOURCE_EXHAUSTED:
119-
return 429;
120-
case FAILED_PRECONDITION:
121-
return 400;
122-
case ABORTED:
123-
return 409;
124-
case OUT_OF_RANGE:
125-
return 400;
126-
case INTERNAL:
127-
return 500;
128-
case UNAVAILABLE:
129-
return 503;
130-
case DATA_LOSS:
131-
return 500;
132-
case UNAUTHENTICATED:
133-
return 401;
134-
135-
default:
136-
throw new IllegalArgumentException("Unrecognized status code: " + statusCode);
137-
}
138-
}
139-
140104
@Override
141105
public StatusCode.Code getCode() {
142106
return statusCode;

gax/src/main/java/com/google/api/gax/core/NoCredentialsProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@
3535
/** NoCredentialsProvider is a CredentialsProvider which always returns null. */
3636
@BetaApi
3737
public final class NoCredentialsProvider implements CredentialsProvider {
38+
@Deprecated
39+
public NoCredentialsProvider() {}
3840

3941
@Override
4042
public Credentials getCredentials() {
4143
return null;
4244
}
45+
46+
public static NoCredentialsProvider of() {
47+
return new NoCredentialsProvider();
48+
}
4349
}

gax/src/main/java/com/google/api/gax/rpc/StatusCode.java

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,33 @@
4242
public interface StatusCode {
4343

4444
enum Code {
45-
OK,
46-
CANCELLED,
47-
UNKNOWN,
48-
INVALID_ARGUMENT,
49-
DEADLINE_EXCEEDED,
50-
NOT_FOUND,
51-
ALREADY_EXISTS,
52-
PERMISSION_DENIED,
53-
RESOURCE_EXHAUSTED,
54-
FAILED_PRECONDITION,
55-
ABORTED,
56-
OUT_OF_RANGE,
57-
UNIMPLEMENTED,
58-
INTERNAL,
59-
UNAVAILABLE,
60-
DATA_LOSS,
61-
UNAUTHENTICATED;
45+
OK(200),
46+
CANCELLED(499),
47+
UNKNOWN(500),
48+
INVALID_ARGUMENT(400),
49+
DEADLINE_EXCEEDED(504),
50+
NOT_FOUND(404),
51+
ALREADY_EXISTS(409),
52+
PERMISSION_DENIED(403),
53+
RESOURCE_EXHAUSTED(429),
54+
FAILED_PRECONDITION(400),
55+
ABORTED(409),
56+
OUT_OF_RANGE(400),
57+
UNIMPLEMENTED(501),
58+
INTERNAL(500),
59+
UNAVAILABLE(503),
60+
DATA_LOSS(500),
61+
UNAUTHENTICATED(401);
62+
63+
Code(int httpStatusCode) {
64+
this.httpStatusCode = httpStatusCode;
65+
}
66+
67+
private int httpStatusCode;
68+
69+
public int getHttpStatusCode() {
70+
return httpStatusCode;
71+
}
6272
}
6373

6474
/** Return the code enum value. */

0 commit comments

Comments
 (0)