Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: rename algo to function #139

Merged
merged 71 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
918fbc8
rename algo to function
ThibaultFy Jan 31, 2023
56e9763
rename algo to function
ThibaultFy Jan 31, 2023
fbf8ed4
rename algo to function
ThibaultFy Jan 31, 2023
f397179
go lint
ThibaultFy Jan 31, 2023
4ceec70
algo to function
ThibaultFy Jan 31, 2023
4c06842
migrations
ThibaultFy Jan 31, 2023
ab653c1
migrations
ThibaultFy Jan 31, 2023
a8e17a0
migrations
ThibaultFy Jan 31, 2023
6b8b16d
migrations
ThibaultFy Jan 31, 2023
cfbd219
migrations
ThibaultFy Jan 31, 2023
acfe95b
migrations
ThibaultFy Jan 31, 2023
6d98434
migrations
ThibaultFy Jan 31, 2023
ba7f0e4
migrations
ThibaultFy Jan 31, 2023
e5818e6
migrations
ThibaultFy Jan 31, 2023
3d43b8b
migrations
ThibaultFy Jan 31, 2023
b0f1c3f
migrations
ThibaultFy Jan 31, 2023
eea5c07
migrations
ThibaultFy Jan 31, 2023
c82f82f
migrations
ThibaultFy Jan 31, 2023
4a6276f
migrations
ThibaultFy Jan 31, 2023
0dbd4b8
migrations
ThibaultFy Jan 31, 2023
1f9caf3
migrations
ThibaultFy Jan 31, 2023
2d4eb06
migrations
ThibaultFy Jan 31, 2023
1b93aa2
rename
ThibaultFy Jan 31, 2023
2b3cacd
migration
ThibaultFy Jan 31, 2023
aeea9e4
migration
ThibaultFy Jan 31, 2023
ae29395
migration
ThibaultFy Jan 31, 2023
8f58e2e
migration
ThibaultFy Jan 31, 2023
a5ecd56
tuple to task
ThibaultFy Feb 1, 2023
4640907
migration
ThibaultFy Feb 1, 2023
314dc3f
migration
ThibaultFy Feb 1, 2023
5d94c7b
doc
ThibaultFy Feb 1, 2023
7a4d191
doc
ThibaultFy Feb 1, 2023
3ac61f4
changelog
ThibaultFy Feb 1, 2023
ea2cb2a
changelog
ThibaultFy Feb 1, 2023
379eb37
migration
ThibaultFy Feb 1, 2023
004c4c4
migration
ThibaultFy Feb 1, 2023
0138085
migration
ThibaultFy Feb 1, 2023
99ac0e9
migration
ThibaultFy Feb 1, 2023
8205b48
migration
ThibaultFy Feb 1, 2023
b945163
migration
ThibaultFy Feb 1, 2023
962d58b
migration
ThibaultFy Feb 1, 2023
e66c353
migration
ThibaultFy Feb 1, 2023
5256c08
migration
ThibaultFy Feb 1, 2023
71c3e60
migration
ThibaultFy Feb 1, 2023
609cd45
migration
ThibaultFy Feb 1, 2023
0bc5db4
migration
ThibaultFy Feb 1, 2023
28e89f4
migration
ThibaultFy Feb 1, 2023
8a8519a
migration
ThibaultFy Feb 1, 2023
bd87812
migration
ThibaultFy Feb 1, 2023
e4b4a30
migration
ThibaultFy Feb 1, 2023
d0f3916
migration
ThibaultFy Feb 1, 2023
40c8862
migration
ThibaultFy Feb 1, 2023
425b87a
migration
ThibaultFy Feb 1, 2023
6f72a34
migration
ThibaultFy Feb 1, 2023
c4c9608
migration
ThibaultFy Feb 1, 2023
ded1bf5
migration
ThibaultFy Feb 1, 2023
7d6d857
migration
ThibaultFy Feb 1, 2023
f50ba9c
migration
ThibaultFy Feb 1, 2023
7cb4be5
migration
ThibaultFy Feb 1, 2023
e408a78
migration
ThibaultFy Feb 1, 2023
25cdff5
rename algo to function
ThibaultFy Feb 2, 2023
66376e9
rename algo to function
ThibaultFy Feb 2, 2023
9a38d09
rename algo to function
ThibaultFy Feb 2, 2023
62904df
rename algo to function
ThibaultFy Feb 2, 2023
138b71e
rename algo to function
ThibaultFy Feb 2, 2023
9d6f08f
fix
ThibaultFy Feb 6, 2023
2f2d365
rename doc
ThibaultFy Feb 7, 2023
5496ab1
changelog
ThibaultFy Feb 9, 2023
3f88b96
alignement
ThibaultFy Feb 10, 2023
e40f521
go fmt
ThibaultFy Feb 10, 2023
b589903
conditions on migrations
ThibaultFy Feb 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]()

### Changed

- BREAKING: rename Algo to Function ([#139](https://github.com/Substra/orchestrator/pull/139))

## [0.32](https://github.com/Substra/orchestrator/releases/tag/0.32.0) - 2023-01-31

### Added
Expand Down
6 changes: 3 additions & 3 deletions chaincode/communication/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (
)

func TestWrapUnwrap(t *testing.T) {
msg := &asset.NewAlgo{Key: "uuid"}
msg := &asset.NewFunction{Key: "uuid"}

wrapped, err := Wrap(context.Background(), msg)
assert.NoError(t, err)

out := new(asset.NewAlgo)
out := new(asset.NewFunction)
err = wrapped.Unwrap(out)
assert.NoError(t, err)
assert.Equal(t, msg, out)

serialized, err := json.Marshal(wrapped)
assert.NoError(t, err)

out = new(asset.NewAlgo)
out = new(asset.NewFunction)
err = Unwrap(serialized, out)
assert.NoError(t, err)
assert.Equal(t, msg, out)
Expand Down
6 changes: 3 additions & 3 deletions chaincode/contracts/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestIsEvaluateMethod(t *testing.T) {
p := NewContractCollection()
assert.True(t, p.IsEvaluateMethod("orchestrator.algo:QueryAlgos"))
assert.False(t, p.IsEvaluateMethod("orchestrator.algo:RegisterAlgo"))
assert.False(t, p.IsEvaluateMethod("orchestrator.algo:DoesntExist"))
assert.True(t, p.IsEvaluateMethod("orchestrator.function:QueryFunctions"))
assert.False(t, p.IsEvaluateMethod("orchestrator.function:RegisterFunction"))
assert.False(t, p.IsEvaluateMethod("orchestrator.function:DoesntExist"))
}
4 changes: 2 additions & 2 deletions chaincode/contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package contracts

import (
"github.com/hyperledger/fabric-contract-api-go/contractapi"
"github.com/substra/orchestrator/chaincode/algo"
"github.com/substra/orchestrator/chaincode/computeplan"
"github.com/substra/orchestrator/chaincode/computetask"
"github.com/substra/orchestrator/chaincode/datamanager"
"github.com/substra/orchestrator/chaincode/datasample"
"github.com/substra/orchestrator/chaincode/dataset"
"github.com/substra/orchestrator/chaincode/event"
"github.com/substra/orchestrator/chaincode/failurereport"
"github.com/substra/orchestrator/chaincode/function"
"github.com/substra/orchestrator/chaincode/info"
"github.com/substra/orchestrator/chaincode/model"
"github.com/substra/orchestrator/chaincode/organization"
Expand All @@ -20,7 +20,7 @@ import (
var AllContracts []contractapi.ContractInterface = []contractapi.ContractInterface{
organization.NewSmartContract(),
datasample.NewSmartContract(),
algo.NewSmartContract(),
function.NewSmartContract(),
datamanager.NewSmartContract(),
dataset.NewSmartContract(),
computetask.NewSmartContract(),
Expand Down
62 changes: 31 additions & 31 deletions chaincode/algo/contract.go → chaincode/function/contract.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package algo
package function

import (
"github.com/hyperledger/fabric-contract-api-go/contractapi"
Expand All @@ -11,7 +11,7 @@ import (
commonserv "github.com/substra/orchestrator/server/common"
)

// SmartContract manages algos
// SmartContract manages functions
type SmartContract struct {
contractapi.Contract
logger zerolog.Logger
Expand All @@ -20,7 +20,7 @@ type SmartContract struct {
// NewSmartContract creates a smart contract to be used in a chaincode
func NewSmartContract() *SmartContract {
contract := &SmartContract{}
contract.Name = "orchestrator.algo"
contract.Name = "orchestrator.function"
contract.TransactionContextHandler = ledger.NewContext()
contract.BeforeTransaction = ledger.GetBeforeTransactionHook(contract)
contract.AfterTransaction = ledger.AfterTransactionHook
Expand All @@ -30,16 +30,16 @@ func NewSmartContract() *SmartContract {
return contract
}

// RegisterAlgo creates a new algo in world state
// RegisterFunction creates a new function in world state
// If the key exists, it will override the existing value with the new one
func (s *SmartContract) RegisterAlgo(ctx ledger.TransactionContext, wrapper *communication.Wrapper) (*communication.Wrapper, error) {
func (s *SmartContract) RegisterFunction(ctx ledger.TransactionContext, wrapper *communication.Wrapper) (*communication.Wrapper, error) {
provider, err := ctx.GetProvider()
if err != nil {
return nil, err
}
service := provider.GetAlgoService()
service := provider.GetFunctionService()

params := new(asset.NewAlgo)
params := new(asset.NewFunction)
err = wrapper.Unwrap(params)
if err != nil {
s.logger.Error().Err(err).Msg("failed to unwrap param")
Expand All @@ -52,9 +52,9 @@ func (s *SmartContract) RegisterAlgo(ctx ledger.TransactionContext, wrapper *com
return nil, err
}

a, err := service.RegisterAlgo(params, owner)
a, err := service.RegisterFunction(params, owner)
if err != nil {
s.logger.Error().Err(err).Msg("failed to register algo")
s.logger.Error().Err(err).Msg("failed to register function")
return nil, err
}
response, err := communication.Wrap(ctx.GetContext(), a)
Expand All @@ -65,58 +65,58 @@ func (s *SmartContract) RegisterAlgo(ctx ledger.TransactionContext, wrapper *com
return response, nil
}

// GetAlgo returns the algo with given key
func (s *SmartContract) GetAlgo(ctx ledger.TransactionContext, wrapper *communication.Wrapper) (*communication.Wrapper, error) {
// GetFunction returns the function with given key
func (s *SmartContract) GetFunction(ctx ledger.TransactionContext, wrapper *communication.Wrapper) (*communication.Wrapper, error) {
provider, err := ctx.GetProvider()
if err != nil {
return nil, err
}
service := provider.GetAlgoService()
service := provider.GetFunctionService()

params := new(asset.GetAlgoParam)
params := new(asset.GetFunctionParam)
err = wrapper.Unwrap(params)
if err != nil {
s.logger.Error().Err(err).Msg("failed to unwrap param")
return nil, err
}

algo, err := service.GetAlgo(params.GetKey())
function, err := service.GetFunction(params.GetKey())
if err != nil {
s.logger.Error().Err(err).Msg("failed to query algo")
s.logger.Error().Err(err).Msg("failed to query function")
return nil, err
}

wrapped, err := communication.Wrap(ctx.GetContext(), algo)
wrapped, err := communication.Wrap(ctx.GetContext(), function)
if err != nil {
s.logger.Error().Err(err).Msg("failed to wrap response")
return nil, err
}
return wrapped, nil
}

// QueryAlgos returns the algos
func (s *SmartContract) QueryAlgos(ctx ledger.TransactionContext, wrapper *communication.Wrapper) (*communication.Wrapper, error) {
// QueryFunctions returns the functions
func (s *SmartContract) QueryFunctions(ctx ledger.TransactionContext, wrapper *communication.Wrapper) (*communication.Wrapper, error) {
provider, err := ctx.GetProvider()
if err != nil {
return nil, err
}
service := provider.GetAlgoService()
service := provider.GetFunctionService()

params := new(asset.QueryAlgosParam)
params := new(asset.QueryFunctionsParam)
err = wrapper.Unwrap(params)
if err != nil {
s.logger.Error().Err(err).Msg("failed to unwrap param")
return nil, err
}

algos, nextPage, err := service.QueryAlgos(&common.Pagination{Token: params.GetPageToken(), Size: params.GetPageSize()}, params.Filter)
functions, nextPage, err := service.QueryFunctions(&common.Pagination{Token: params.GetPageToken(), Size: params.GetPageSize()}, params.Filter)
if err != nil {
s.logger.Error().Err(err).Msg("failed to query algos")
s.logger.Error().Err(err).Msg("failed to query functions")
return nil, err
}

resp := &asset.QueryAlgosResponse{
Algos: algos,
resp := &asset.QueryFunctionsResponse{
Functions: functions,
NextPageToken: nextPage,
}

Expand All @@ -128,16 +128,16 @@ func (s *SmartContract) QueryAlgos(ctx ledger.TransactionContext, wrapper *commu
return wrapped, nil
}

// UpdateAlgo updates an algo in world state
// UpdateFunction updates an function in world state
// If the key does not exist, it will throw an error
func (s *SmartContract) UpdateAlgo(ctx ledger.TransactionContext, wrapper *communication.Wrapper) error {
func (s *SmartContract) UpdateFunction(ctx ledger.TransactionContext, wrapper *communication.Wrapper) error {
provider, err := ctx.GetProvider()
if err != nil {
return err
}
service := provider.GetAlgoService()
service := provider.GetFunctionService()

params := new(asset.UpdateAlgoParam)
params := new(asset.UpdateFunctionParam)
err = wrapper.Unwrap(params)
if err != nil {
s.logger.Error().Err(err).Msg("failed to unwrap param")
Expand All @@ -150,9 +150,9 @@ func (s *SmartContract) UpdateAlgo(ctx ledger.TransactionContext, wrapper *commu
return err
}

err = service.UpdateAlgo(params, requester)
err = service.UpdateFunction(params, requester)
if err != nil {
s.logger.Error().Err(err).Msg("failed to update algo")
s.logger.Error().Err(err).Msg("failed to update function")
return err
}

Expand All @@ -161,5 +161,5 @@ func (s *SmartContract) UpdateAlgo(ctx ledger.TransactionContext, wrapper *commu

// GetEvaluateTransactions returns functions of SmartContract not to be tagged as submit
func (s *SmartContract) GetEvaluateTransactions() []string {
return commonserv.ReadOnlyMethods["Algo"]
return commonserv.ReadOnlyMethods["Function"]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package algo
package function

import (
"context"
Expand All @@ -15,11 +15,11 @@ import (
)

// getMockedService returns a service mocks and make sure the provider returns the mock as well.
func getMockedService(ctx *ledger.MockTransactionContext) *service.MockAlgoAPI {
mockService := new(service.MockAlgoAPI)
func getMockedService(ctx *ledger.MockTransactionContext) *service.MockFunctionAPI {
mockService := new(service.MockFunctionAPI)

provider := new(service.MockDependenciesProvider)
provider.On("GetAlgoService").Return(mockService).Once()
provider.On("GetFunctionService").Return(mockService).Once()

ctx.On("GetProvider").Return(provider, nil).Once()
ctx.On("GetContext").Return(context.Background())
Expand All @@ -36,94 +36,94 @@ func TestRegistration(t *testing.T) {

mspid := "org"

newObj := &asset.NewAlgo{
newObj := &asset.NewFunction{
Key: "uuid1",
Name: "Algo name",
Name: "Function name",
Description: addressable,
Algorithm: addressable,
Function: addressable,
Metadata: metadata,
NewPermissions: newPerms,
}

params, err := communication.Wrap(context.Background(), newObj)
assert.NoError(t, err)

a := &asset.Algo{}
a := &asset.Function{}

ctx := new(ledger.MockTransactionContext)

service := getMockedService(ctx)
service.On("RegisterAlgo", newObj, mspid).Return(a, nil).Once()
service.On("RegisterFunction", newObj, mspid).Return(a, nil).Once()

stub := new(testHelper.MockedStub)
ctx.On("GetStub").Return(stub).Once()

stub.On("GetCreator").Return(testHelper.FakeTxCreator(t, mspid), nil).Once()

_, err = contract.RegisterAlgo(ctx, params)
_, err = contract.RegisterFunction(ctx, params)
assert.NoError(t, err)
}

func TestQueryAlgos(t *testing.T) {
func TestQueryFunctions(t *testing.T) {
contract := &SmartContract{}

computePlanKey := uuid.NewString()

algos := []*asset.Algo{
functions := []*asset.Function{
{Name: "test"},
{Name: "test2"},
}

filter := &asset.AlgoQueryFilter{
filter := &asset.FunctionQueryFilter{
ComputePlanKey: computePlanKey,
}

ctx := new(ledger.MockTransactionContext)
service := getMockedService(ctx)
service.On("QueryAlgos", &common.Pagination{Token: "", Size: 20}, filter).Return(algos, "", nil).Once()
service.On("QueryFunctions", &common.Pagination{Token: "", Size: 20}, filter).Return(functions, "", nil).Once()

param := &asset.QueryAlgosParam{Filter: filter, PageToken: "", PageSize: 20}
param := &asset.QueryFunctionsParam{Filter: filter, PageToken: "", PageSize: 20}
wrapper, err := communication.Wrap(context.Background(), param)
assert.NoError(t, err)

wrapped, err := contract.QueryAlgos(ctx, wrapper)
wrapped, err := contract.QueryFunctions(ctx, wrapper)
assert.NoError(t, err, "query should not fail")
resp := new(asset.QueryAlgosResponse)
resp := new(asset.QueryFunctionsResponse)
err = wrapped.Unwrap(resp)
assert.NoError(t, err)
assert.Len(t, resp.Algos, len(algos), "query should return all algos")
assert.Len(t, resp.Functions, len(functions), "query should return all functions")
}

func TestUpdate(t *testing.T) {
contract := &SmartContract{}

mspid := "org"
updateAlgoParam := &asset.UpdateAlgoParam{
updateFunctionParam := &asset.UpdateFunctionParam{
Key: "4c67ad88-309a-48b4-8bc4-c2e2c1a87a83",
Name: "Updated algo name",
Name: "Updated function name",
}
wrapper, err := communication.Wrap(context.Background(), updateAlgoParam)
wrapper, err := communication.Wrap(context.Background(), updateFunctionParam)
assert.NoError(t, err)

ctx := new(ledger.MockTransactionContext)

service := getMockedService(ctx)
service.On("UpdateAlgo", updateAlgoParam, mspid).Return(nil).Once()
service.On("UpdateFunction", updateFunctionParam, mspid).Return(nil).Once()

stub := new(testHelper.MockedStub)
ctx.On("GetStub").Return(stub).Once()
stub.On("GetCreator").Return(testHelper.FakeTxCreator(t, mspid), nil).Once()

err = contract.UpdateAlgo(ctx, wrapper)
err = contract.UpdateFunction(ctx, wrapper)
assert.NoError(t, err, "Smart contract execution should not fail")
}

func TestEvaluateTransactions(t *testing.T) {
contract := &SmartContract{}

queries := []string{
"GetAlgo",
"QueryAlgos",
"GetFunction",
"QueryFunctions",
}

assert.Equal(t, queries, contract.GetEvaluateTransactions(), "All non-commit transactions should be flagged")
Expand Down
4 changes: 2 additions & 2 deletions chaincode/ledger/dbal_computetask.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ func (db *DB) QueryComputeTasks(p *common.Pagination, filter *asset.TaskQueryFil
if filter.ComputePlanKey != "" {
assetFilter["compute_plan_key"] = filter.ComputePlanKey
}
if filter.AlgoKey != "" {
assetFilter["algo_key"] = json.RawMessage(fmt.Sprintf(`{"key": "%s"}`, filter.AlgoKey))
if filter.FunctionKey != "" {
assetFilter["function_key"] = json.RawMessage(fmt.Sprintf(`{"key": "%s"}`, filter.FunctionKey))
}

if len(assetFilter) > 0 {
Expand Down
Loading