Skip to content

Commit

Permalink
Move ab Status codes to common
Browse files Browse the repository at this point in the history
In order to have consistent error reporting across the fabric, it has
been decided to use standard HTTP status codes.  These were defined in
the orderer ab.proto, but have wider applicability.

This changeset removes the Status message from ab.proto and moves it to
common.proto.

Change-Id: I511bcdd0442e9b06daba678763c87f32478377f4
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Nov 10, 2016
1 parent bc358a5 commit 492f2ad
Show file tree
Hide file tree
Showing 25 changed files with 246 additions and 246 deletions.
57 changes: 54 additions & 3 deletions bddtests/common/common_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 14 additions & 66 deletions bddtests/orderer/ab_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion core/committer/noopssinglechain/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/committer"
"github.com/hyperledger/fabric/core/ledger/kvledger"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
putils "github.com/hyperledger/fabric/protos/utils"
"golang.org/x/net/context"
Expand Down Expand Up @@ -127,7 +128,7 @@ func (r *deliverClient) readUntilClose() {

switch t := msg.Type.(type) {
case *ab.DeliverResponse_Error:
if t.Error == ab.Status_SUCCESS {
if t.Error == cb.Status_SUCCESS {
fmt.Println("ERROR! Received success in error field")
return
}
Expand Down
2 changes: 1 addition & 1 deletion orderer/kafka/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (b *broadcasterImpl) recvRequests(stream ab.AtomicBroadcast_BroadcastServer
}

b.batchChan <- msg
reply.Status = ab.Status_SUCCESS // TODO This shouldn't always be a success
reply.Status = cb.Status_SUCCESS // TODO This shouldn't always be a success

if err := stream.Send(reply); err != nil {
logger.Info("Cannot send broadcast reply to client")
Expand Down
3 changes: 1 addition & 2 deletions orderer/kafka/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
)

func TestBroadcastInit(t *testing.T) {
Expand Down Expand Up @@ -81,7 +80,7 @@ func TestBroadcastResponse(t *testing.T) {
for {
select {
case reply := <-mbs.outgoing:
if reply.Status != ab.Status_SUCCESS {
if reply.Status != cb.Status_SUCCESS {
t.Fatal("Client should have received a SUCCESS reply")
}
return
Expand Down
8 changes: 4 additions & 4 deletions orderer/kafka/client_deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ func (cd *clientDelivererImpl) sendBlocks(stream ab.AtomicBroadcast_DeliverServe
err = cd.processACK(t)
}
if err != nil {
var errorStatus ab.Status
var errorStatus cb.Status
// TODO Will need to flesh this out into
// a proper error handling system eventually.
switch err.Error() {
case seekOutOfRangeError:
errorStatus = ab.Status_NOT_FOUND
errorStatus = cb.Status_NOT_FOUND
case ackOutOfRangeError, windowOutOfRangeError:
errorStatus = ab.Status_BAD_REQUEST
errorStatus = cb.Status_BAD_REQUEST
default:
errorStatus = ab.Status_SERVICE_UNAVAILABLE
errorStatus = cb.Status_SERVICE_UNAVAILABLE
}
reply = new(ab.DeliverResponse)
reply.Type = &ab.DeliverResponse_Error{Error: errorStatus}
Expand Down
2 changes: 1 addition & 1 deletion orderer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func retrieveConfiguration(rl rawledger.Reader) *cb.ConfigurationEnvelope {
select {
case <-it.ReadyChan():
block, status := it.Next()
if status != ab.Status_SUCCESS {
if status != cb.Status_SUCCESS {
panic(fmt.Errorf("Error parsing blockchain at startup: %v", status))
}
// ConfigTxs should always be by themselves
Expand Down
8 changes: 4 additions & 4 deletions orderer/rawledger/blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func getBlock(number uint64, li ReadWriter) *cb.Block {
select {
case <-i.ReadyChan():
block, status := i.Next()
if status != ab.Status_SUCCESS {
if status != cb.Status_SUCCESS {
return nil
}
return block
Expand Down Expand Up @@ -155,7 +155,7 @@ func testRetrieval(lf ledgerFactory, t *testing.T) {
t.Fatalf("Should be ready for block read")
}
block, status := it.Next()
if status != ab.Status_SUCCESS {
if status != cb.Status_SUCCESS {
t.Fatalf("Expected to successfully read the genesis block")
}
if block.Header.Number != 0 {
Expand All @@ -168,7 +168,7 @@ func testRetrieval(lf ledgerFactory, t *testing.T) {
t.Fatalf("Should still be ready for block read")
}
block, status = it.Next()
if status != ab.Status_SUCCESS {
if status != cb.Status_SUCCESS {
t.Fatalf("Expected to successfully read the second block")
}
if block.Header.Number != 1 {
Expand Down Expand Up @@ -199,7 +199,7 @@ func testBlockedRetrieval(lf ledgerFactory, t *testing.T) {
t.Fatalf("Should now be ready for block read")
}
block, status := it.Next()
if status != ab.Status_SUCCESS {
if status != cb.Status_SUCCESS {
t.Fatalf("Expected to successfully read the second block")
}
if block.Header.Number != 1 {
Expand Down
6 changes: 3 additions & 3 deletions orderer/rawledger/fileledger/fileledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,16 @@ func (fl *fileLedger) Iterator(startType ab.SeekInfo_StartType, specified uint64
}

// Next blocks until there is a new block available, or returns an error if the next block is no longer retrievable
func (cu *cursor) Next() (*cb.Block, ab.Status) {
func (cu *cursor) Next() (*cb.Block, cb.Status) {
// This only loops once, as signal reading indicates the new block has been written
for {
block, found := cu.fl.readBlock(cu.blockNumber)
if found {
if block == nil {
return nil, ab.Status_SERVICE_UNAVAILABLE
return nil, cb.Status_SERVICE_UNAVAILABLE
}
cu.blockNumber++
return block, ab.Status_SUCCESS
return block, cb.Status_SUCCESS
}
<-cu.fl.signal
}
Expand Down
6 changes: 3 additions & 3 deletions orderer/rawledger/fileledger/fileledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestRetrieval(t *testing.T) {
t.Fatalf("Should be ready for block read")
}
block, status := it.Next()
if status != ab.Status_SUCCESS {
if status != cb.Status_SUCCESS {
t.Fatalf("Expected to successfully read the genesis block")
}
if block.Header.Number != 0 {
Expand All @@ -135,7 +135,7 @@ func TestRetrieval(t *testing.T) {
t.Fatalf("Should still be ready for block read")
}
block, status = it.Next()
if status != ab.Status_SUCCESS {
if status != cb.Status_SUCCESS {
t.Fatalf("Expected to successfully read the second block")
}
if block.Header.Number != 1 {
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestBlockedRetrieval(t *testing.T) {
t.Fatalf("Should now be ready for block read")
}
block, status := it.Next()
if status != ab.Status_SUCCESS {
if status != cb.Status_SUCCESS {
t.Fatalf("Expected to successfully read the second block")
}
if block.Header.Number != 1 {
Expand Down
Loading

0 comments on commit 492f2ad

Please sign in to comment.