Skip to content

Commit 9bd01c5

Browse files
author
Yingjian Wu
committed
moveConfig out to oss
1 parent 084e314 commit 9bd01c5

File tree

12 files changed

+425
-51
lines changed

12 files changed

+425
-51
lines changed

metacat-common-server/src/main/java/com/netflix/metacat/common/server/properties/Config.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,5 +635,12 @@ public interface Config {
635635
* @return True if it should be.
636636
*/
637637
boolean isParentChildDropEnabled();
638+
639+
/**
640+
* Get the parentChildRelationshipProperties config.
641+
*
642+
* @return parentChildRelationshipProperties
643+
*/
644+
ParentChildRelationshipProperties getParentChildRelationshipProperties();
638645
}
639646

metacat-common-server/src/main/java/com/netflix/metacat/common/server/properties/DefaultConfigImpl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,21 +681,26 @@ public boolean shouldFetchOnlyMetadataLocationEnabled() {
681681

682682
@Override
683683
public boolean isParentChildCreateEnabled() {
684-
return this.metacatProperties.getParentChildRelationshipProperties().isParentChildCreateEnabled();
684+
return this.metacatProperties.getParentChildRelationshipProperties().isCreateEnabled();
685685
}
686686

687687
@Override
688688
public boolean isParentChildRenameEnabled() {
689-
return this.metacatProperties.getParentChildRelationshipProperties().isParentChildRenameEnabled();
689+
return this.metacatProperties.getParentChildRelationshipProperties().isRenameEnabled();
690690
}
691691

692692
@Override
693693
public boolean isParentChildGetEnabled() {
694-
return this.metacatProperties.getParentChildRelationshipProperties().isParentChildGetEnabled();
694+
return this.metacatProperties.getParentChildRelationshipProperties().isGetEnabled();
695695
}
696696

697697
@Override
698698
public boolean isParentChildDropEnabled() {
699-
return this.metacatProperties.getParentChildRelationshipProperties().isParentChildDropEnabled();
699+
return this.metacatProperties.getParentChildRelationshipProperties().isDropEnabled();
700+
}
701+
702+
@Override
703+
public ParentChildRelationshipProperties getParentChildRelationshipProperties() {
704+
return this.metacatProperties.getParentChildRelationshipProperties();
700705
}
701706
}

metacat-common-server/src/main/java/com/netflix/metacat/common/server/properties/MetacatProperties.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.netflix.metacat.common.server.properties;
1919

2020
import lombok.NonNull;
21+
import org.springframework.core.env.Environment;
2122

2223
/**
2324
* Entry point to entire property tree of Metacat namespace.
@@ -27,6 +28,8 @@
2728
*/
2829
@lombok.Data
2930
public class MetacatProperties {
31+
@NonNull
32+
private Environment env;
3033
@NonNull
3134
private Data data = new Data();
3235
@NonNull
@@ -68,6 +71,15 @@ public class MetacatProperties {
6871
@NonNull
6972
private RateLimiterProperties rateLimiterProperties = new RateLimiterProperties();
7073
@NonNull
71-
private ParentChildRelationshipProperties parentChildRelationshipProperties
72-
= new ParentChildRelationshipProperties();
74+
private ParentChildRelationshipProperties parentChildRelationshipProperties;
75+
76+
/**
77+
* Constructor for MetacatProperties.
78+
*
79+
* @param env Spring Environment
80+
*/
81+
public MetacatProperties(final Environment env) {
82+
this.env = env;
83+
this.parentChildRelationshipProperties = new ParentChildRelationshipProperties(env);
84+
}
7385
}
Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,119 @@
11
package com.netflix.metacat.common.server.properties;
22

33
import lombok.Data;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.core.env.Environment;
6+
7+
import javax.annotation.Nullable;
8+
import java.util.Arrays;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
import java.util.stream.Collectors;
412

513
/**
614
* Parent Child Relationship service properties.
715
*
816
* @author yingjianw
917
*/
1018
@Data
19+
@Slf4j
1120
public class ParentChildRelationshipProperties {
12-
private boolean parentChildCreateEnabled = true;
13-
private boolean parentChildGetEnabled = true;
14-
private boolean parentChildRenameEnabled = true;
15-
private boolean parentChildDropEnabled = true;
21+
private boolean createEnabled = true;
22+
private boolean getEnabled = true;
23+
private boolean renameEnabled = true;
24+
private boolean dropEnabled = true;
25+
private int maxAllow = 5;
26+
private Map<String, Map<String, Integer>> maxAllowPerTablePerRelType = new HashMap<>();
27+
private Map<String, Map<String, Integer>> maxAllowPerDBPerRelType = new HashMap<>();
28+
private Map<String, Integer> defaultMaxAllowPerRelType = new HashMap<>();
29+
private String maxAllowPerTablePerRelPropertyName =
30+
"metacat.parentChildRelationshipProperties.maxAllowPerTablePerRelConfig";
31+
private String maxAllowPerDBPerRelPropertyName =
32+
"metacat.parentChildRelationshipProperties.maxAllowPerDBPerRelConfig";
33+
private String defaultMaxAllowPerRelPropertyName =
34+
"metacat.parentChildRelationshipProperties.defaultMaxAllowPerRelConfig";
35+
36+
/**
37+
* Constructor.
38+
*
39+
* @param env Spring environment
40+
*/
41+
public ParentChildRelationshipProperties(@Nullable final Environment env) {
42+
if (env != null) {
43+
setMaxAllowPerTablePerRelType(
44+
env.getProperty(maxAllowPerTablePerRelPropertyName, String.class, "")
45+
);
46+
setMaxAllowPerDBPerRelType(
47+
env.getProperty(maxAllowPerDBPerRelPropertyName, String.class, "")
48+
);
49+
setDefaultMaxAllowPerRelType(
50+
env.getProperty(defaultMaxAllowPerRelPropertyName, String.class, "")
51+
);
52+
}
53+
}
54+
55+
/**
56+
* setMaxAllowPerTablePerRelType based on String config.
57+
*
58+
* @param configStr configString
59+
*/
60+
public void setMaxAllowPerTablePerRelType(@Nullable final String configStr) {
61+
if (configStr == null || configStr.isEmpty()) {
62+
return;
63+
}
64+
try {
65+
this.maxAllowPerTablePerRelType = parseNestedConfigString(configStr);
66+
} catch (Exception e) {
67+
log.error("Fail to apply configStr = {} for maxAllowPerTablePerRelType", configStr, e);
68+
}
69+
}
70+
71+
/**
72+
* setMaxAllowPerDBPerRelType based on String config.
73+
*
74+
* @param configStr configString
75+
*/
76+
public void setMaxAllowPerDBPerRelType(@Nullable final String configStr) {
77+
if (configStr == null || configStr.isEmpty()) {
78+
return;
79+
}
80+
try {
81+
this.maxAllowPerDBPerRelType = parseNestedConfigString(configStr);
82+
} catch (Exception e) {
83+
log.error("Fail to apply configStr = {} for maxCloneAllowPerDBPerRelType", configStr);
84+
}
85+
}
86+
/**
87+
* setMaxCloneAllowPerDBPerRelType based on String config.
88+
*
89+
* @param configStr configString
90+
*/
91+
public void setDefaultMaxAllowPerRelType(@Nullable final String configStr) {
92+
if (configStr == null || configStr.isEmpty()) {
93+
return;
94+
}
95+
try {
96+
this.defaultMaxAllowPerRelType =
97+
Arrays.stream(configStr.split(";"))
98+
.map(entry -> entry.split(","))
99+
.collect(Collectors.toMap(
100+
parts -> parts[0],
101+
parts -> Integer.parseInt(parts[1])
102+
));
103+
} catch (Exception e) {
104+
log.error("Fail to apply configStr = {} for defaultMaxAllowPerRelType", configStr);
105+
}
106+
}
107+
108+
private Map<String, Map<String, Integer>> parseNestedConfigString(final String configStr) {
109+
return Arrays.stream(configStr.split(";"))
110+
.map(entry -> entry.split(","))
111+
.collect(Collectors.groupingBy(
112+
parts -> parts[0],
113+
Collectors.toMap(
114+
parts -> parts[1],
115+
parts -> Integer.parseInt(parts[2])
116+
)
117+
));
118+
}
16119
}

metacat-common-server/src/main/java/com/netflix/metacat/common/server/usermetadata/ParentChildRelMetadataService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.netflix.metacat.common.dto.ParentInfoDto;
55
import com.netflix.metacat.common.server.model.ChildInfo;
66
import com.netflix.metacat.common.server.model.ParentInfo;
7+
import com.netflix.metacat.common.server.properties.ParentChildRelationshipProperties;
78

89
import java.util.Set;
910

@@ -25,13 +26,15 @@ public interface ParentChildRelMetadataService {
2526
* @param childName the name of the child entity
2627
* @param childUUID the uuid of the child
2728
* @param relationType the type of the relationship
29+
* @param prop properties config
2830
*/
2931
void createParentChildRelation(
3032
QualifiedName parentName,
3133
String parentUUID,
3234
QualifiedName childName,
3335
String childUUID,
34-
String relationType
36+
String relationType,
37+
ParentChildRelationshipProperties prop
3538
);
3639

3740
/**

metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class PolarisConnectorDatabaseServiceTest {
6565
@BeforeEach
6666
public void init() {
6767
connectorContext = new ConnectorContext(CATALOG_NAME, CATALOG_NAME, "polaris",
68-
new DefaultConfigImpl(new MetacatProperties()), new NoopRegistry(), null, Maps.newHashMap());
68+
new DefaultConfigImpl(new MetacatProperties(null)), new NoopRegistry(), null, Maps.newHashMap());
6969
polarisDBService = new PolarisConnectorDatabaseService(polarisStoreService, connectorContext);
7070
}
7171

metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorTableServiceTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.beans.factory.annotation.Autowired;
3434
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa;
3535
import org.springframework.boot.test.context.SpringBootTest;
36+
import org.springframework.core.env.Environment;
3637
import org.springframework.test.annotation.DirtiesContext;
3738
import org.springframework.test.context.ActiveProfiles;
3839
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -75,6 +76,9 @@ public class PolarisConnectorTableServiceTest {
7576
@Shared
7677
private PolarisConnectorTableService polarisTableService;
7778

79+
@Shared
80+
private Environment env = Mockito.mock(Environment.class);
81+
7882
/**
7983
* Initialization.
8084
*/
@@ -83,7 +87,7 @@ public void init() {
8387
final String location = "file://temp";
8488
polarisStoreService.createDatabase(DB_NAME, location, "metacat_user");
8589
connectorContext = new ConnectorContext(CATALOG_NAME, CATALOG_NAME, "polaris",
86-
new DefaultConfigImpl(new MetacatProperties()), new NoopRegistry(), null, Maps.newHashMap());
90+
new DefaultConfigImpl(new MetacatProperties(null)), new NoopRegistry(), null, Maps.newHashMap());
8791
polarisDBService = new PolarisConnectorDatabaseService(polarisStoreService, connectorContext);
8892
polarisTableService = new PolarisConnectorTableService(
8993
polarisStoreService,

0 commit comments

Comments
 (0)