Skip to content

Commit

Permalink
Adding support for custom override for role_manager (#918)
Browse files Browse the repository at this point in the history
Co-authored-by: Sumanth Pasupuleti <[email protected]>
  • Loading branch information
sumanth-pasupuleti and Sumanth Pasupuleti authored Feb 17, 2021
1 parent 6919d34 commit 243afcf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ default String getAuthorizer() {
return "org.apache.cassandra.auth.AllowAllAuthorizer";
}

/** Defaults to 'CassandraRoleManager'. */
default String getRoleManager() {
return "org.apache.cassandra.auth.CassandraRoleManager";
}

/** @return true/false, if Cassandra needs to be started manually */
default boolean doesCassandraStartManually() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,11 @@ public String getAuthorizer() {
PRIAM_PRE + ".authorizer", "org.apache.cassandra.auth.AllowAllAuthorizer");
}

public String getRoleManager() {
return config.get(
PRIAM_PRE + ".roleManager", "org.apache.cassandra.auth.CassandraRoleManager");
}

@Override
public boolean doesCassandraStartManually() {
return config.get(PRIAM_PRE + ".cass.manual.start.enable", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public void writeAllProperties(String yamlLocation, String hostname, String seed
map.put("hinted_handoff_throttle_in_kb", config.getHintedHandoffThrottleKb());
map.put("authenticator", config.getAuthenticator());
map.put("authorizer", config.getAuthorizer());
map.put("role_manager", config.getRoleManager());
map.put("internode_compression", config.getInternodeCompression());
map.put("dynamic_snitch", config.isDynamicSnitchEnabled());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class FakeConfiguration implements IConfiguration {
private final String appName;
private String restorePrefix = "";
public Map<String, Object> fakeConfig;
private String roleManager = "";

public Map<String, String> fakeProperties = new HashMap<>();

Expand Down Expand Up @@ -184,6 +185,16 @@ public ImmutableSet<String> getTunablePropertyFiles() {
return ImmutableSet.of(path + "/cassandra-rackdc.properties");
}

@Override
public String getRoleManager() {
return this.roleManager;
}

public FakeConfiguration setRoleManager(String roleManager) {
this.roleManager = roleManager;
return this;
}

public String getRAC() {
return "my_zone";
}
Expand Down
33 changes: 22 additions & 11 deletions priam/src/test/java/com/netflix/priam/tuner/StandardTunerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,36 @@ public void addExtraParams() throws Exception {
extraParamValues.put(priamKeyName2, "test");
extraParamValues.put(priamKeyName3, "randomKeyValue");
extraParamValues.put(priamKeyName4, "randomGroupValue");

Map map =
applyFakeConfiguration(new TunerConfiguration(extraConfigParam, extraParamValues));
Assert.assertEquals("your_host", map.get("listen_address"));
Assert.assertEquals("true", ((Map) map.get("client_encryption_options")).get("optional"));
Assert.assertEquals(
"test", ((Map) map.get("client_encryption_options")).get("keystore_password"));
Assert.assertEquals("randomKeyValue", map.get("randomKey"));
Assert.assertEquals("randomGroupValue", ((Map) map.get("randomGroup")).get("randomKey"));
}

@Test
public void testRoleManagerOverride() throws Exception {
String roleManagerOverride = "org.apache.cassandra.auth.CustomRoleManager";
Map map =
applyFakeConfiguration(new FakeConfiguration().setRoleManager(roleManagerOverride));
Assert.assertEquals(roleManagerOverride, map.get("role_manager"));
}

private Map applyFakeConfiguration(FakeConfiguration fakeConfiguration) throws Exception {
StandardTuner tuner =
new StandardTuner(
new TunerConfiguration(extraConfigParam, extraParamValues),
backupRestoreConfig,
instanceInfo);
new StandardTuner(fakeConfiguration, backupRestoreConfig, instanceInfo);
Files.copy(new File("src/main/resources/incr-restore-cassandra.yaml"), target);
tuner.writeAllProperties(target.getAbsolutePath(), "your_host", "YourSeedProvider");

// Read the tuned file and verify
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
Map map = yaml.load(new FileInputStream(target));
Assert.assertEquals("your_host", map.get("listen_address"));
Assert.assertEquals("true", ((Map) map.get("client_encryption_options")).get("optional"));
Assert.assertEquals(
"test", ((Map) map.get("client_encryption_options")).get("keystore_password"));
Assert.assertEquals("randomKeyValue", map.get("randomKey"));
Assert.assertEquals("randomGroupValue", ((Map) map.get("randomGroup")).get("randomKey"));
return yaml.load(new FileInputStream(target));
}

private class TunerConfiguration extends FakeConfiguration {
Expand Down

0 comments on commit 243afcf

Please sign in to comment.