-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1487 from kaleido-io/batchcancel
Allow cancelling a batch that is stuck in dispatch
- Loading branch information
Showing
25 changed files
with
1,225 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright © 2024 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package apiserver | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/ffapi" | ||
"github.com/hyperledger/firefly/internal/coremsgs" | ||
) | ||
|
||
var postBatchCancel = &ffapi.Route{ | ||
Name: "postBatchCancel", | ||
Path: "batches/{batchid}/cancel", | ||
Method: http.MethodPost, | ||
PathParams: []*ffapi.PathParam{ | ||
{Name: "batchid", Description: coremsgs.APIParamsBatchID}, | ||
}, | ||
QueryParams: nil, | ||
Description: coremsgs.APIEndpointsPostBatchCancel, | ||
JSONInputValue: nil, | ||
JSONOutputValue: nil, | ||
JSONOutputCodes: []int{http.StatusNoContent}, | ||
Extensions: &coreExtensions{ | ||
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { | ||
return nil, cr.or.BatchManager().CancelBatch(cr.ctx, r.PP["batchid"]) | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright © 2022 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package apiserver | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/fftypes" | ||
"github.com/hyperledger/firefly/mocks/batchmocks" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestPostBatchCancel(t *testing.T) { | ||
o, r := newTestAPIServer() | ||
o.On("Authorize", mock.Anything, mock.Anything).Return(nil) | ||
mbm := &batchmocks.Manager{} | ||
o.On("BatchManager").Return(mbm) | ||
input := fftypes.JSONObject{} | ||
var buf bytes.Buffer | ||
json.NewEncoder(&buf).Encode(&input) | ||
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/batches/batch1/cancel", &buf) | ||
req.Header.Set("Content-Type", "application/json; charset=utf-8") | ||
res := httptest.NewRecorder() | ||
|
||
mbm.On("CancelBatch", mock.Anything, "batch1").Return(nil) | ||
r.ServeHTTP(res, req) | ||
|
||
assert.Equal(t, 204, res.Result().StatusCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.