-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support wildcard based matching for togglestatus endpoint (#203)
This PR contains logically two components: - The changes in `iceberg/openhouse/internalcatalog/src/main/java/com/linkedin/openhouse/internal/catalog/OpenHouseInternalCatalog.java` is due to the discovery in the testing phase that the an inheritance doesn't apply for annotation and AOP's proxy model requires the annotation to be applied on the object that got directly invoked. Thus the annotation in this `createTable` is not necessary. Since adding annotation was the only reason why rewriting this method, removing this whole method doesn't change any behavior. - The main part of this PR is to add wildcard matching for `hts/togglestatus` endpoint, so that for features like temporarily forbidding table-creation, we can simply insert one rule that contains wildcard for both tableId and databaseId.
- Loading branch information
Showing
8 changed files
with
114 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...les/src/main/java/com/linkedin/openhouse/housetables/services/TableToggleRuleMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.linkedin.openhouse.housetables.services; | ||
|
||
import com.linkedin.openhouse.housetables.model.TableToggleRule; | ||
|
||
public interface TableToggleRuleMatcher { | ||
boolean matches(TableToggleRule rule, String tableId, String databaseId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...main/java/com/linkedin/openhouse/housetables/services/WildcardTableToggleRuleMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.linkedin.openhouse.housetables.services; | ||
|
||
import com.linkedin.openhouse.housetables.model.TableToggleRule; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** An implementation of {@link TableToggleRuleMatcher} that supports '*' to match any entities */ | ||
@Component | ||
public class WildcardTableToggleRuleMatcher implements TableToggleRuleMatcher { | ||
@Override | ||
public boolean matches(TableToggleRule rule, String tableId, String databaseId) { | ||
boolean tableMatches = | ||
rule.getTablePattern().equals("*") || rule.getTablePattern().equals(tableId); | ||
boolean databaseMatches = | ||
rule.getDatabasePattern().equals("*") || rule.getDatabasePattern().equals(databaseId); | ||
|
||
return tableMatches && databaseMatches; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...test/java/com/linkedin/openhouse/housetables/mock/WildcardTableToggleRuleMatcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.linkedin.openhouse.housetables.mock; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.linkedin.openhouse.housetables.model.TableToggleRule; | ||
import com.linkedin.openhouse.housetables.services.WildcardTableToggleRuleMatcher; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
class WildcardTableToggleRuleMatcherTest { | ||
|
||
@Mock private TableToggleRule mockRule; | ||
|
||
private WildcardTableToggleRuleMatcher matcher; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
matcher = new WildcardTableToggleRuleMatcher(); | ||
} | ||
|
||
@Test | ||
void testExactMatch() { | ||
when(mockRule.getTablePattern()).thenReturn("table1"); | ||
when(mockRule.getDatabasePattern()).thenReturn("db1"); | ||
|
||
assertTrue(matcher.matches(mockRule, "table1", "db1")); | ||
assertFalse(matcher.matches(mockRule, "table2", "db1")); | ||
assertFalse(matcher.matches(mockRule, "table1", "db2")); | ||
} | ||
|
||
@Test | ||
void testWildcardTableMatch() { | ||
when(mockRule.getTablePattern()).thenReturn("*"); | ||
when(mockRule.getDatabasePattern()).thenReturn("db1"); | ||
|
||
assertTrue(matcher.matches(mockRule, "table1", "db1")); | ||
assertTrue(matcher.matches(mockRule, "table2", "db1")); | ||
assertFalse(matcher.matches(mockRule, "table1", "db2")); | ||
} | ||
|
||
@Test | ||
void testWildcardDatabaseMatch() { | ||
when(mockRule.getTablePattern()).thenReturn("table1"); | ||
when(mockRule.getDatabasePattern()).thenReturn("*"); | ||
|
||
assertTrue(matcher.matches(mockRule, "table1", "db1")); | ||
assertTrue(matcher.matches(mockRule, "table1", "db2")); | ||
assertFalse(matcher.matches(mockRule, "table2", "db1")); | ||
} | ||
|
||
@Test | ||
void testBothWildcardMatch() { | ||
when(mockRule.getTablePattern()).thenReturn("*"); | ||
when(mockRule.getDatabasePattern()).thenReturn("*"); | ||
|
||
assertTrue(matcher.matches(mockRule, "table1", "db1")); | ||
assertTrue(matcher.matches(mockRule, "table2", "db2")); | ||
assertTrue(matcher.matches(mockRule, "anyTable", "anyDb")); | ||
} | ||
|
||
@Test | ||
void testNoMatch() { | ||
when(mockRule.getTablePattern()).thenReturn("table1"); | ||
when(mockRule.getDatabasePattern()).thenReturn("db1"); | ||
|
||
assertFalse(matcher.matches(mockRule, "table2", "db2")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters