Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved the issue where the custom database prefix was lost after th… #335

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ public AbstractMetaStore(
this.writableDatabaseWhitelist = writableDatabaseWhitelist;
}

public AbstractMetaStore(
String name,
String remoteMetaStoreUris,
String databasePrefix,
AccessControlType accessControlType,
List<String> writableDatabaseWhitelist) {
this.name = name;
this.remoteMetaStoreUris = remoteMetaStoreUris;
this.databasePrefix = databasePrefix;
this.accessControlType = accessControlType;
this.writableDatabaseWhitelist = writableDatabaseWhitelist;
}


public static FederatedMetaStore newFederatedInstance(String name, String remoteMetaStoreUris) {
return new FederatedMetaStore(name, remoteMetaStoreUris);
}
Expand All @@ -95,6 +109,14 @@ public static PrimaryMetaStore newPrimaryInstance(String name, String remoteMeta
return new PrimaryMetaStore(name, remoteMetaStoreUris, AccessControlType.READ_ONLY);
}

public static PrimaryMetaStore newPrimaryInstance(
String name,
String remoteMetaStoreUris,
String databasePrefix,
AccessControlType accessControlType) {
return new PrimaryMetaStore(name, remoteMetaStoreUris, databasePrefix, accessControlType);
}

public String getDatabasePrefix() {
return databasePrefix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ public PrimaryMetaStore(
super(name, remoteMetaStoreUris, accessControlType, writableDatabaseWhitelist);
}

public PrimaryMetaStore(
String name,
String remoteMetaStoreUris,
String databasePrefix,
AccessControlType accessControlType,
String... writableDatabaseWhitelist) {
this(name, remoteMetaStoreUris, databasePrefix, accessControlType, Arrays.asList(writableDatabaseWhitelist));
}

public PrimaryMetaStore(
String name,
String remoteMetaStoreUris,
String databasePrefix,
AccessControlType accessControlType,
List<String> writableDatabaseWhitelist) {
super(name, remoteMetaStoreUris, databasePrefix, accessControlType, writableDatabaseWhitelist);
}

@Override
public FederationType getFederationType() {
return FederationType.PRIMARY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ public void newPrimaryInstanceWithDefaultAccessControlType() {
assertThat(primaryMetaStore.getAccessControlType(), is(AccessControlType.READ_ONLY));
}

@Test
public void newPrimaryPrefixInstance() {
AccessControlType access = AccessControlType.READ_AND_WRITE_AND_CREATE;
String databasePrefix = "primary";
PrimaryMetaStore primaryMetaStore = AbstractMetaStore.newPrimaryInstance(name, remoteMetaStoreUri, databasePrefix, access);
assertThat(primaryMetaStore.getName(), is(name));
assertThat(primaryMetaStore.getRemoteMetaStoreUris(), is(remoteMetaStoreUri));
assertThat(primaryMetaStore.getDatabasePrefix(), is(databasePrefix));
assertThat(primaryMetaStore.getAccessControlType(), is(access));
}


@Test
public void mappedDatabases() {
List<String> mappedDatabases = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class PrimaryMetaStoreTest extends AbstractMetaStoreTest<PrimaryMetaStore
private final String remoteMetaStoreUris = "remoteMetaStoreUris";
private final List<String> whitelist = new ArrayList<>();
private final AccessControlType accessControlType = AccessControlType.READ_AND_WRITE_ON_DATABASE_WHITELIST;
private final String databasePrefix = "primary";

public PrimaryMetaStoreTest() {
super(new PrimaryMetaStore());
Expand Down Expand Up @@ -120,4 +121,29 @@ public void constructorWithArrayListForWhitelist() {
assertThat(store.getWritableDatabaseWhiteList(), is(whitelist));
}

@Test
public void nonEmptyPrefixConstructor() {
whitelist.add("databaseOne");
whitelist.add("databaseTwo");
PrimaryMetaStore store = new PrimaryMetaStore(name, remoteMetaStoreUris, databasePrefix, accessControlType, whitelist.get(0),
whitelist.get(1));
assertThat(store.getName(), is(name));
assertThat(store.getRemoteMetaStoreUris(), is(remoteMetaStoreUris));
assertThat(store.getDatabasePrefix(), is(databasePrefix));
assertThat(store.getAccessControlType(), is(accessControlType));
assertThat(store.getWritableDatabaseWhiteList(), is(whitelist));
}

@Test
public void constructorWithPrefixArrayListForWhitelist() {
whitelist.add("databaseOne");
whitelist.add("databaseTwo");
PrimaryMetaStore store = new PrimaryMetaStore(name, remoteMetaStoreUris, databasePrefix, accessControlType, whitelist);
assertThat(store.getName(), is(name));
assertThat(store.getRemoteMetaStoreUris(), is(remoteMetaStoreUris));
assertThat(store.getDatabasePrefix(), is(databasePrefix));
assertThat(store.getAccessControlType(), is(accessControlType));
assertThat(store.getWritableDatabaseWhiteList(), is(whitelist));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void databaseCreatedNotification(String name) {
AbstractMetaStore newMetaStore;
if (metaStore instanceof PrimaryMetaStore) {
newMetaStore = new PrimaryMetaStore(metaStore.getName(), metaStore.getRemoteMetaStoreUris(),
metaStore.getAccessControlType(), newWritableDatabaseWhiteList);
metaStore.getDatabasePrefix(), metaStore.getAccessControlType(), newWritableDatabaseWhiteList);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test on this class: DatabaseWhitelistAccessControlHandlerTest

newMetaStore.setMappedDatabases(mappedDatabases);
} else {
throw new WaggleDanceException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void databaseCreatedNotification(String name) {
AbstractMetaStore newMetaStore;
if (metaStore instanceof PrimaryMetaStore) {
newMetaStore = new PrimaryMetaStore(metaStore.getName(), metaStore.getRemoteMetaStoreUris(),
metaStore.getAccessControlType());
metaStore.getDatabasePrefix(), metaStore.getAccessControlType());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test in here: ReadWriteCreateAccessControlHandlerTest

newMetaStore.setMappedDatabases(mappedDatabases);
} else {
throw new WaggleDanceException(
Expand Down