|
@@ -136,11 +136,13 @@ public final class Pipeline {
|
|
|
return nodeStatus.isEmpty();
|
|
|
}
|
|
|
|
|
|
- public HddsProtos.Pipeline getProtobufMessage() {
|
|
|
+ public HddsProtos.Pipeline getProtobufMessage()
|
|
|
+ throws UnknownPipelineStateException {
|
|
|
HddsProtos.Pipeline.Builder builder = HddsProtos.Pipeline.newBuilder()
|
|
|
.setId(id.getProtobuf())
|
|
|
.setType(type)
|
|
|
.setFactor(factor)
|
|
|
+ .setState(PipelineState.getProtobuf(state))
|
|
|
.setLeaderID("")
|
|
|
.addAllMembers(nodeStatus.keySet().stream()
|
|
|
.map(DatanodeDetails::getProtoBufMessage)
|
|
@@ -148,11 +150,13 @@ public final class Pipeline {
|
|
|
return builder.build();
|
|
|
}
|
|
|
|
|
|
- public static Pipeline getFromProtobuf(HddsProtos.Pipeline pipeline) {
|
|
|
+ public static Pipeline getFromProtobuf(HddsProtos.Pipeline pipeline)
|
|
|
+ throws UnknownPipelineStateException {
|
|
|
+ Preconditions.checkNotNull(pipeline, "Pipeline is null");
|
|
|
return new Builder().setId(PipelineID.getFromProtobuf(pipeline.getId()))
|
|
|
.setFactor(pipeline.getFactor())
|
|
|
.setType(pipeline.getType())
|
|
|
- .setState(PipelineState.ALLOCATED)
|
|
|
+ .setState(PipelineState.fromProtobuf(pipeline.getState()))
|
|
|
.setNodes(pipeline.getMembersList().stream()
|
|
|
.map(DatanodeDetails::getFromProtoBuf).collect(Collectors.toList()))
|
|
|
.build();
|
|
@@ -270,6 +274,32 @@ public final class Pipeline {
|
|
|
* Possible Pipeline states in SCM.
|
|
|
*/
|
|
|
public enum PipelineState {
|
|
|
- ALLOCATED, OPEN, CLOSED
|
|
|
+ ALLOCATED, OPEN, CLOSED;
|
|
|
+
|
|
|
+ public static PipelineState fromProtobuf(HddsProtos.PipelineState state)
|
|
|
+ throws UnknownPipelineStateException {
|
|
|
+ Preconditions.checkNotNull(state, "Pipeline state is null");
|
|
|
+ switch (state) {
|
|
|
+ case PIPELINE_ALLOCATED: return ALLOCATED;
|
|
|
+ case PIPELINE_OPEN: return OPEN;
|
|
|
+ case PIPELINE_CLOSED: return CLOSED;
|
|
|
+ default:
|
|
|
+ throw new UnknownPipelineStateException(
|
|
|
+ "Pipeline state: " + state + " is not recognized.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static HddsProtos.PipelineState getProtobuf(PipelineState state)
|
|
|
+ throws UnknownPipelineStateException {
|
|
|
+ Preconditions.checkNotNull(state, "Pipeline state is null");
|
|
|
+ switch (state) {
|
|
|
+ case ALLOCATED: return HddsProtos.PipelineState.PIPELINE_ALLOCATED;
|
|
|
+ case OPEN: return HddsProtos.PipelineState.PIPELINE_OPEN;
|
|
|
+ case CLOSED: return HddsProtos.PipelineState.PIPELINE_CLOSED;
|
|
|
+ default:
|
|
|
+ throw new UnknownPipelineStateException(
|
|
|
+ "Pipeline state: " + state + " is not recognized.");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|