use of alluxio.cli.fsadmin.FileSystemAdminShell in project alluxio by Alluxio.
the class QuorumCommandIntegrationTest method elect.
@Test
public void elect() throws Exception {
final int MASTER_INDEX_WAIT_TIME = 5_000;
int numMasters = 3;
mCluster = MultiProcessCluster.newBuilder(PortCoordination.QUORUM_SHELL_REMOVE).setClusterName("QuorumShellElect").setNumMasters(numMasters).setNumWorkers(0).addProperty(PropertyKey.MASTER_JOURNAL_TYPE, JournalType.EMBEDDED.toString()).addProperty(PropertyKey.MASTER_JOURNAL_FLUSH_TIMEOUT_MS, "5min").addProperty(PropertyKey.MASTER_EMBEDDED_JOURNAL_MIN_ELECTION_TIMEOUT, "750ms").addProperty(PropertyKey.MASTER_EMBEDDED_JOURNAL_MAX_ELECTION_TIMEOUT, "1500ms").build();
mCluster.start();
try (FileSystemAdminShell shell = new FileSystemAdminShell(ServerConfiguration.global())) {
int newLeaderIdx = (mCluster.getPrimaryMasterIndex(MASTER_INDEX_WAIT_TIME) + 1) % numMasters;
// `getPrimaryMasterIndex` uses the same `mMasterAddresses` variable as getMasterAddresses
// we can therefore access to the new leader's address this ways
MasterNetAddress netAddress = mCluster.getMasterAddresses().get(newLeaderIdx);
String newLeaderAddr = String.format("%s:%s", netAddress.getHostname(), netAddress.getEmbeddedJournalPort());
mOutput.reset();
shell.run("journal", "quorum", "elect", "-address", newLeaderAddr);
String output = mOutput.toString().trim();
String expected = String.format("%s\n%s\n%s\n%s", String.format(QuorumElectCommand.TRANSFER_INIT, newLeaderAddr), String.format(QuorumElectCommand.TRANSFER_SUCCESS, newLeaderAddr), String.format(QuorumElectCommand.RESET_INIT, "successful"), QuorumElectCommand.RESET_SUCCESS);
Assert.assertEquals(expected, output);
}
mCluster.notifySuccess();
}
use of alluxio.cli.fsadmin.FileSystemAdminShell in project alluxio by Alluxio.
the class QuorumCommandIntegrationTest method quorumCommand.
@Test
public void quorumCommand() throws Exception {
mCluster = MultiProcessCluster.newBuilder(PortCoordination.QUORUM_SHELL).setClusterName("QuorumShell").setNumMasters(3).setNumWorkers(0).addProperty(PropertyKey.MASTER_JOURNAL_TYPE, JournalType.EMBEDDED.toString()).addProperty(PropertyKey.MASTER_JOURNAL_FLUSH_TIMEOUT_MS, "5min").addProperty(PropertyKey.MASTER_EMBEDDED_JOURNAL_MIN_ELECTION_TIMEOUT, "750ms").addProperty(PropertyKey.MASTER_EMBEDDED_JOURNAL_MAX_ELECTION_TIMEOUT, "1500ms").build();
mCluster.start();
try (FileSystemAdminShell shell = new FileSystemAdminShell(ServerConfiguration.global())) {
String output;
// Validate quorum sub-commands are validated.
mOutput.reset();
shell.run("journal", "quorum", "nonexistentCommand");
output = mOutput.toString().trim();
Assert.assertEquals(QuorumCommand.description(), lastLine(output));
// Validate option counts are validated for "quorum info"
mOutput.reset();
shell.run("journal", "quorum", "info");
output = mOutput.toString().trim();
Assert.assertEquals(QuorumInfoCommand.description(), lastLine(output));
mOutput.reset();
shell.run("journal", "quorum", "info", "-op1", "val1", "-op2", "val2");
output = mOutput.toString().trim();
Assert.assertEquals(QuorumInfoCommand.description(), lastLine(output));
// Validate option counts are validated for "quorum", "remove"
mOutput.reset();
shell.run("journal", "quorum", "remove");
output = mOutput.toString().trim();
Assert.assertEquals(QuorumRemoveCommand.description(), lastLine(output));
mOutput.reset();
shell.run("journal", "quorum", "remove", "-op1", "val1");
output = mOutput.toString().trim();
Assert.assertEquals(QuorumRemoveCommand.description(), lastLine(output));
mOutput.reset();
shell.run("journal", "quorum", "remove", "-op1", "val1", "-op2", "val2", "-op3", "val3");
output = mOutput.toString().trim();
Assert.assertEquals(QuorumRemoveCommand.description(), lastLine(output));
// Validate option counts are validated for "quorum", "elect"
mOutput.reset();
shell.run("journal", "quorum", "elect");
output = mOutput.toString().trim();
Assert.assertEquals(QuorumElectCommand.description(), lastLine(output));
mOutput.reset();
shell.run("journal", "quorum", "elect", "-op1", "val1");
output = mOutput.toString().trim();
Assert.assertEquals(QuorumElectCommand.description(), lastLine(output));
mOutput.reset();
shell.run("journal", "quorum", "elect", "-op1", "val1", "-op2", "val2", "-op3", "val3");
output = mOutput.toString().trim();
Assert.assertEquals(QuorumElectCommand.description(), lastLine(output));
// Validate option validation works for "quorum info".
mOutput.reset();
shell.run("journal", "quorum", "info", "-domain", "UNKNOWN");
output = mOutput.toString().trim();
Assert.assertEquals(ExceptionMessage.INVALID_OPTION_VALUE.getMessage(QuorumInfoCommand.DOMAIN_OPTION_NAME, Arrays.toString(JournalDomain.values())), output);
// Validate option validation works for "journal quorum remove"
// Validate -domain is validated.
mOutput.reset();
shell.run("journal", "quorum", "remove", "-domain", "UNKNOWN", "-address", "host:0");
output = mOutput.toString().trim();
Assert.assertEquals(ExceptionMessage.INVALID_OPTION_VALUE.getMessage(QuorumInfoCommand.DOMAIN_OPTION_NAME, Arrays.toString(JournalDomain.values())), output);
// Validate -address is validated.
mOutput.reset();
shell.run("journal", "quorum", "remove", "-domain", "JOB_MASTER", "-address", "hostname:invalid_port");
output = mOutput.toString().trim();
Assert.assertEquals(ExceptionMessage.INVALID_ADDRESS_VALUE.getMessage(), output);
// Validate -address is validated for transferLeader.
mOutput.reset();
shell.run("journal", "quorum", "elect", "-address", "hostname:invalid_port");
output = mOutput.toString().trim();
Assert.assertEquals(ExceptionMessage.INVALID_ADDRESS_VALUE.getMessage(), output);
}
mCluster.notifySuccess();
}
use of alluxio.cli.fsadmin.FileSystemAdminShell in project alluxio by Alluxio.
the class QuorumCommandIntegrationTest method quorumInfo.
@Test
public void quorumInfo() throws Exception {
mCluster = MultiProcessCluster.newBuilder(PortCoordination.QUORUM_SHELL_INFO).setClusterName("QuorumShellInfo").setNumMasters(3).setNumWorkers(0).addProperty(PropertyKey.MASTER_JOURNAL_TYPE, JournalType.EMBEDDED.toString()).addProperty(PropertyKey.MASTER_JOURNAL_FLUSH_TIMEOUT_MS, "5min").addProperty(PropertyKey.MASTER_EMBEDDED_JOURNAL_MIN_ELECTION_TIMEOUT, "750ms").addProperty(PropertyKey.MASTER_EMBEDDED_JOURNAL_MAX_ELECTION_TIMEOUT, "1500ms").build();
mCluster.start();
String output;
try (FileSystemAdminShell shell = new FileSystemAdminShell(ServerConfiguration.global())) {
// Validate quorum state is dumped as expected.
mOutput.reset();
shell.run("journal", "quorum", "info", "-domain", "MASTER");
output = mOutput.toString().trim();
Assert.assertTrue(output.contains(String.format(QuorumInfoCommand.OUTPUT_HEADER_DOMAIN, JournalDomain.MASTER.name())));
Assert.assertTrue(output.contains(String.format(QuorumInfoCommand.OUTPUT_HEADER_QUORUM_SIZE, 3)));
String journalAddresses = ServerConfiguration.getString(PropertyKey.MASTER_EMBEDDED_JOURNAL_ADDRESSES);
for (String address : journalAddresses.split(",")) {
String format = String.format(QuorumInfoCommand.OUTPUT_SERVER_INFO, QuorumServerState.AVAILABLE.name(), "0", address).trim();
Assert.assertTrue(output.contains(format));
}
// Validate quorum state is updated as expected after a fail-over.
mCluster.stopMaster(0);
// Wait for up to 2 election timeouts until quorum notices the change.
// Use shell "quorum info" for validation.
CommonUtils.waitFor("Quorum noticing change.", () -> {
mOutput.reset();
shell.run("journal", "quorum", "info", "-domain", "MASTER");
return mOutput.toString().trim().contains(QuorumServerState.UNAVAILABLE.name());
}, WaitForOptions.defaults().setTimeoutMs(2 * (int) ServerConfiguration.getMs(PropertyKey.MASTER_EMBEDDED_JOURNAL_MAX_ELECTION_TIMEOUT)));
}
mCluster.notifySuccess();
}
use of alluxio.cli.fsadmin.FileSystemAdminShell in project alluxio by Alluxio.
the class AddCommandIntegrationTest method add.
@Test
public void add() throws Exception {
try (FileSystemAdminShell shell = new FileSystemAdminShell(ServerConfiguration.global())) {
int ret = shell.run("pathConf", "list");
Assert.assertEquals(0, ret);
String output = mOutput.toString();
Assert.assertEquals("", output);
ret = shell.run("pathConf", "show", PATH1);
Assert.assertEquals(0, ret);
output = mOutput.toString();
Assert.assertEquals("", output);
mOutput.reset();
ret = shell.run("pathConf", "show", PATH2);
Assert.assertEquals(0, ret);
output = mOutput.toString();
Assert.assertEquals("", output);
mOutput.reset();
ret = shell.run("pathConf", "add", "--property", READ_TYPE_NO_CACHE, "--property", WRITE_TYPE_CACHE_THROUGH, PATH1);
Assert.assertEquals(0, ret);
output = mOutput.toString();
Assert.assertEquals("", output);
mOutput.reset();
ret = shell.run("pathConf", "list");
Assert.assertEquals(0, ret);
output = mOutput.toString();
Assert.assertEquals(PATH1 + "\n", output);
mOutput.reset();
ret = shell.run("pathConf", "add", "--property", WRITE_TYPE_THROUGH, PATH2);
Assert.assertEquals(0, ret);
output = mOutput.toString();
Assert.assertEquals("", output);
mOutput.reset();
ret = shell.run("pathConf", "list");
Assert.assertEquals(0, ret);
output = mOutput.toString();
Assert.assertEquals(PATH1 + "\n" + PATH2 + "\n", output);
mOutput.reset();
ret = shell.run("pathConf", "show", PATH1);
Assert.assertEquals(0, ret);
String expected = READ_TYPE_NO_CACHE + "\n" + WRITE_TYPE_CACHE_THROUGH + "\n";
output = mOutput.toString();
Assert.assertEquals(expected, output);
mOutput.reset();
ret = shell.run("pathConf", "show", PATH2);
Assert.assertEquals(0, ret);
expected = WRITE_TYPE_THROUGH + "\n";
output = mOutput.toString();
Assert.assertEquals(expected, output);
}
}
use of alluxio.cli.fsadmin.FileSystemAdminShell in project alluxio by Alluxio.
the class AddCommandIntegrationTest method nonClientScopeKey.
@Test
public void nonClientScopeKey() throws Exception {
try (FileSystemAdminShell shell = new FileSystemAdminShell(ServerConfiguration.global())) {
PropertyKey key = PropertyKey.NETWORK_CONNECTION_SERVER_SHUTDOWN_TIMEOUT;
int ret = shell.run("pathConf", "add", "--property", format(key, "10ms"), "/");
Assert.assertEquals(-1, ret);
String output = mOutput.toString();
Assert.assertEquals(AddCommand.nonClientScopePropertyException(key) + "\n", output);
}
}
Aggregations