Search in sources :

Example 1 with ScmClient

use of org.apache.hadoop.hdds.scm.client.ScmClient in project ozone by apache.

the class TestInfoSubCommand method testReplicasIncludedInOutput.

@Test
public void testReplicasIncludedInOutput() throws Exception {
    Mockito.when(scmClient.getContainerReplicas(anyLong())).thenReturn(getReplicas());
    cmd = new InfoSubcommand();
    CommandLine c = new CommandLine(cmd);
    c.parseArgs("1");
    cmd.execute(scmClient);
    // Ensure we have a line for Replicas:
    List<LoggingEvent> logs = appender.getLog();
    List<LoggingEvent> replica = logs.stream().filter(m -> m.getRenderedMessage().matches("(?s)^Replicas:.*")).collect(Collectors.toList());
    Assert.assertEquals(1, replica.size());
    // Ensure each DN UUID is mentioned in the message:
    for (DatanodeDetails dn : datanodes) {
        Pattern pattern = Pattern.compile(".*" + dn.getUuid().toString() + ".*", Pattern.DOTALL);
        Matcher matcher = pattern.matcher(replica.get(0).getRenderedMessage());
        Assert.assertTrue(matcher.matches());
    }
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) ContainerReplicaInfo(org.apache.hadoop.hdds.scm.container.ContainerReplicaInfo) HddsProtos(org.apache.hadoop.hdds.protocol.proto.HddsProtos) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AppenderSkeleton(org.apache.log4j.AppenderSkeleton) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger) Matcher(java.util.regex.Matcher) Level(org.apache.log4j.Level) After(org.junit.After) CommandLine(picocli.CommandLine) Before(org.junit.Before) ScmClient(org.apache.hadoop.hdds.scm.client.ScmClient) RatisReplicationConfig(org.apache.hadoop.hdds.client.RatisReplicationConfig) CLOSED(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.CLOSED) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) LoggingEvent(org.apache.log4j.spi.LoggingEvent) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Test(org.junit.Test) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) List(java.util.List) PipelineID(org.apache.hadoop.hdds.scm.pipeline.PipelineID) THREE(org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.THREE) Pattern(java.util.regex.Pattern) Assert(org.junit.Assert) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) Mockito.mock(org.mockito.Mockito.mock) Pattern(java.util.regex.Pattern) CommandLine(picocli.CommandLine) Matcher(java.util.regex.Matcher) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) Test(org.junit.Test)

Example 2 with ScmClient

use of org.apache.hadoop.hdds.scm.client.ScmClient in project ozone by apache.

the class TestReportSubCommand method testCorrectValuesAppearInEmptyReport.

@Test
public void testCorrectValuesAppearInEmptyReport() throws IOException {
    ScmClient scmClient = mock(ScmClient.class);
    Mockito.when(scmClient.getReplicationManagerReport()).thenAnswer(invocation -> new ReplicationManagerReport());
    cmd.execute(scmClient);
    for (HddsProtos.LifeCycleState state : HddsProtos.LifeCycleState.values()) {
        Pattern p = Pattern.compile("^" + state.toString() + ": 0$", Pattern.MULTILINE);
        Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
        assertTrue(m.find());
    }
    for (ReplicationManagerReport.HealthState state : ReplicationManagerReport.HealthState.values()) {
        Pattern p = Pattern.compile("^" + state.toString() + ": 0$", Pattern.MULTILINE);
        Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
        assertTrue(m.find());
    }
}
Also used : Pattern(java.util.regex.Pattern) HddsProtos(org.apache.hadoop.hdds.protocol.proto.HddsProtos) Matcher(java.util.regex.Matcher) ScmClient(org.apache.hadoop.hdds.scm.client.ScmClient) ReplicationManagerReport(org.apache.hadoop.hdds.scm.container.ReplicationManagerReport) Test(org.junit.jupiter.api.Test)

Example 3 with ScmClient

use of org.apache.hadoop.hdds.scm.client.ScmClient in project ozone by apache.

the class TestReportSubCommand method testValidJsonOutput.

@Test
public void testValidJsonOutput() throws IOException {
    // More complete testing of the Report JSON output is in
    // TestReplicationManagerReport.
    ScmClient scmClient = mock(ScmClient.class);
    Mockito.when(scmClient.getReplicationManagerReport()).thenAnswer(invocation -> new ReplicationManagerReport());
    CommandLine c = new CommandLine(cmd);
    c.parseArgs("--json");
    cmd.execute(scmClient);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode json = mapper.readTree(outContent.toString("UTF-8"));
    assertNotNull(json.get("reportTimeStamp"));
    assertNotNull(json.get("stats"));
    assertNotNull(json.get("samples"));
}
Also used : CommandLine(picocli.CommandLine) JsonNode(com.fasterxml.jackson.databind.JsonNode) ScmClient(org.apache.hadoop.hdds.scm.client.ScmClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReplicationManagerReport(org.apache.hadoop.hdds.scm.container.ReplicationManagerReport) Test(org.junit.jupiter.api.Test)

Example 4 with ScmClient

use of org.apache.hadoop.hdds.scm.client.ScmClient in project ozone by apache.

the class TestReportSubCommand method testCorrectValuesAppearInReport.

@Test
public void testCorrectValuesAppearInReport() throws IOException {
    ScmClient scmClient = mock(ScmClient.class);
    Mockito.when(scmClient.getReplicationManagerReport()).thenAnswer(invocation -> createReport());
    cmd.execute(scmClient);
    int counter = SEED;
    for (HddsProtos.LifeCycleState state : HddsProtos.LifeCycleState.values()) {
        Pattern p = Pattern.compile("^" + state.toString() + ": " + counter + "$", Pattern.MULTILINE);
        Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
        assertTrue(m.find());
        counter++;
    }
    counter = SEED;
    for (ReplicationManagerReport.HealthState state : ReplicationManagerReport.HealthState.values()) {
        Pattern p = Pattern.compile("^" + state.toString() + ": " + counter + "$", Pattern.MULTILINE);
        Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
        assertTrue(m.find());
        // Check the correct samples are returned
        p = Pattern.compile("^First 100 " + state + " containers:\n" + containerList(0, counter) + "$", Pattern.MULTILINE);
        m = p.matcher(outContent.toString(DEFAULT_ENCODING));
        assertTrue(m.find());
        counter++;
    }
}
Also used : Pattern(java.util.regex.Pattern) HddsProtos(org.apache.hadoop.hdds.protocol.proto.HddsProtos) Matcher(java.util.regex.Matcher) ScmClient(org.apache.hadoop.hdds.scm.client.ScmClient) ReplicationManagerReport(org.apache.hadoop.hdds.scm.container.ReplicationManagerReport) Test(org.junit.jupiter.api.Test)

Example 5 with ScmClient

use of org.apache.hadoop.hdds.scm.client.ScmClient in project ozone by apache.

the class TestContainerBalancerSubCommand method testContainerBalancerStatusSubcommandNotRunning.

@Test
public void testContainerBalancerStatusSubcommandNotRunning() throws IOException {
    ScmClient scmClient = mock(ScmClient.class);
    Mockito.when(scmClient.getContainerBalancerStatus()).thenAnswer(invocation -> false);
    statusCmd.execute(scmClient);
    Pattern p = Pattern.compile("^ContainerBalancer\\sis\\sNot\\sRunning.");
    Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
    assertTrue(m.find());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ScmClient(org.apache.hadoop.hdds.scm.client.ScmClient) Test(org.junit.jupiter.api.Test)

Aggregations

ScmClient (org.apache.hadoop.hdds.scm.client.ScmClient)23 Test (org.junit.jupiter.api.Test)19 Matcher (java.util.regex.Matcher)17 Pattern (java.util.regex.Pattern)17 CommandLine (picocli.CommandLine)11 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 HddsProtos (org.apache.hadoop.hdds.protocol.proto.HddsProtos)6 DatanodeAdminError (org.apache.hadoop.hdds.scm.DatanodeAdminError)6 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)4 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)4 List (java.util.List)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 RatisReplicationConfig (org.apache.hadoop.hdds.client.RatisReplicationConfig)3 CLOSED (org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.CLOSED)3 THREE (org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.THREE)3 ContainerInfo (org.apache.hadoop.hdds.scm.container.ContainerInfo)3 ContainerReplicaInfo (org.apache.hadoop.hdds.scm.container.ContainerReplicaInfo)3 ReplicationManagerReport (org.apache.hadoop.hdds.scm.container.ReplicationManagerReport)3