Skip to content

Commit

Permalink
moveConfig out to oss
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingjian Wu committed Jul 6, 2024
1 parent 084e314 commit 9bd01c5
Show file tree
Hide file tree
Showing 12 changed files with 425 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -635,5 +635,12 @@ public interface Config {
* @return True if it should be.
*/
boolean isParentChildDropEnabled();

/**
* Get the parentChildRelationshipProperties config.
*
* @return parentChildRelationshipProperties
*/
ParentChildRelationshipProperties getParentChildRelationshipProperties();
}

Original file line number Diff line number Diff line change
Expand Up @@ -681,21 +681,26 @@ public boolean shouldFetchOnlyMetadataLocationEnabled() {

@Override
public boolean isParentChildCreateEnabled() {
return this.metacatProperties.getParentChildRelationshipProperties().isParentChildCreateEnabled();
return this.metacatProperties.getParentChildRelationshipProperties().isCreateEnabled();
}

@Override
public boolean isParentChildRenameEnabled() {
return this.metacatProperties.getParentChildRelationshipProperties().isParentChildRenameEnabled();
return this.metacatProperties.getParentChildRelationshipProperties().isRenameEnabled();
}

@Override
public boolean isParentChildGetEnabled() {
return this.metacatProperties.getParentChildRelationshipProperties().isParentChildGetEnabled();
return this.metacatProperties.getParentChildRelationshipProperties().isGetEnabled();
}

@Override
public boolean isParentChildDropEnabled() {
return this.metacatProperties.getParentChildRelationshipProperties().isParentChildDropEnabled();
return this.metacatProperties.getParentChildRelationshipProperties().isDropEnabled();
}

@Override
public ParentChildRelationshipProperties getParentChildRelationshipProperties() {
return this.metacatProperties.getParentChildRelationshipProperties();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.netflix.metacat.common.server.properties;

import lombok.NonNull;
import org.springframework.core.env.Environment;

/**
* Entry point to entire property tree of Metacat namespace.
Expand All @@ -27,6 +28,8 @@
*/
@lombok.Data
public class MetacatProperties {
@NonNull
private Environment env;
@NonNull
private Data data = new Data();
@NonNull
Expand Down Expand Up @@ -68,6 +71,15 @@ public class MetacatProperties {
@NonNull
private RateLimiterProperties rateLimiterProperties = new RateLimiterProperties();
@NonNull
private ParentChildRelationshipProperties parentChildRelationshipProperties
= new ParentChildRelationshipProperties();
private ParentChildRelationshipProperties parentChildRelationshipProperties;

/**
* Constructor for MetacatProperties.
*
* @param env Spring Environment
*/
public MetacatProperties(final Environment env) {
this.env = env;
this.parentChildRelationshipProperties = new ParentChildRelationshipProperties(env);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,119 @@
package com.netflix.metacat.common.server.properties;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
* Parent Child Relationship service properties.
*
* @author yingjianw
*/
@Data
@Slf4j
public class ParentChildRelationshipProperties {
private boolean parentChildCreateEnabled = true;
private boolean parentChildGetEnabled = true;
private boolean parentChildRenameEnabled = true;
private boolean parentChildDropEnabled = true;
private boolean createEnabled = true;
private boolean getEnabled = true;
private boolean renameEnabled = true;
private boolean dropEnabled = true;
private int maxAllow = 5;
private Map<String, Map<String, Integer>> maxAllowPerTablePerRelType = new HashMap<>();
private Map<String, Map<String, Integer>> maxAllowPerDBPerRelType = new HashMap<>();
private Map<String, Integer> defaultMaxAllowPerRelType = new HashMap<>();
private String maxAllowPerTablePerRelPropertyName =
"metacat.parentChildRelationshipProperties.maxAllowPerTablePerRelConfig";
private String maxAllowPerDBPerRelPropertyName =
"metacat.parentChildRelationshipProperties.maxAllowPerDBPerRelConfig";
private String defaultMaxAllowPerRelPropertyName =
"metacat.parentChildRelationshipProperties.defaultMaxAllowPerRelConfig";

/**
* Constructor.
*
* @param env Spring environment
*/
public ParentChildRelationshipProperties(@Nullable final Environment env) {
if (env != null) {
setMaxAllowPerTablePerRelType(
env.getProperty(maxAllowPerTablePerRelPropertyName, String.class, "")
);
setMaxAllowPerDBPerRelType(
env.getProperty(maxAllowPerDBPerRelPropertyName, String.class, "")
);
setDefaultMaxAllowPerRelType(
env.getProperty(defaultMaxAllowPerRelPropertyName, String.class, "")
);
}
}

/**
* setMaxAllowPerTablePerRelType based on String config.
*
* @param configStr configString
*/
public void setMaxAllowPerTablePerRelType(@Nullable final String configStr) {
if (configStr == null || configStr.isEmpty()) {
return;
}
try {
this.maxAllowPerTablePerRelType = parseNestedConfigString(configStr);
} catch (Exception e) {
log.error("Fail to apply configStr = {} for maxAllowPerTablePerRelType", configStr, e);
}
}

/**
* setMaxAllowPerDBPerRelType based on String config.
*
* @param configStr configString
*/
public void setMaxAllowPerDBPerRelType(@Nullable final String configStr) {
if (configStr == null || configStr.isEmpty()) {
return;
}
try {
this.maxAllowPerDBPerRelType = parseNestedConfigString(configStr);
} catch (Exception e) {
log.error("Fail to apply configStr = {} for maxCloneAllowPerDBPerRelType", configStr);
}
}
/**
* setMaxCloneAllowPerDBPerRelType based on String config.
*
* @param configStr configString
*/
public void setDefaultMaxAllowPerRelType(@Nullable final String configStr) {
if (configStr == null || configStr.isEmpty()) {
return;
}
try {
this.defaultMaxAllowPerRelType =
Arrays.stream(configStr.split(";"))
.map(entry -> entry.split(","))
.collect(Collectors.toMap(
parts -> parts[0],
parts -> Integer.parseInt(parts[1])
));
} catch (Exception e) {
log.error("Fail to apply configStr = {} for defaultMaxAllowPerRelType", configStr);
}
}

private Map<String, Map<String, Integer>> parseNestedConfigString(final String configStr) {
return Arrays.stream(configStr.split(";"))
.map(entry -> entry.split(","))
.collect(Collectors.groupingBy(
parts -> parts[0],
Collectors.toMap(
parts -> parts[1],
parts -> Integer.parseInt(parts[2])
)
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.netflix.metacat.common.dto.ParentInfoDto;
import com.netflix.metacat.common.server.model.ChildInfo;
import com.netflix.metacat.common.server.model.ParentInfo;
import com.netflix.metacat.common.server.properties.ParentChildRelationshipProperties;

import java.util.Set;

Expand All @@ -25,13 +26,15 @@ public interface ParentChildRelMetadataService {
* @param childName the name of the child entity
* @param childUUID the uuid of the child
* @param relationType the type of the relationship
* @param prop properties config
*/
void createParentChildRelation(
QualifiedName parentName,
String parentUUID,
QualifiedName childName,
String childUUID,
String relationType
String relationType,
ParentChildRelationshipProperties prop
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class PolarisConnectorDatabaseServiceTest {
@BeforeEach
public void init() {
connectorContext = new ConnectorContext(CATALOG_NAME, CATALOG_NAME, "polaris",
new DefaultConfigImpl(new MetacatProperties()), new NoopRegistry(), null, Maps.newHashMap());
new DefaultConfigImpl(new MetacatProperties(null)), new NoopRegistry(), null, Maps.newHashMap());
polarisDBService = new PolarisConnectorDatabaseService(polarisStoreService, connectorContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;
Expand Down Expand Up @@ -75,6 +76,9 @@ public class PolarisConnectorTableServiceTest {
@Shared
private PolarisConnectorTableService polarisTableService;

@Shared
private Environment env = Mockito.mock(Environment.class);

/**
* Initialization.
*/
Expand All @@ -83,7 +87,7 @@ public void init() {
final String location = "file://temp";
polarisStoreService.createDatabase(DB_NAME, location, "metacat_user");
connectorContext = new ConnectorContext(CATALOG_NAME, CATALOG_NAME, "polaris",
new DefaultConfigImpl(new MetacatProperties()), new NoopRegistry(), null, Maps.newHashMap());
new DefaultConfigImpl(new MetacatProperties(null)), new NoopRegistry(), null, Maps.newHashMap());
polarisDBService = new PolarisConnectorDatabaseService(polarisStoreService, connectorContext);
polarisTableService = new PolarisConnectorTableService(
polarisStoreService,
Expand Down
Loading

0 comments on commit 9bd01c5

Please sign in to comment.