1+ /*
2+ * Copyright © 2025 Cask Data, Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+ * use this file except in compliance with the License. You may obtain a copy of
6+ * the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+ * License for the specific language governing permissions and limitations under
14+ * the License.
15+ */
16+ package io .cdap .cdap .metadata .spanner ;
17+
18+ import com .google .cloud .spanner .DatabaseAdminClient ;
19+ import com .google .cloud .spanner .DatabaseClient ;
20+ import com .google .cloud .spanner .DatabaseId ;
21+ import com .google .cloud .spanner .Spanner ;
22+ import java .util .Map ;
23+
24+ /**
25+ * Utility class for spanner metadata storage.
26+ */
27+ class SpannerConfig {
28+
29+ static final String PROJECT = "project" ;
30+ static final String INSTANCE = "instance" ;
31+ static final String DATABASE = "database" ;
32+
33+ static DatabaseClient getSpannerDbClient (String projectID , String instanceID , String databaseID , Spanner spanner ) {
34+ DatabaseId db = DatabaseId .of (projectID , instanceID , databaseID );
35+ return spanner .getDatabaseClient (db );
36+ }
37+
38+ static DatabaseAdminClient getSpannerDbAdminClient (Spanner spanner ) {
39+ return spanner .getDatabaseAdminClient ();
40+ }
41+
42+ static String getInstanceID (Map <String , String > cConf ) {
43+ String instance = cConf .get (INSTANCE );
44+ if (instance == null ) {
45+ throw new IllegalArgumentException ("Missing configuration " + PROJECT );
46+ }
47+ return instance ;
48+ }
49+
50+ static String getDatabaseID (Map <String , String > cConf ) {
51+ String instance = cConf .get (DATABASE );
52+ if (instance == null ) {
53+ throw new IllegalArgumentException ("Missing configuration " + DATABASE );
54+ }
55+ return cConf .get (DATABASE );
56+ }
57+
58+ static String getProjectID (Map <String , String > cConf ) {
59+ String instance = cConf .get (PROJECT );
60+ if (instance == null ) {
61+ throw new IllegalArgumentException ("Missing configuration " + PROJECT );
62+ }
63+ return cConf .get (PROJECT );
64+ }
65+ }
0 commit comments