use of org.apache.hadoop.hdds.scm.DatanodeAdminError in project ozone by apache.
the class StorageContainerLocationProtocolClientSideTranslatorPB method startMaintenanceNodes.
/**
* Attempts to put the list of nodes into maintenance mode.
*
* @param nodes The list of hostnames or hostname:ports to put into
* maintenance
* @param endInHours A number of hours from now where the nodes will be taken
* out of maintenance automatically. Passing zero will
* allow the nodes to stay in maintenance indefinitely
* @throws IOException
*/
@Override
public List<DatanodeAdminError> startMaintenanceNodes(List<String> nodes, int endInHours) throws IOException {
Preconditions.checkNotNull(nodes);
StartMaintenanceNodesRequestProto request = StartMaintenanceNodesRequestProto.newBuilder().addAllHosts(nodes).setEndInHours(endInHours).build();
StartMaintenanceNodesResponseProto response = submitRequest(Type.StartMaintenanceNodes, builder -> builder.setStartMaintenanceNodesRequest(request)).getStartMaintenanceNodesResponse();
List<DatanodeAdminError> errors = new ArrayList<>();
for (DatanodeAdminErrorResponseProto e : response.getFailedHostsList()) {
errors.add(new DatanodeAdminError(e.getHost(), e.getError()));
}
return errors;
}
use of org.apache.hadoop.hdds.scm.DatanodeAdminError in project ozone by apache.
the class TestMaintenanceSubCommand method testErrorsReportedWhenEnteringMaintenance.
@Test
public void testErrorsReportedWhenEnteringMaintenance() throws IOException {
ScmClient scmClient = mock(ScmClient.class);
Mockito.when(scmClient.startMaintenanceNodes(anyListOf(String.class), anyInt())).thenAnswer(invocation -> {
ArrayList<DatanodeAdminError> e = new ArrayList<>();
e.add(new DatanodeAdminError("host1", "host1 error"));
return e;
});
CommandLine c = new CommandLine(cmd);
c.parseArgs("host1", "host2");
try {
cmd.execute(scmClient);
fail("Should not succeed without an exception");
} catch (IOException e) {
// Expected
}
Pattern p = Pattern.compile("^Entering\\smaintenance\\smode\\son\\sdatanode\\(s\\)", Pattern.MULTILINE);
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
p = Pattern.compile("^host1$", Pattern.MULTILINE);
m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
p = Pattern.compile("^host2$", Pattern.MULTILINE);
m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
p = Pattern.compile("^Error: host1: host1 error$", Pattern.MULTILINE);
m = p.matcher(errContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
}
use of org.apache.hadoop.hdds.scm.DatanodeAdminError in project ozone by apache.
the class TestMaintenanceSubCommand method testNoErrorsWhenEnteringMaintenance.
@Test
public void testNoErrorsWhenEnteringMaintenance() throws IOException {
ScmClient scmClient = mock(ScmClient.class);
Mockito.when(scmClient.startMaintenanceNodes(anyListOf(String.class), anyInt())).thenAnswer(invocation -> new ArrayList<DatanodeAdminError>());
CommandLine c = new CommandLine(cmd);
c.parseArgs("host1", "host2");
cmd.execute(scmClient);
Pattern p = Pattern.compile("^Entering\\smaintenance\\smode\\son\\sdatanode\\(s\\)", Pattern.MULTILINE);
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
p = Pattern.compile("^host1$", Pattern.MULTILINE);
m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
p = Pattern.compile("^host2$", Pattern.MULTILINE);
m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
}
use of org.apache.hadoop.hdds.scm.DatanodeAdminError in project ozone by apache.
the class TestRecommissionSubCommand method testNoErrorsWhenRecommissioning.
@Test
public void testNoErrorsWhenRecommissioning() throws IOException {
ScmClient scmClient = mock(ScmClient.class);
Mockito.when(scmClient.recommissionNodes(anyListOf(String.class))).thenAnswer(invocation -> new ArrayList<DatanodeAdminError>());
CommandLine c = new CommandLine(cmd);
c.parseArgs("host1", "host2");
cmd.execute(scmClient);
Pattern p = Pattern.compile("^Started\\srecommissioning\\sdatanode\\(s\\)", Pattern.MULTILINE);
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
p = Pattern.compile("^host1$", Pattern.MULTILINE);
m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
p = Pattern.compile("^host2$", Pattern.MULTILINE);
m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
}
use of org.apache.hadoop.hdds.scm.DatanodeAdminError in project ozone by apache.
the class DecommissionSubCommand method execute.
@Override
public void execute(ScmClient scmClient) throws IOException {
if (hosts.size() > 0) {
List<DatanodeAdminError> errors = scmClient.decommissionNodes(hosts);
System.out.println("Started decommissioning datanode(s):\n" + String.join("\n", hosts));
if (errors.size() > 0) {
for (DatanodeAdminError error : errors) {
System.err.println("Error: " + error.getHostname() + ": " + error.getError());
}
// command.
throw new IOException("Some nodes could not enter the decommission workflow");
}
} else {
GenericCli.missingSubcommand(spec);
}
}
Aggregations