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);
});
}
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();
}
Aggregations