Skip to content

Commit b2814a2

Browse files
authored
Feat: Add universe domain (#3090)
* Universe domain feat * Feat: Add universe domain feat * Feat: Add universe domain feat * Feat: Add universe domain feat
1 parent eb773b9 commit b2814a2

File tree

2 files changed

+177
-2
lines changed

2 files changed

+177
-2
lines changed

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java

+43-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public HttpBigQueryRpc(BigQueryOptions options) {
105105
this.options = options;
106106
bigquery =
107107
new Bigquery.Builder(transport, new GsonFactory(), initializer)
108-
.setRootUrl(options.getHost())
108+
.setRootUrl(options.getResolvedApiaryHost("bigquery"))
109109
.setApplicationName(options.getApplicationName())
110110
.build();
111111
}
@@ -114,9 +114,16 @@ private static BigQueryException translate(IOException exception) {
114114
return new BigQueryException(exception);
115115
}
116116

117+
private void validateRPC() throws BigQueryException, IOException {
118+
if (!this.options.hasValidUniverseDomain()) {
119+
throw new BigQueryException(BigQueryException.UNKNOWN_CODE, "Invalid universe domain");
120+
}
121+
}
122+
117123
@Override
118124
public Dataset getDataset(String projectId, String datasetId, Map<Option, ?> options) {
119125
try {
126+
validateRPC();
120127
return bigquery
121128
.datasets()
122129
.get(projectId, datasetId)
@@ -135,6 +142,7 @@ public Dataset getDataset(String projectId, String datasetId, Map<Option, ?> opt
135142
@Override
136143
public Tuple<String, Iterable<Dataset>> listDatasets(String projectId, Map<Option, ?> options) {
137144
try {
145+
validateRPC();
138146
DatasetList datasetsList =
139147
bigquery
140148
.datasets()
@@ -159,6 +167,7 @@ public Tuple<String, Iterable<Dataset>> listDatasets(String projectId, Map<Optio
159167
@Override
160168
public Dataset create(Dataset dataset, Map<Option, ?> options) {
161169
try {
170+
validateRPC();
162171
return bigquery
163172
.datasets()
164173
.insert(dataset.getDatasetReference().getProjectId(), dataset)
@@ -173,6 +182,7 @@ public Dataset create(Dataset dataset, Map<Option, ?> options) {
173182
@Override
174183
public Table create(Table table, Map<Option, ?> options) {
175184
try {
185+
validateRPC();
176186
// unset the type, as it is output only
177187
table.setType(null);
178188
TableReference reference = table.getTableReference();
@@ -190,6 +200,7 @@ public Table create(Table table, Map<Option, ?> options) {
190200
@Override
191201
public Routine create(Routine routine, Map<Option, ?> options) {
192202
try {
203+
validateRPC();
193204
RoutineReference reference = routine.getRoutineReference();
194205
return bigquery
195206
.routines()
@@ -205,6 +216,7 @@ public Routine create(Routine routine, Map<Option, ?> options) {
205216
@Override
206217
public Job create(Job job, Map<Option, ?> options) {
207218
try {
219+
validateRPC();
208220
String projectId =
209221
job.getJobReference() != null
210222
? job.getJobReference().getProjectId()
@@ -223,6 +235,7 @@ public Job create(Job job, Map<Option, ?> options) {
223235
@Override
224236
public Job createJobForQuery(Job job) {
225237
try {
238+
validateRPC();
226239
String projectId =
227240
job.getJobReference() != null
228241
? job.getJobReference().getProjectId()
@@ -236,6 +249,7 @@ public Job createJobForQuery(Job job) {
236249
@Override
237250
public boolean deleteDataset(String projectId, String datasetId, Map<Option, ?> options) {
238251
try {
252+
validateRPC();
239253
bigquery
240254
.datasets()
241255
.delete(projectId, datasetId)
@@ -255,6 +269,7 @@ public boolean deleteDataset(String projectId, String datasetId, Map<Option, ?>
255269
@Override
256270
public Dataset patch(Dataset dataset, Map<Option, ?> options) {
257271
try {
272+
validateRPC();
258273
DatasetReference reference = dataset.getDatasetReference();
259274
return bigquery
260275
.datasets()
@@ -270,6 +285,7 @@ public Dataset patch(Dataset dataset, Map<Option, ?> options) {
270285
@Override
271286
public Table patch(Table table, Map<Option, ?> options) {
272287
try {
288+
validateRPC();
273289
// unset the type, as it is output only
274290
table.setType(null);
275291
TableReference reference = table.getTableReference();
@@ -289,6 +305,7 @@ public Table patch(Table table, Map<Option, ?> options) {
289305
public Table getTable(
290306
String projectId, String datasetId, String tableId, Map<Option, ?> options) {
291307
try {
308+
validateRPC();
292309
return bigquery
293310
.tables()
294311
.get(projectId, datasetId, tableId)
@@ -316,6 +333,7 @@ private String getTableMetadataOption(Map<Option, ?> options) {
316333
public Tuple<String, Iterable<Table>> listTables(
317334
String projectId, String datasetId, Map<Option, ?> options) {
318335
try {
336+
validateRPC();
319337
TableList tableList =
320338
bigquery
321339
.tables()
@@ -351,6 +369,7 @@ public Table apply(TableList.Tables tablePb) {
351369
@Override
352370
public boolean deleteTable(String projectId, String datasetId, String tableId) {
353371
try {
372+
validateRPC();
354373
bigquery.tables().delete(projectId, datasetId, tableId).execute();
355374
return true;
356375
} catch (IOException ex) {
@@ -365,6 +384,7 @@ public boolean deleteTable(String projectId, String datasetId, String tableId) {
365384
@Override
366385
public Model patch(Model model, Map<Option, ?> options) {
367386
try {
387+
validateRPC();
368388
// unset the type, as it is output only
369389
ModelReference reference = model.getModelReference();
370390
return bigquery
@@ -382,6 +402,7 @@ public Model patch(Model model, Map<Option, ?> options) {
382402
public Model getModel(
383403
String projectId, String datasetId, String modelId, Map<Option, ?> options) {
384404
try {
405+
validateRPC();
385406
return bigquery
386407
.models()
387408
.get(projectId, datasetId, modelId)
@@ -401,6 +422,7 @@ public Model getModel(
401422
public Tuple<String, Iterable<Model>> listModels(
402423
String projectId, String datasetId, Map<Option, ?> options) {
403424
try {
425+
validateRPC();
404426
ListModelsResponse modelList =
405427
bigquery
406428
.models()
@@ -420,6 +442,7 @@ public Tuple<String, Iterable<Model>> listModels(
420442
@Override
421443
public boolean deleteModel(String projectId, String datasetId, String modelId) {
422444
try {
445+
validateRPC();
423446
bigquery.models().delete(projectId, datasetId, modelId).execute();
424447
return true;
425448
} catch (IOException ex) {
@@ -434,6 +457,7 @@ public boolean deleteModel(String projectId, String datasetId, String modelId) {
434457
@Override
435458
public Routine update(Routine routine, Map<Option, ?> options) {
436459
try {
460+
validateRPC();
437461
RoutineReference reference = routine.getRoutineReference();
438462
return bigquery
439463
.routines()
@@ -451,6 +475,7 @@ public Routine update(Routine routine, Map<Option, ?> options) {
451475
public Routine getRoutine(
452476
String projectId, String datasetId, String routineId, Map<Option, ?> options) {
453477
try {
478+
validateRPC();
454479
return bigquery
455480
.routines()
456481
.get(projectId, datasetId, routineId)
@@ -470,6 +495,7 @@ public Routine getRoutine(
470495
public Tuple<String, Iterable<Routine>> listRoutines(
471496
String projectId, String datasetId, Map<Option, ?> options) {
472497
try {
498+
validateRPC();
473499
ListRoutinesResponse routineList =
474500
bigquery
475501
.routines()
@@ -491,6 +517,7 @@ public Tuple<String, Iterable<Routine>> listRoutines(
491517
@Override
492518
public boolean deleteRoutine(String projectId, String datasetId, String routineId) {
493519
try {
520+
validateRPC();
494521
bigquery.routines().delete(projectId, datasetId, routineId).execute();
495522
return true;
496523
} catch (IOException ex) {
@@ -506,6 +533,7 @@ public boolean deleteRoutine(String projectId, String datasetId, String routineI
506533
public TableDataInsertAllResponse insertAll(
507534
String projectId, String datasetId, String tableId, TableDataInsertAllRequest request) {
508535
try {
536+
validateRPC();
509537
return bigquery
510538
.tabledata()
511539
.insertAll(projectId, datasetId, tableId, request)
@@ -520,6 +548,7 @@ public TableDataInsertAllResponse insertAll(
520548
public TableDataList listTableData(
521549
String projectId, String datasetId, String tableId, Map<Option, ?> options) {
522550
try {
551+
validateRPC();
523552
return bigquery
524553
.tabledata()
525554
.list(projectId, datasetId, tableId)
@@ -544,6 +573,7 @@ public TableDataList listTableDataWithRowLimit(
544573
Integer maxResultPerPage,
545574
String pageToken) {
546575
try {
576+
validateRPC();
547577
return bigquery
548578
.tabledata()
549579
.list(projectId, datasetId, tableId)
@@ -559,6 +589,7 @@ public TableDataList listTableDataWithRowLimit(
559589
@Override
560590
public Job getJob(String projectId, String jobId, String location, Map<Option, ?> options) {
561591
try {
592+
validateRPC();
562593
return bigquery
563594
.jobs()
564595
.get(projectId, jobId)
@@ -578,6 +609,7 @@ public Job getJob(String projectId, String jobId, String location, Map<Option, ?
578609
@Override
579610
public Job getQueryJob(String projectId, String jobId, String location) {
580611
try {
612+
validateRPC();
581613
return bigquery
582614
.jobs()
583615
.get(projectId, jobId)
@@ -596,6 +628,7 @@ public Job getQueryJob(String projectId, String jobId, String location) {
596628
@Override
597629
public Tuple<String, Iterable<Job>> listJobs(String projectId, Map<Option, ?> options) {
598630
try {
631+
validateRPC();
599632
Bigquery.Jobs.List request =
600633
bigquery
601634
.jobs()
@@ -650,6 +683,7 @@ public Job apply(JobList.Jobs jobPb) {
650683
@Override
651684
public boolean cancel(String projectId, String jobId, String location) {
652685
try {
686+
validateRPC();
653687
bigquery
654688
.jobs()
655689
.cancel(projectId, jobId)
@@ -669,6 +703,7 @@ public boolean cancel(String projectId, String jobId, String location) {
669703
@Override
670704
public boolean deleteJob(String projectId, String jobName, String location) {
671705
try {
706+
validateRPC();
672707
bigquery
673708
.jobs()
674709
.delete(projectId, jobName)
@@ -685,6 +720,7 @@ public boolean deleteJob(String projectId, String jobName, String location) {
685720
public GetQueryResultsResponse getQueryResults(
686721
String projectId, String jobId, String location, Map<Option, ?> options) {
687722
try {
723+
validateRPC();
688724
return bigquery
689725
.jobs()
690726
.getQueryResults(projectId, jobId)
@@ -707,6 +743,7 @@ public GetQueryResultsResponse getQueryResults(
707743
public GetQueryResultsResponse getQueryResultsWithRowLimit(
708744
String projectId, String jobId, String location, Integer maxResultPerPage, Long timeoutMs) {
709745
try {
746+
validateRPC();
710747
return bigquery
711748
.jobs()
712749
.getQueryResults(projectId, jobId)
@@ -723,6 +760,7 @@ public GetQueryResultsResponse getQueryResultsWithRowLimit(
723760
@Override
724761
public QueryResponse queryRpc(String projectId, QueryRequest content) {
725762
try {
763+
validateRPC();
726764
return bigquery.jobs().query(projectId, content).execute();
727765
} catch (IOException ex) {
728766
throw translate(ex);
@@ -732,7 +770,7 @@ public QueryResponse queryRpc(String projectId, QueryRequest content) {
732770
@Override
733771
public String open(Job loadJob) {
734772
try {
735-
String builder = options.getHost();
773+
String builder = options.getResolvedApiaryHost("bigquery");
736774
if (!builder.endsWith("/")) {
737775
builder += "/";
738776
}
@@ -807,6 +845,7 @@ public Job write(
807845
@Override
808846
public Policy getIamPolicy(String resourceId, Map<Option, ?> options) {
809847
try {
848+
validateRPC();
810849
GetIamPolicyRequest policyRequest = new GetIamPolicyRequest();
811850
if (null != Option.REQUESTED_POLICY_VERSION.getLong(options)) {
812851
policyRequest =
@@ -828,6 +867,7 @@ public Policy getIamPolicy(String resourceId, Map<Option, ?> options) {
828867
@Override
829868
public Policy setIamPolicy(String resourceId, Policy policy, Map<Option, ?> options) {
830869
try {
870+
validateRPC();
831871
SetIamPolicyRequest policyRequest = new SetIamPolicyRequest().setPolicy(policy);
832872
return bigquery
833873
.tables()
@@ -843,6 +883,7 @@ public Policy setIamPolicy(String resourceId, Policy policy, Map<Option, ?> opti
843883
public TestIamPermissionsResponse testIamPermissions(
844884
String resourceId, List<String> permissions, Map<Option, ?> options) {
845885
try {
886+
validateRPC();
846887
TestIamPermissionsRequest permissionsRequest =
847888
new TestIamPermissionsRequest().setPermissions(permissions);
848889
return bigquery

0 commit comments

Comments
 (0)