Skip to content

Commit 9ef2d81

Browse files
committed
[#5779] feat(core): Wildcard properties meta
1 parent c0bdd46 commit 9ef2d81

File tree

11 files changed

+796
-13
lines changed

11 files changed

+796
-13
lines changed

catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveCatalogPropertiesMeta.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public class HiveCatalogPropertiesMeta extends BaseCatalogPropertiesMetadata {
110110
DEFAULT_LIST_ALL_TABLES,
111111
false /* hidden */,
112112
false /* reserved */))
113-
.putAll(AuthorizationPropertiesMeta.RANGER_AUTHORIZATION_PROPERTY_ENTRIES)
113+
.putAll(AuthorizationPropertiesMeta.AUTHORIZATION_PROPERTY_ENTRIES)
114114
.putAll(CLIENT_PROPERTIES_METADATA.propertyEntries())
115115
.build();
116116

catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestHiveCatalogOperations.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void testPropertyMeta() {
7474
Map<String, PropertyEntry<?>> propertyEntryMap =
7575
HIVE_PROPERTIES_METADATA.catalogPropertiesMetadata().propertyEntries();
7676

77-
Assertions.assertEquals(21, propertyEntryMap.size());
77+
Assertions.assertEquals(29, propertyEntryMap.size());
7878
Assertions.assertTrue(propertyEntryMap.containsKey(METASTORE_URIS));
7979
Assertions.assertTrue(propertyEntryMap.containsKey(Catalog.PROPERTY_PACKAGE));
8080
Assertions.assertTrue(propertyEntryMap.containsKey(BaseCatalog.CATALOG_OPERATION_IMPL));
@@ -93,6 +93,24 @@ void testPropertyMeta() {
9393
propertyEntryMap.containsKey(AuthorizationPropertiesMeta.RANGER_PASSWORD));
9494
Assertions.assertTrue(
9595
propertyEntryMap.containsKey(AuthorizationPropertiesMeta.RANGER_SERVICE_NAME));
96+
Assertions.assertTrue(
97+
propertyEntryMap.containsKey(
98+
AuthorizationPropertiesMeta.getInstance().wildcardNodePropertyKey()));
99+
Assertions.assertTrue(
100+
propertyEntryMap.containsKey(AuthorizationPropertiesMeta.CHAIN_CATALOG_PROVIDER));
101+
Assertions.assertTrue(
102+
propertyEntryMap.containsKey(AuthorizationPropertiesMeta.CHAIN_CATALOG_PROVIDER));
103+
Assertions.assertTrue(propertyEntryMap.containsKey(AuthorizationPropertiesMeta.CHAIN_PROVIDER));
104+
Assertions.assertTrue(
105+
propertyEntryMap.containsKey(AuthorizationPropertiesMeta.CHAIN_RANGER_ADMIN_URL));
106+
Assertions.assertTrue(
107+
propertyEntryMap.containsKey(AuthorizationPropertiesMeta.CHAIN_RANGER_AUTH_TYPES));
108+
Assertions.assertTrue(
109+
propertyEntryMap.containsKey(AuthorizationPropertiesMeta.CHAIN_RANGER_USERNAME));
110+
Assertions.assertTrue(
111+
propertyEntryMap.containsKey(AuthorizationPropertiesMeta.CHAIN_RANGER_PASSWORD));
112+
Assertions.assertTrue(
113+
propertyEntryMap.containsKey(AuthorizationPropertiesMeta.CHAIN_RANGER_SERVICE_NAME));
96114

97115
Assertions.assertTrue(propertyEntryMap.get(METASTORE_URIS).isRequired());
98116
Assertions.assertFalse(propertyEntryMap.get(Catalog.PROPERTY_PACKAGE).isRequired());

core/src/main/java/org/apache/gravitino/catalog/PropertiesMetadataHelpers.java

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.stream.Collectors;
2727
import org.apache.gravitino.connector.PropertiesMetadata;
2828
import org.apache.gravitino.connector.PropertyEntry;
29+
import org.apache.gravitino.connector.WildcardPropertiesMeta;
2930

3031
/** This class contains helper methods for properties metadata. */
3132
public class PropertiesMetadataHelpers {
@@ -67,6 +68,8 @@ public static void validatePropertyForCreate(
6768
"Properties are required and must be set: %s",
6869
absentProperties);
6970

71+
WildcardPropertiesMeta.validate(propertiesMetadata, properties);
72+
7073
// use decode function to validate the property values
7174
for (Map.Entry<String, String> entry : properties.entrySet()) {
7275
String key = entry.getKey();

core/src/main/java/org/apache/gravitino/connector/AuthorizationPropertiesMeta.java

+168-7
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,166 @@
2121
import com.google.common.collect.ImmutableMap;
2222
import java.util.Map;
2323

24-
public class AuthorizationPropertiesMeta {
24+
public class AuthorizationPropertiesMeta extends BasePropertiesMetadata
25+
implements WildcardPropertiesMeta {
26+
private static volatile AuthorizationPropertiesMeta instance = null;
27+
28+
public static synchronized AuthorizationPropertiesMeta getInstance() {
29+
if (instance == null) {
30+
synchronized (AuthorizationPropertiesMeta.class) {
31+
if (instance == null) {
32+
instance = new AuthorizationPropertiesMeta();
33+
}
34+
}
35+
}
36+
return instance;
37+
}
38+
2539
/** Ranger admin web URIs */
26-
public static final String RANGER_ADMIN_URL = "authorization.ranger.admin.url";
40+
private static final String RANGER_ADMIN_URL_KEY = "ranger.admin.url";
41+
42+
public static final String getRangerAdminUrlKey() {
43+
return RANGER_ADMIN_URL_KEY;
44+
}
45+
46+
public static final String RANGER_ADMIN_URL =
47+
AuthorizationPropertiesMeta.getInstance().generateFirstNodePropertyKey(RANGER_ADMIN_URL_KEY);
2748
/** Ranger authentication type kerberos or simple */
28-
public static final String RANGER_AUTH_TYPE = "authorization.ranger.auth.type";
49+
private static final String RANGER_AUTH_TYPE_KEY = "ranger.auth.type";
50+
51+
public static final String getRangerAuthTypeKey() {
52+
return RANGER_AUTH_TYPE_KEY;
53+
}
54+
55+
public static final String RANGER_AUTH_TYPE =
56+
AuthorizationPropertiesMeta.getInstance().generateFirstNodePropertyKey(RANGER_AUTH_TYPE_KEY);
2957
/**
3058
* Ranger admin web login username(auth_type=simple), or kerberos principal(auth_type=kerberos)
3159
*/
32-
public static final String RANGER_USERNAME = "authorization.ranger.username";
60+
private static final String RANGER_USERNAME_KEY = "ranger.username";
61+
62+
public static final String getRangerUsernameKey() {
63+
return RANGER_USERNAME_KEY;
64+
}
65+
66+
public static final String RANGER_USERNAME =
67+
AuthorizationPropertiesMeta.getInstance().generateFirstNodePropertyKey(RANGER_USERNAME_KEY);
3368
/**
3469
* Ranger admin web login user password(auth_type=simple), or path of the keytab
3570
* file(auth_type=kerberos)
3671
*/
37-
public static final String RANGER_PASSWORD = "authorization.ranger.password";
72+
private static final String RANGER_PASSWORD_KEY = "ranger.password";
73+
74+
public static final String getRangerPasswordKey() {
75+
return RANGER_PASSWORD_KEY;
76+
}
77+
78+
public static final String RANGER_PASSWORD =
79+
AuthorizationPropertiesMeta.getInstance().generateFirstNodePropertyKey(RANGER_PASSWORD_KEY);
80+
3881
/** Ranger service name */
39-
public static final String RANGER_SERVICE_NAME = "authorization.ranger.service.name";
82+
private static final String RANGER_SERVICE_NAME_KEY = "ranger.service.name";
83+
84+
public static final String getRangerServiceNameKey() {
85+
return RANGER_SERVICE_NAME_KEY;
86+
}
87+
88+
public static final String RANGER_SERVICE_NAME =
89+
AuthorizationPropertiesMeta.getInstance()
90+
.generateFirstNodePropertyKey(RANGER_SERVICE_NAME_KEY);
91+
92+
/** Chain authorization plugin provider */
93+
private static final String CHAIN_CATALOG_PROVIDER_KEY = "catalog-provider";
94+
95+
public static final String getChainCatalogProviderKey() {
96+
return CHAIN_CATALOG_PROVIDER_KEY;
97+
}
98+
99+
public static final String CHAIN_CATALOG_PROVIDER =
100+
AuthorizationPropertiesMeta.getInstance()
101+
.getPropertyValue(Constants.WILDCARD, CHAIN_CATALOG_PROVIDER_KEY);
102+
103+
/** Chain authorization plugin provider */
104+
private static final String CHAIN_PROVIDER_KEY = "provider";
40105

41-
public static final Map<String, PropertyEntry<?>> RANGER_AUTHORIZATION_PROPERTY_ENTRIES =
106+
public static final String getChainProviderKey() {
107+
return CHAIN_PROVIDER_KEY;
108+
}
109+
110+
public static final String CHAIN_PROVIDER =
111+
AuthorizationPropertiesMeta.getInstance()
112+
.getPropertyValue(Constants.WILDCARD, CHAIN_PROVIDER_KEY);
113+
/** Chain authorization Ranger admin web URIs */
114+
public static final String CHAIN_RANGER_ADMIN_URL =
115+
AuthorizationPropertiesMeta.getInstance()
116+
.getPropertyValue(Constants.WILDCARD, RANGER_ADMIN_URL_KEY);
117+
/** Chain authorization Ranger authentication type kerberos or simple */
118+
public static final String CHAIN_RANGER_AUTH_TYPES =
119+
AuthorizationPropertiesMeta.getInstance()
120+
.getPropertyValue(Constants.WILDCARD, RANGER_AUTH_TYPE_KEY);
121+
/** Chain authorization Ranger username */
122+
public static final String CHAIN_RANGER_USERNAME =
123+
AuthorizationPropertiesMeta.getInstance()
124+
.getPropertyValue(Constants.WILDCARD, RANGER_USERNAME_KEY);
125+
/**
126+
* Chain authorization Ranger admin web login user password(auth_type=simple), or path of the
127+
* keytab file(auth_type=kerberos)
128+
*/
129+
public static final String CHAIN_RANGER_PASSWORD =
130+
AuthorizationPropertiesMeta.getInstance()
131+
.getPropertyValue(Constants.WILDCARD, RANGER_PASSWORD_KEY);
132+
/** Chain authorization Ranger service name */
133+
public static final String CHAIN_RANGER_SERVICE_NAME =
134+
AuthorizationPropertiesMeta.getInstance()
135+
.getPropertyValue(Constants.WILDCARD, RANGER_SERVICE_NAME_KEY);
136+
137+
public static String chainKeyToPluginKey(String chainKey, String plugin) {
138+
return chainKey.replace(
139+
String.format(
140+
"%s.%s", AuthorizationPropertiesMeta.getInstance().wildcardNodePropertyKey(), plugin),
141+
AuthorizationPropertiesMeta.getInstance().firstNodeName());
142+
}
143+
144+
public static final Map<String, PropertyEntry<?>> AUTHORIZATION_PROPERTY_ENTRIES =
42145
ImmutableMap.<String, PropertyEntry<?>>builder()
146+
.put(
147+
AuthorizationPropertiesMeta.getInstance().wildcardNodePropertyKey(),
148+
PropertyEntry.wildcardPropertyEntry(
149+
AuthorizationPropertiesMeta.getInstance().wildcardNodePropertyKey(),
150+
"The Chain authorization plugins"))
151+
.put(
152+
CHAIN_CATALOG_PROVIDER,
153+
PropertyEntry.wildcardPropertyEntry(
154+
CHAIN_PROVIDER, "The Chain sub entity catalog provider"))
155+
.put(
156+
CHAIN_PROVIDER,
157+
PropertyEntry.wildcardPropertyEntry(
158+
CHAIN_PROVIDER, "The Chain sub entity authorization plugin provider"))
159+
.put(
160+
CHAIN_RANGER_SERVICE_NAME,
161+
PropertyEntry.wildcardPropertyEntry(
162+
CHAIN_RANGER_SERVICE_NAME,
163+
"The Chain sub entity authorization Ranger service name"))
164+
.put(
165+
CHAIN_RANGER_ADMIN_URL,
166+
PropertyEntry.wildcardPropertyEntry(
167+
CHAIN_RANGER_ADMIN_URL,
168+
"The Chain sub entity authorization Ranger admin web URIs"))
169+
.put(
170+
CHAIN_RANGER_AUTH_TYPES,
171+
PropertyEntry.wildcardPropertyEntry(
172+
CHAIN_RANGER_AUTH_TYPES,
173+
"The Chain sub entity authorization Ranger admin web auth type (kerberos/simple)"))
174+
.put(
175+
CHAIN_RANGER_USERNAME,
176+
PropertyEntry.wildcardPropertyEntry(
177+
CHAIN_RANGER_USERNAME,
178+
"The Chain sub entity authorization Ranger admin web login username"))
179+
.put(
180+
CHAIN_RANGER_PASSWORD,
181+
PropertyEntry.wildcardPropertyEntry(
182+
CHAIN_RANGER_PASSWORD,
183+
"The Chain sub entity authorization Ranger admin web login password"))
43184
.put(
44185
RANGER_SERVICE_NAME,
45186
PropertyEntry.stringOptionalPropertyEntry(
@@ -65,4 +206,24 @@ public class AuthorizationPropertiesMeta {
65206
PropertyEntry.stringOptionalPropertyEntry(
66207
RANGER_PASSWORD, "The Ranger admin web login password", true, null, false))
67208
.build();
209+
210+
@Override
211+
protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
212+
return AUTHORIZATION_PROPERTY_ENTRIES;
213+
}
214+
215+
@Override
216+
public String firstNodeName() {
217+
return "authorization";
218+
}
219+
220+
@Override
221+
public String secondNodeName() {
222+
return "chain";
223+
}
224+
225+
@Override
226+
public String wildcardNodeName() {
227+
return "plugins";
228+
}
68229
}

core/src/main/java/org/apache/gravitino/connector/PropertiesMetadata.java

+11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ default boolean isRequiredProperty(String propertyName) {
5050
&& propertyEntries().get(propertyName).isRequired();
5151
}
5252

53+
/**
54+
* Check if the property is wildcard.
55+
*
56+
* @param propertyName The name of the property.
57+
* @return true if the property is existed and wildcard, false otherwise.
58+
*/
59+
default boolean isWildcardProperty(String propertyName) {
60+
return propertyEntries().containsKey(propertyName)
61+
&& propertyEntries().get(propertyName).isWildcard();
62+
}
63+
5364
/**
5465
* Check if the property is immutable.
5566
*

core/src/main/java/org/apache/gravitino/connector/PropertyEntry.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public final class PropertyEntry<T> {
3939
private final Function<T, String> encoder;
4040
private final boolean hidden;
4141
private final boolean reserved;
42+
private final boolean wildcard;
4243

4344
/**
4445
* @param name The name of the property
@@ -64,7 +65,8 @@ private PropertyEntry(
6465
Function<String, T> decoder,
6566
Function<T, String> encoder,
6667
boolean hidden,
67-
boolean reserved) {
68+
boolean reserved,
69+
boolean wildcard) {
6870
Preconditions.checkArgument(StringUtils.isNotBlank(name), "name cannot be null or empty");
6971
Preconditions.checkArgument(
7072
StringUtils.isNotBlank(description), "description cannot be null or empty");
@@ -87,6 +89,7 @@ private PropertyEntry(
8789
this.encoder = encoder;
8890
this.hidden = hidden;
8991
this.reserved = reserved;
92+
this.wildcard = wildcard;
9093
}
9194

9295
public static class Builder<T> {
@@ -100,6 +103,7 @@ public static class Builder<T> {
100103
private Function<T, String> encoder;
101104
private boolean hidden;
102105
private boolean reserved;
106+
private boolean wildcard;
103107

104108
public Builder<T> withName(String name) {
105109
this.name = name;
@@ -151,6 +155,11 @@ public Builder<T> withReserved(boolean reserved) {
151155
return this;
152156
}
153157

158+
public Builder<T> withWildcard(boolean wildcard) {
159+
this.wildcard = wildcard;
160+
return this;
161+
}
162+
154163
public PropertyEntry<T> build() {
155164
return new PropertyEntry<T>(
156165
name,
@@ -162,7 +171,8 @@ public PropertyEntry<T> build() {
162171
decoder,
163172
encoder,
164173
hidden,
165-
reserved);
174+
reserved,
175+
wildcard);
166176
}
167177
}
168178

@@ -268,6 +278,22 @@ public static PropertyEntry<Boolean> booleanReservedPropertyEntry(
268278
return booleanPropertyEntry(name, description, false, true, defaultValue, hidden, true);
269279
}
270280

281+
public static PropertyEntry<String> wildcardPropertyEntry(String name, String description) {
282+
return new Builder<String>()
283+
.withName(name)
284+
.withDescription(description)
285+
.withRequired(false)
286+
.withImmutable(false)
287+
.withJavaType(String.class)
288+
.withDefaultValue(null)
289+
.withDecoder(Function.identity())
290+
.withEncoder(Function.identity())
291+
.withHidden(false)
292+
.withReserved(false)
293+
.withWildcard(true)
294+
.build();
295+
}
296+
271297
public static PropertyEntry<Boolean> booleanPropertyEntry(
272298
String name,
273299
String description,

0 commit comments

Comments
 (0)