Search in sources :

Example 1 with PipelinesResponse

use of org.apache.hadoop.ozone.recon.api.types.PipelinesResponse in project ozone by apache.

the class TestEndpoints method testGetPipelines.

@Test
public void testGetPipelines() throws Exception {
    Response response = pipelineEndpoint.getPipelines();
    PipelinesResponse pipelinesResponse = (PipelinesResponse) response.getEntity();
    Assert.assertEquals(1, pipelinesResponse.getTotalCount());
    Assert.assertEquals(1, pipelinesResponse.getPipelines().size());
    PipelineMetadata pipelineMetadata = pipelinesResponse.getPipelines().iterator().next();
    Assert.assertEquals(1, pipelineMetadata.getDatanodes().size());
    Assert.assertEquals(pipeline.getType().toString(), pipelineMetadata.getReplicationType());
    Assert.assertEquals(pipeline.getReplicationConfig().getRequiredNodes(), pipelineMetadata.getReplicationFactor());
    Assert.assertEquals(datanodeDetails.getHostName(), pipelineMetadata.getLeaderNode());
    Assert.assertEquals(pipeline.getId().getId(), pipelineMetadata.getPipelineId());
    Assert.assertEquals(5, pipelineMetadata.getLeaderElections());
    waitAndCheckConditionAfterHeartbeat(() -> {
        Response response1 = pipelineEndpoint.getPipelines();
        PipelinesResponse pipelinesResponse1 = (PipelinesResponse) response1.getEntity();
        PipelineMetadata pipelineMetadata1 = pipelinesResponse1.getPipelines().iterator().next();
        return (pipelineMetadata1.getContainers() == 1);
    });
}
Also used : ClusterStateResponse(org.apache.hadoop.ozone.recon.api.types.ClusterStateResponse) DatanodesResponse(org.apache.hadoop.ozone.recon.api.types.DatanodesResponse) Response(javax.ws.rs.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) PipelinesResponse(org.apache.hadoop.ozone.recon.api.types.PipelinesResponse) PipelineMetadata(org.apache.hadoop.ozone.recon.api.types.PipelineMetadata) PipelinesResponse(org.apache.hadoop.ozone.recon.api.types.PipelinesResponse) Test(org.junit.Test) AbstractReconSqlDBTest(org.apache.hadoop.ozone.recon.persistence.AbstractReconSqlDBTest)

Example 2 with PipelinesResponse

use of org.apache.hadoop.ozone.recon.api.types.PipelinesResponse in project ozone by apache.

the class PipelineEndpoint method getPipelines.

/**
 * Return the list of pipelines with detailed information about each pipeline.
 * @return {@link Response}
 */
@GET
public Response getPipelines() {
    List<PipelineMetadata> pipelinesList = new ArrayList<>();
    List<Pipeline> pipelines = pipelineManager.getPipelines();
    pipelines.forEach(pipeline -> {
        UUID pipelineId = pipeline.getId().getId();
        List<String> datanodes = new ArrayList<>();
        PipelineMetadata.Builder builder = PipelineMetadata.newBuilder();
        pipeline.getNodes().forEach(node -> datanodes.add(node.getHostName()));
        long duration = Instant.now().toEpochMilli() - pipeline.getCreationTimestamp().toEpochMilli();
        try {
            String leaderNode = pipeline.getLeaderNode().getHostName();
            builder.setLeaderNode(leaderNode);
        } catch (IOException ioEx) {
            LOG.warn("Cannot get leader node for pipeline {}", pipelineId, ioEx);
        }
        try {
            int containers = pipelineManager.getNumberOfContainers(pipeline.getId());
            builder.setContainers(containers);
        } catch (IOException ioEx) {
            LOG.warn("Cannot get containers for pipeline {} ", pipelineId, ioEx);
        }
        PipelineMetadata.Builder pipelineBuilder = builder.setPipelineId(pipelineId).setDatanodes(datanodes).setDuration(duration).setStatus(pipeline.getPipelineState()).setReplicationFactor(ReplicationConfig.getLegacyFactor(pipeline.getReplicationConfig()).getNumber()).setReplicationType(pipeline.getType().toString());
        // leader election count and last leader election time
        if (metricsServiceProvider != null) {
            // Extract last part of pipelineId to get its group Id.
            // ex. group id of 48981bf7-8bea-4fbd-9857-79df51ee872d
            // is group-79DF51EE872D
            String[] splits = pipelineId.toString().split("-");
            String groupId = "group-" + splits[splits.length - 1].toUpperCase();
            Optional<Long> leaderElectionCount = getMetricValue("ratis_leader_election_electionCount", groupId);
            leaderElectionCount.ifPresent(pipelineBuilder::setLeaderElections);
            Optional<Long> leaderElectionTime = getMetricValue("ratis_leader_election_lastLeaderElectionTime", groupId);
            leaderElectionTime.ifPresent(pipelineBuilder::setLastLeaderElection);
        }
        pipelinesList.add(pipelineBuilder.build());
    });
    PipelinesResponse pipelinesResponse = new PipelinesResponse(pipelinesList.size(), pipelinesList);
    return Response.ok(pipelinesResponse).build();
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) PipelinesResponse(org.apache.hadoop.ozone.recon.api.types.PipelinesResponse) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) PipelineMetadata(org.apache.hadoop.ozone.recon.api.types.PipelineMetadata) UUID(java.util.UUID) GET(javax.ws.rs.GET)

Aggregations

PipelineMetadata (org.apache.hadoop.ozone.recon.api.types.PipelineMetadata)2 PipelinesResponse (org.apache.hadoop.ozone.recon.api.types.PipelinesResponse)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 Response (javax.ws.rs.core.Response)1 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)1 ClusterStateResponse (org.apache.hadoop.ozone.recon.api.types.ClusterStateResponse)1 DatanodesResponse (org.apache.hadoop.ozone.recon.api.types.DatanodesResponse)1 AbstractReconSqlDBTest (org.apache.hadoop.ozone.recon.persistence.AbstractReconSqlDBTest)1 Test (org.junit.Test)1