mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
NOISSUE - Implement State-machine (#16)
* add state machine Signed-off-by: SammyOina <sammyoina@gmail.com> * This commit addresses the following changes: - In agent/service.go: - Added a goroutine to start the StateMachine - Sent the start event to the StateMachine - In agent/state.go: - Added a copyright notice and license identifier These changes ensure that the StateMachine starts correctly and that the agent/state.go file includes the necessary copyright and license information. Signed-off-by: SammyOina <sammyoina@gmail.com> * Fix race condition in agent service initialization The commit fixes a race condition in the agent service initialization. Previously, the `New` function in `agent/service.go` would start the state machine goroutine before initializing the `sm` field. This could lead to a race condition where the state machine would access uninitialized fields. To fix this, the `New` function now takes a `context.Context` argument and passes it to the `Start` method of the state machine. Additionally, a `sync.Mutex` has been added to the `StateMachine` struct to ensure thread safety. This commit addresses the race condition and ensures proper initialization of the agent service. Signed-off-by: SammyOina <sammyoina@gmail.com> * Fix sending events when algorithms and datasets are received This commit fixes a bug where events were not being sent when algorithms and datasets were received in the agent service. The bug was causing the events to not be triggered, leading to incorrect behavior. This commit adds the necessary code to send the events when algorithms and datasets are received, ensuring that the events are properly triggered. Signed-off-by: SammyOina <sammyoina@gmail.com> * Fix bug: computation results not ready The computation results were not being marked as ready, resulting in an error when trying to access them. This commit fixes the issue by adding a check for the computation results before returning them. Signed-off-by: SammyOina <sammyoina@gmail.com> * Fix bug in agent service and state The commit fixes a bug in the agent service and state files. Previously, the condition to check the state in the agent service was incorrect. It was checking the state directly instead of using the GetState() method. This has been fixed by using the GetState() method to check the state. Additionally, a new GetState() method has been added to the StateMachine struct in the state file. This method retrieves the current state by acquiring a lock and returning the state value. The changes have been tested and verified to resolve the bug and improve the accuracy of state checking in the agent service. Signed-off-by: SammyOina <sammyoina@gmail.com> * check for time outs Signed-off-by: SammyOina <sammyoina@gmail.com> * Fix bug in agent state machine The bug in the agent state machine caused an error when attempting an invalid transition. This commit fixes the bug by properly locking and unlocking the state machine before and after transitioning to the next state. Additionally, the logger now correctly logs the current and next state during a valid transition. Signed-off-by: SammyOina <sammyoina@gmail.com> * Fix race condition in state machine The commit fixes a race condition in the state machine implementation in the `Start` method. The race condition occurs when multiple goroutines try to access and modify the state concurrently. To fix this, a mutex lock and unlock are added around the critical sections of code to ensure exclusive access to the state variable. This prevents race conditions and ensures the state transitions are executed correctly. Signed-off-by: SammyOina <sammyoina@gmail.com> * Fix race condition in StateMachine.Start() The StateMachine.Start() method was experiencing a race condition when multiple events were being processed concurrently. This was caused by not properly locking and unlocking the state machine before and after updating the state. This commit fixes the issue by adding proper locking and unlocking around the state update operation. Additionally, the logging statement has been updated to include the previous and next states for better debugging. Signed-off-by: SammyOina <sammyoina@gmail.com> --------- Signed-off-by: SammyOina <sammyoina@gmail.com>
This commit is contained in:
committed by
GitHub
parent
4eea9c1a4c
commit
4958f9468f
+22
-4
@@ -124,6 +124,7 @@ type AlgoRequest struct {
|
||||
|
||||
Algorithm []byte `protobuf:"bytes,1,opt,name=algorithm,proto3" json:"algorithm,omitempty"`
|
||||
Provider string `protobuf:"bytes,2,opt,name=provider,proto3" json:"provider,omitempty"`
|
||||
Id string `protobuf:"bytes,3,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *AlgoRequest) Reset() {
|
||||
@@ -172,6 +173,13 @@ func (x *AlgoRequest) GetProvider() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AlgoRequest) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type AlgoResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -226,6 +234,7 @@ type DataRequest struct {
|
||||
|
||||
Dataset []byte `protobuf:"bytes,1,opt,name=dataset,proto3" json:"dataset,omitempty"`
|
||||
Provider string `protobuf:"bytes,2,opt,name=provider,proto3" json:"provider,omitempty"`
|
||||
Id string `protobuf:"bytes,3,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *DataRequest) Reset() {
|
||||
@@ -274,6 +283,13 @@ func (x *DataRequest) GetProvider() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *DataRequest) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type DataResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -510,19 +526,21 @@ var file_agent_agent_proto_rawDesc = []byte{
|
||||
0x6f, 0x6d, 0x70, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x2f, 0x0a, 0x0b, 0x52, 0x75,
|
||||
0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x43, 0x6f, 0x6d,
|
||||
0x70, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b,
|
||||
0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x47, 0x0a, 0x0b, 0x41,
|
||||
0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x57, 0x0a, 0x0b, 0x41,
|
||||
0x6c, 0x67, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x61, 0x6c,
|
||||
0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x61,
|
||||
0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76,
|
||||
0x69, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76,
|
||||
0x69, 0x64, 0x65, 0x72, 0x22, 0x30, 0x0a, 0x0c, 0x41, 0x6c, 0x67, 0x6f, 0x52, 0x65, 0x73, 0x70,
|
||||
0x69, 0x64, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x02, 0x69, 0x64, 0x22, 0x30, 0x0a, 0x0c, 0x41, 0x6c, 0x67, 0x6f, 0x52, 0x65, 0x73, 0x70,
|
||||
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x61, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68,
|
||||
0x6d, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x6c, 0x67, 0x6f, 0x72,
|
||||
0x69, 0x74, 0x68, 0x6d, 0x49, 0x44, 0x22, 0x43, 0x0a, 0x0b, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65,
|
||||
0x69, 0x74, 0x68, 0x6d, 0x49, 0x44, 0x22, 0x53, 0x0a, 0x0b, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x61, 0x74, 0x61, 0x73, 0x65, 0x74,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x64, 0x61, 0x74, 0x61, 0x73, 0x65, 0x74, 0x12,
|
||||
0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x22, 0x2c, 0x0a, 0x0c, 0x44,
|
||||
0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69,
|
||||
0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2c, 0x0a, 0x0c, 0x44,
|
||||
0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64,
|
||||
0x61, 0x74, 0x61, 0x73, 0x65, 0x74, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09,
|
||||
0x64, 0x61, 0x74, 0x61, 0x73, 0x65, 0x74, 0x49, 0x44, 0x22, 0x2b, 0x0a, 0x0d, 0x52, 0x65, 0x73,
|
||||
|
||||
@@ -22,6 +22,7 @@ message RunResponse { string Computation = 1; }
|
||||
message AlgoRequest {
|
||||
bytes algorithm = 1;
|
||||
string provider = 2;
|
||||
string id = 3;
|
||||
}
|
||||
|
||||
message AlgoResponse { string algorithmID = 1; }
|
||||
@@ -29,6 +30,7 @@ message AlgoResponse { string algorithmID = 1; }
|
||||
message DataRequest {
|
||||
bytes dataset = 1;
|
||||
string provider = 2;
|
||||
string id = 3;
|
||||
}
|
||||
|
||||
message DataResponse { string datasetID = 1; }
|
||||
|
||||
@@ -106,6 +106,8 @@ func encodeAlgoRequest(_ context.Context, request interface{}) (interface{}, err
|
||||
|
||||
return &agent.AlgoRequest{
|
||||
Algorithm: req.Algorithm,
|
||||
Provider: req.Provider,
|
||||
Id: req.Id,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -131,7 +133,9 @@ func encodeDataRequest(_ context.Context, request interface{}) (interface{}, err
|
||||
}
|
||||
|
||||
return &agent.DataRequest{
|
||||
Dataset: req.Dataset,
|
||||
Dataset: req.Dataset,
|
||||
Provider: req.Provider,
|
||||
Id: req.Id,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -151,8 +155,14 @@ func decodeDataResponse(_ context.Context, grpcResponse interface{}) (interface{
|
||||
// encodeResultRequest is a transport/grpc.EncodeRequestFunc that
|
||||
// converts a user-domain resultReq to a gRPC request.
|
||||
func encodeResultRequest(_ context.Context, request interface{}) (interface{}, error) {
|
||||
// No request parameters needed for retrieving computation result file
|
||||
return &agent.ResultRequest{}, nil
|
||||
req, ok := request.(*resultReq)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid request type: %T", request)
|
||||
}
|
||||
|
||||
return &agent.ResultRequest{
|
||||
Consumer: req.Consumer,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// decodeResultResponse is a transport/grpc.DecodeResponseFunc that
|
||||
@@ -207,7 +217,7 @@ func (c grpcClient) Algo(ctx context.Context, request *agent.AlgoRequest, _ ...g
|
||||
ctx, cancel := context.WithTimeout(ctx, c.timeout)
|
||||
defer cancel()
|
||||
|
||||
res, err := c.algo(ctx, &algoReq{Algorithm: request.Algorithm})
|
||||
res, err := c.algo(ctx, &algoReq{Algorithm: request.Algorithm, Provider: request.Provider, Id: request.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -221,7 +231,7 @@ func (c grpcClient) Data(ctx context.Context, request *agent.DataRequest, _ ...g
|
||||
ctx, cancel := context.WithTimeout(ctx, c.timeout)
|
||||
defer cancel()
|
||||
|
||||
res, err := c.data(ctx, &dataReq{Dataset: request.Dataset})
|
||||
res, err := c.data(ctx, &dataReq{Dataset: request.Dataset, Provider: request.Provider, Id: request.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -235,7 +245,7 @@ func (c grpcClient) Result(ctx context.Context, request *agent.ResultRequest, _
|
||||
ctx, cancel := context.WithTimeout(ctx, c.timeout)
|
||||
defer cancel()
|
||||
|
||||
res, err := c.result(ctx, &resultReq{})
|
||||
res, err := c.result(ctx, &resultReq{Consumer: request.Consumer})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -249,7 +259,7 @@ func (c grpcClient) Attestation(ctx context.Context, request *agent.AttestationR
|
||||
ctx, cancel := context.WithTimeout(ctx, c.timeout)
|
||||
defer cancel()
|
||||
|
||||
res, err := c.result(ctx, &resultReq{})
|
||||
res, err := c.result(ctx, &attestationReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func algoEndpoint(svc agent.Service) endpoint.Endpoint {
|
||||
return algoRes{}, err
|
||||
}
|
||||
|
||||
algo := agent.Algorithm{Algorithm: req.Algorithm, Provider: req.Provider}
|
||||
algo := agent.Algorithm{Algorithm: req.Algorithm, Provider: req.Provider, ID: req.Id}
|
||||
|
||||
algorithmID, err := svc.Algo(ctx, algo)
|
||||
if err != nil {
|
||||
@@ -60,7 +60,7 @@ func dataEndpoint(svc agent.Service) endpoint.Endpoint {
|
||||
return dataRes{}, err
|
||||
}
|
||||
|
||||
dataset := agent.Dataset{Dataset: req.Dataset, Provider: req.Provider}
|
||||
dataset := agent.Dataset{Dataset: req.Dataset, Provider: req.Provider, ID: req.Id}
|
||||
|
||||
datasetID, err := svc.Data(ctx, dataset)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
package grpc
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type runReq struct {
|
||||
Computation []byte `protobuf:"bytes,1,opt,name=algorithm,proto3" json:"algorithm,omitempty"`
|
||||
@@ -18,24 +20,38 @@ func (req runReq) validate() error {
|
||||
type algoReq struct {
|
||||
Algorithm []byte `protobuf:"bytes,1,opt,name=algorithm,proto3" json:"algorithm,omitempty"`
|
||||
Provider string `protobuf:"bytes,2,opt,name=provider,proto3" json:"provider,omitempty"`
|
||||
Id string `protobuf:"bytes,3,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (req algoReq) validate() error {
|
||||
if len(req.Algorithm) == 0 {
|
||||
return errors.New("algorithm binary is required")
|
||||
}
|
||||
if req.Id == "" {
|
||||
return errors.New("malformed entity")
|
||||
}
|
||||
if req.Provider == "" {
|
||||
return errors.New("malformed entity")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type dataReq struct {
|
||||
Dataset []byte `protobuf:"bytes,1,opt,name=dataset,proto3" json:"dataset,omitempty"`
|
||||
Provider string `protobuf:"bytes,2,opt,name=provider,proto3" json:"provider,omitempty"`
|
||||
Id string `protobuf:"bytes,3,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (req dataReq) validate() error {
|
||||
if len(req.Dataset) == 0 {
|
||||
return errors.New("dataset CSV file is required")
|
||||
}
|
||||
if req.Id == "" {
|
||||
return errors.New("malformed entity")
|
||||
}
|
||||
if req.Provider == "" {
|
||||
return errors.New("malformed entity")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,8 @@ func decodeAlgoRequest(_ context.Context, grpcReq interface{}) (interface{}, err
|
||||
|
||||
return algoReq{
|
||||
Algorithm: req.Algorithm,
|
||||
Provider: req.Provider,
|
||||
Id: req.Id,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -83,7 +85,9 @@ func decodeDataRequest(_ context.Context, grpcReq interface{}) (interface{}, err
|
||||
req := grpcReq.(*agent.DataRequest)
|
||||
|
||||
return dataReq{
|
||||
Dataset: req.Dataset,
|
||||
Dataset: req.Dataset,
|
||||
Provider: req.Provider,
|
||||
Id: req.Id,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -95,8 +99,8 @@ func encodeDataResponse(_ context.Context, response interface{}) (interface{}, e
|
||||
}
|
||||
|
||||
func decodeResultRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
// No fields to extract from gRPC request, so returning an empty struct
|
||||
return resultReq{}, nil
|
||||
req := grpcReq.(*agent.ResultRequest)
|
||||
return resultReq{Consumer: req.Consumer}, nil
|
||||
}
|
||||
|
||||
func encodeResultResponse(_ context.Context, response interface{}) (interface{}, error) {
|
||||
|
||||
+35
-1
@@ -3,7 +3,9 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -20,8 +22,40 @@ type Computation struct {
|
||||
ResultConsumers []string `json:"result_consumers,omitempty"`
|
||||
Ttl int32 `json:"ttl,omitempty"`
|
||||
Metadata Metadata `json:"metadata,omitempty"`
|
||||
Timeout Duration `json:"timeout,omitempty"`
|
||||
}
|
||||
|
||||
type Duration struct {
|
||||
time.Duration
|
||||
}
|
||||
|
||||
func (d Duration) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(d.String())
|
||||
}
|
||||
|
||||
func (d *Duration) UnmarshalJSON(b []byte) error {
|
||||
var v interface{}
|
||||
if err := json.Unmarshal(b, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch value := v.(type) {
|
||||
case float64:
|
||||
d.Duration = time.Duration(value)
|
||||
return nil
|
||||
case string:
|
||||
var err error
|
||||
d.Duration, err = time.ParseDuration(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return errors.New("invalid duration")
|
||||
}
|
||||
}
|
||||
|
||||
type Metadata map[string]interface{}
|
||||
|
||||
type Dataset struct {
|
||||
Dataset []byte `json:"-"`
|
||||
Provider string `json:"provider,omitempty"`
|
||||
|
||||
+68
-18
@@ -12,7 +12,9 @@ import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
"github.com/ultravioletrs/cocos-ai/pkg/socket"
|
||||
)
|
||||
|
||||
@@ -35,10 +37,12 @@ var (
|
||||
errAllManifestItemsReceived = errors.New("all expected manifest Items have been received")
|
||||
// errUndeclaredConsumer indicates the consumer requesting results in not declared in computation manifest.
|
||||
errUndeclaredConsumer = errors.New("result consumer is undeclared in computation manifest")
|
||||
// errResultsNotReady indicates the computation results are not ready.
|
||||
errResultsNotReady = errors.New("computation results are not yet ready")
|
||||
// errStateNotReady agent received a request in the wrong state.
|
||||
errStateNotReady = errors.New("agent not expecting this operation in the current state")
|
||||
)
|
||||
|
||||
type Metadata map[string]interface{}
|
||||
|
||||
// Service specifies an API that must be fullfiled by the domain service
|
||||
// implementation, and all of its decorators (e.g. logging & metrics).
|
||||
type Service interface {
|
||||
@@ -55,6 +59,8 @@ type agentService struct {
|
||||
datasets [][]byte
|
||||
result []byte
|
||||
attestation []byte
|
||||
sm *StateMachine
|
||||
runError error
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -65,17 +71,27 @@ const (
|
||||
var _ Service = (*agentService)(nil)
|
||||
|
||||
// New instantiates the agent service implementation.
|
||||
func New() Service {
|
||||
return &agentService{}
|
||||
func New(ctx context.Context, logger logger.Logger) Service {
|
||||
svc := &agentService{
|
||||
sm: NewStateMachine(logger),
|
||||
}
|
||||
go svc.sm.Start(ctx)
|
||||
svc.sm.SendEvent(start)
|
||||
svc.sm.StateFunctions[running] = svc.runComputation
|
||||
return svc
|
||||
}
|
||||
|
||||
func (as *agentService) Run(ctx context.Context, cmp Computation) (string, error) {
|
||||
if as.sm.GetState() != receivingManifests {
|
||||
return "", errStateNotReady
|
||||
}
|
||||
cmpJSON, err := json.Marshal(cmp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
as.computation = cmp
|
||||
as.sm.SendEvent(manifestsReceived)
|
||||
|
||||
// Calculate the SHA-256 hash of the algorithm
|
||||
hash := sha256.Sum256(cmpJSON)
|
||||
@@ -85,6 +101,9 @@ func (as *agentService) Run(ctx context.Context, cmp Computation) (string, error
|
||||
}
|
||||
|
||||
func (as *agentService) Algo(ctx context.Context, algorithm Algorithm) (string, error) {
|
||||
if as.sm.GetState() != receivingAlgorithms {
|
||||
return "", errStateNotReady
|
||||
}
|
||||
if len(as.computation.Algorithms) == 0 {
|
||||
return "", errAllManifestItemsReceived
|
||||
}
|
||||
@@ -101,6 +120,10 @@ func (as *agentService) Algo(ctx context.Context, algorithm Algorithm) (string,
|
||||
|
||||
as.algorithms = append(as.algorithms, algorithm.Algorithm)
|
||||
|
||||
if len(as.computation.Algorithms) == 0 {
|
||||
as.sm.SendEvent(algorithmsReceived)
|
||||
}
|
||||
|
||||
// Calculate the SHA-256 hash of the algorithm.
|
||||
hash := sha256.Sum256(algorithm.Algorithm)
|
||||
algorithmHash := hex.EncodeToString(hash[:])
|
||||
@@ -110,6 +133,9 @@ func (as *agentService) Algo(ctx context.Context, algorithm Algorithm) (string,
|
||||
}
|
||||
|
||||
func (as *agentService) Data(ctx context.Context, dataset Dataset) (string, error) {
|
||||
if as.sm.GetState() != receivingData {
|
||||
return "", errStateNotReady
|
||||
}
|
||||
if len(as.computation.Datasets) == 0 {
|
||||
return "", errAllManifestItemsReceived
|
||||
}
|
||||
@@ -126,6 +152,10 @@ func (as *agentService) Data(ctx context.Context, dataset Dataset) (string, erro
|
||||
|
||||
as.datasets = append(as.datasets, dataset.Dataset)
|
||||
|
||||
if len(as.computation.Datasets) == 0 {
|
||||
as.sm.SendEvent(dataReceived)
|
||||
}
|
||||
|
||||
// Calculate the SHA-256 hash of the dataset.
|
||||
hash := sha256.Sum256(dataset.Dataset)
|
||||
datasetHash := hex.EncodeToString(hash[:])
|
||||
@@ -135,6 +165,9 @@ func (as *agentService) Data(ctx context.Context, dataset Dataset) (string, erro
|
||||
}
|
||||
|
||||
func (as *agentService) Result(ctx context.Context, consumer string) ([]byte, error) {
|
||||
if as.sm.GetState() != resultsReady {
|
||||
return []byte{}, errResultsNotReady
|
||||
}
|
||||
if len(as.computation.ResultConsumers) == 0 {
|
||||
return []byte{}, errAllManifestItemsReceived
|
||||
}
|
||||
@@ -146,14 +179,11 @@ func (as *agentService) Result(ctx context.Context, consumer string) ([]byte, er
|
||||
as.computation.ResultConsumers = slices.Delete(as.computation.ResultConsumers, index, index+1)
|
||||
}
|
||||
|
||||
result, err := run(as.algorithms[0], as.datasets[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error performing computation: %v", err)
|
||||
if len(as.computation.ResultConsumers) == 0 {
|
||||
as.sm.SendEvent(resultsConsumed)
|
||||
}
|
||||
as.result = result
|
||||
|
||||
// Return the result file or an error
|
||||
return as.result, nil
|
||||
return as.result, as.runError
|
||||
}
|
||||
|
||||
func (as *agentService) Attestation(ctx context.Context) ([]byte, error) {
|
||||
@@ -166,7 +196,24 @@ func (as *agentService) Attestation(ctx context.Context) ([]byte, error) {
|
||||
return as.attestation, nil
|
||||
}
|
||||
|
||||
func run(algoContent []byte, dataContent []byte) ([]byte, error) {
|
||||
func (as *agentService) runComputation() {
|
||||
as.sm.logger.Debug("computation run started")
|
||||
defer as.sm.SendEvent(runComplete)
|
||||
var cancel context.CancelFunc
|
||||
ctx := context.Background()
|
||||
if as.computation.Timeout.Duration != 0 {
|
||||
ctx, cancel = context.WithDeadline(ctx, <-time.After(as.computation.Timeout.Duration))
|
||||
defer cancel()
|
||||
}
|
||||
result, err := run(ctx, as.algorithms[0], as.datasets[0])
|
||||
if err != nil {
|
||||
as.runError = err
|
||||
return
|
||||
}
|
||||
as.result = result
|
||||
}
|
||||
|
||||
func run(ctx context.Context, algoContent []byte, dataContent []byte) ([]byte, error) {
|
||||
listener, err := socket.StartUnixSocketServer(socketPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating stdout pipe: %v", err)
|
||||
@@ -176,6 +223,16 @@ func run(algoContent []byte, dataContent []byte) ([]byte, error) {
|
||||
// Create channels for received data and errors
|
||||
dataChannel := make(chan []byte)
|
||||
errorChannel := make(chan error)
|
||||
|
||||
var result []byte
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, errors.New("computation timed out")
|
||||
case result = <-dataChannel:
|
||||
case err = <-errorChannel:
|
||||
return nil, fmt.Errorf("error receiving data: %v", err)
|
||||
}
|
||||
|
||||
go socket.AcceptConnection(listener, dataChannel, errorChannel)
|
||||
|
||||
// Construct the Python script content with CSV data as a command-line argument
|
||||
@@ -187,13 +244,6 @@ func run(algoContent []byte, dataContent []byte) ([]byte, error) {
|
||||
return nil, fmt.Errorf("error starting Python script: %v", err)
|
||||
}
|
||||
|
||||
var result []byte
|
||||
select {
|
||||
case result = <-dataChannel:
|
||||
case err = <-errorChannel:
|
||||
return nil, fmt.Errorf("error receiving data: %v", err)
|
||||
}
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
return nil, fmt.Errorf("python script execution error: %v", err)
|
||||
}
|
||||
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
// Copyright (c) Ultraviolet
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
)
|
||||
|
||||
type state int
|
||||
|
||||
const (
|
||||
idle state = iota
|
||||
receivingManifests
|
||||
receivingAlgorithms
|
||||
receivingData
|
||||
running
|
||||
resultsReady
|
||||
complete
|
||||
)
|
||||
|
||||
type event int
|
||||
|
||||
const (
|
||||
start event = iota
|
||||
manifestsReceived
|
||||
algorithmsReceived
|
||||
dataReceived
|
||||
runComplete
|
||||
resultsConsumed
|
||||
)
|
||||
|
||||
// StateMachine represents the state machine.
|
||||
type StateMachine struct {
|
||||
sync.Mutex
|
||||
State state
|
||||
EventChan chan event
|
||||
Transitions map[state]map[event]state
|
||||
StateFunctions map[state]func()
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
// NewStateMachine creates a new StateMachine.
|
||||
func NewStateMachine(logger logger.Logger) *StateMachine {
|
||||
sm := &StateMachine{
|
||||
State: idle,
|
||||
EventChan: make(chan event),
|
||||
Transitions: make(map[state]map[event]state),
|
||||
StateFunctions: make(map[state]func()),
|
||||
logger: logger,
|
||||
}
|
||||
|
||||
sm.Transitions[idle] = make(map[event]state)
|
||||
sm.Transitions[idle][start] = receivingManifests
|
||||
|
||||
sm.Transitions[receivingManifests] = make(map[event]state)
|
||||
sm.Transitions[receivingManifests][manifestsReceived] = receivingAlgorithms
|
||||
|
||||
sm.Transitions[receivingAlgorithms] = make(map[event]state)
|
||||
sm.Transitions[receivingAlgorithms][algorithmsReceived] = receivingData
|
||||
|
||||
sm.Transitions[receivingData] = make(map[event]state)
|
||||
sm.Transitions[receivingData][dataReceived] = running
|
||||
|
||||
sm.Transitions[running] = make(map[event]state)
|
||||
sm.Transitions[running][runComplete] = resultsReady
|
||||
|
||||
sm.Transitions[resultsReady] = make(map[event]state)
|
||||
sm.Transitions[resultsReady][resultsConsumed] = complete
|
||||
|
||||
return sm
|
||||
}
|
||||
|
||||
// Start the state machine.
|
||||
func (sm *StateMachine) Start(ctx context.Context) {
|
||||
for {
|
||||
select {
|
||||
case event := <-sm.EventChan:
|
||||
nextState, valid := sm.Transitions[sm.GetState()][event]
|
||||
if valid {
|
||||
sm.Lock()
|
||||
sm.State = nextState
|
||||
sm.Unlock()
|
||||
sm.logger.Debug(fmt.Sprintf("Transition: %v -> %v\n", sm.GetState(), nextState))
|
||||
} else {
|
||||
sm.logger.Error(fmt.Sprintf("Invalid transition: %v -> ???\n", sm.GetState()))
|
||||
}
|
||||
stateFunc, exists := sm.StateFunctions[sm.GetState()]
|
||||
if exists {
|
||||
go stateFunc()
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SendEvent sends an event to the state machine.
|
||||
func (sm *StateMachine) SendEvent(event event) {
|
||||
sm.EventChan <- event
|
||||
}
|
||||
|
||||
func (sm *StateMachine) GetState() state {
|
||||
sm.Lock()
|
||||
state := sm.State
|
||||
sm.Unlock()
|
||||
return state
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) Ultraviolet
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
)
|
||||
|
||||
func TestStateMachineTransitions(t *testing.T) {
|
||||
testCases := []struct {
|
||||
fromState state
|
||||
event event
|
||||
expected state
|
||||
}{
|
||||
{idle, start, receivingManifests},
|
||||
{receivingManifests, manifestsReceived, receivingAlgorithms},
|
||||
{receivingAlgorithms, algorithmsReceived, receivingData},
|
||||
{receivingData, dataReceived, running},
|
||||
{running, runComplete, resultsReady},
|
||||
{resultsReady, resultsConsumed, complete},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(fmt.Sprintf("Transition from %v to %v", testCase.fromState, testCase.expected), func(t *testing.T) {
|
||||
sm := NewStateMachine(logger.NewMock())
|
||||
done := make(chan struct{})
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
sm.Start(ctx)
|
||||
close(done)
|
||||
}()
|
||||
sm.Lock()
|
||||
sm.State = testCase.fromState
|
||||
sm.Unlock()
|
||||
|
||||
sm.SendEvent(testCase.event)
|
||||
|
||||
if sm.GetState() != testCase.expected {
|
||||
t.Errorf("Expected state %v after the event, but got %v", testCase.expected, sm.GetState())
|
||||
}
|
||||
close(sm.EventChan)
|
||||
cancel()
|
||||
<-done
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateMachineInvalidTransition(t *testing.T) {
|
||||
sm := NewStateMachine(logger.NewMock())
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go sm.Start(ctx)
|
||||
|
||||
sm.Lock()
|
||||
sm.State = idle
|
||||
sm.Unlock()
|
||||
|
||||
sm.SendEvent(dataReceived)
|
||||
|
||||
if sm.State != idle {
|
||||
t.Errorf("State should not change on an invalid event, but got %v", sm.State)
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
+15
-11
@@ -3,19 +3,19 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/ultravioletrs/cocos-ai/pkg/sdk"
|
||||
"github.com/ultravioletrs/cocos-ai/agent"
|
||||
)
|
||||
|
||||
func NewAlgorithmsCmd(sdk sdk.SDK) *cobra.Command {
|
||||
func NewAlgorithmsCmd(sdk agent.Service) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "algo",
|
||||
Short: "Upload an algorithm binary",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "algo",
|
||||
Short: "Upload an algorithm binary",
|
||||
Example: "algo <algo_file> <id> <provider>",
|
||||
Args: cobra.ExactArgs(3),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
algorithmFile := args[0]
|
||||
|
||||
@@ -23,14 +23,18 @@ func NewAlgorithmsCmd(sdk sdk.SDK) *cobra.Command {
|
||||
|
||||
algorithm, err := os.ReadFile(algorithmFile)
|
||||
if err != nil {
|
||||
log.Println("Error reading dataset file:", err)
|
||||
return
|
||||
log.Fatalf("Error reading algorithm file: %v", err)
|
||||
}
|
||||
|
||||
response, err := sdk.UploadAlgorithm(context.Background(), algorithm)
|
||||
algoReq := agent.Algorithm{
|
||||
Algorithm: algorithm,
|
||||
ID: args[1],
|
||||
Provider: args[2],
|
||||
}
|
||||
|
||||
response, err := sdk.Algo(cmd.Context(), algoReq)
|
||||
if err != nil {
|
||||
log.Println("Error uploading algorithm:", err)
|
||||
return
|
||||
log.Fatalf("Error uploading algorithm with ID %s and provider %s: %v", algoReq.ID, algoReq.Provider, err)
|
||||
}
|
||||
|
||||
log.Println("Successfully uploaded algorithm:", response)
|
||||
|
||||
+5
-8
@@ -3,32 +3,29 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/ultravioletrs/cocos-ai/pkg/sdk"
|
||||
"github.com/ultravioletrs/cocos-ai/agent"
|
||||
)
|
||||
|
||||
const attestationFilePath = "attestation.txt"
|
||||
|
||||
func NewAttestationCmd(sdk sdk.SDK) *cobra.Command {
|
||||
func NewAttestationCmd(sdk agent.Service) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "attestation",
|
||||
Short: "Retrieve attestation information",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
log.Println("Checking attestation")
|
||||
|
||||
result, err := sdk.Attestation(context.Background())
|
||||
result, err := sdk.Attestation(cmd.Context())
|
||||
if err != nil {
|
||||
log.Println("Error retrieving attestation:", err)
|
||||
return
|
||||
log.Fatalf("Error retrieving attestation: %v", err)
|
||||
}
|
||||
|
||||
if err = os.WriteFile(attestationFilePath, result, 0o644); err != nil {
|
||||
log.Println("Error saving attestation result:", err)
|
||||
return
|
||||
log.Fatalf("Error saving attestation result: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Attestation result retrieved and saved successfully!")
|
||||
|
||||
+15
-11
@@ -3,19 +3,19 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/ultravioletrs/cocos-ai/pkg/sdk"
|
||||
"github.com/ultravioletrs/cocos-ai/agent"
|
||||
)
|
||||
|
||||
func NewDatasetsCmd(sdk sdk.SDK) *cobra.Command {
|
||||
func NewDatasetsCmd(sdk agent.Service) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "data",
|
||||
Short: "Upload a dataset CSV file",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "data",
|
||||
Short: "Upload a dataset CSV file",
|
||||
Example: "data <dataset.csv> <id> <provider>",
|
||||
Args: cobra.ExactArgs(3),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
datasetFile := args[0]
|
||||
|
||||
@@ -23,14 +23,18 @@ func NewDatasetsCmd(sdk sdk.SDK) *cobra.Command {
|
||||
|
||||
dataset, err := os.ReadFile(datasetFile)
|
||||
if err != nil {
|
||||
log.Println("Error reading dataset file:", err)
|
||||
return
|
||||
log.Fatalf("Error reading dataset file: %v", err)
|
||||
}
|
||||
|
||||
response, err := sdk.UploadDataset(context.Background(), dataset)
|
||||
dataReq := agent.Dataset{
|
||||
Dataset: dataset,
|
||||
ID: args[1],
|
||||
Provider: args[2],
|
||||
}
|
||||
|
||||
response, err := sdk.Data(cmd.Context(), dataReq)
|
||||
if err != nil {
|
||||
log.Println("Error uploading dataset:", err)
|
||||
return
|
||||
log.Fatalf("Error uploading dataset: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Response:", response)
|
||||
|
||||
+6
-8
@@ -3,32 +3,30 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/ultravioletrs/cocos-ai/pkg/sdk"
|
||||
"github.com/ultravioletrs/cocos-ai/agent"
|
||||
)
|
||||
|
||||
const resultFilePath = "result.bin"
|
||||
|
||||
func NewResultsCmd(sdk sdk.SDK) *cobra.Command {
|
||||
func NewResultsCmd(sdk agent.Service) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "result",
|
||||
Short: "Retrieve computation result file",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
log.Println("Retrieving computation result file")
|
||||
|
||||
result, err := sdk.Result(context.Background())
|
||||
result, err := sdk.Result(cmd.Context(), args[0])
|
||||
if err != nil {
|
||||
log.Println("Error retrieving computation result:", err)
|
||||
return
|
||||
log.Fatalf("Error retrieving computation result: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(resultFilePath, result, 0o644); err != nil {
|
||||
log.Println("Error saving computation result:", err)
|
||||
return
|
||||
log.Fatalf("Error saving computation result to %s: %v", resultFilePath, err)
|
||||
}
|
||||
|
||||
log.Println("Computation result retrieved and saved successfully!")
|
||||
|
||||
+6
-9
@@ -3,15 +3,14 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
agentsdk "github.com/ultravioletrs/cocos-ai/pkg/sdk"
|
||||
"github.com/ultravioletrs/cocos-ai/agent"
|
||||
)
|
||||
|
||||
func NewRunCmd(sdk agentsdk.SDK) *cobra.Command {
|
||||
func NewRunCmd(sdk agent.Service) *cobra.Command {
|
||||
var computationJSON string
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -20,16 +19,14 @@ func NewRunCmd(sdk agentsdk.SDK) *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
log.Println("Running computation")
|
||||
|
||||
var computation agentsdk.Computation
|
||||
var computation agent.Computation
|
||||
if err := json.Unmarshal([]byte(computationJSON), &computation); err != nil {
|
||||
log.Println("Failed to unmarshal computation JSON:", err)
|
||||
return
|
||||
log.Fatalf("Failed to unmarshal computation JSON: %v", err)
|
||||
}
|
||||
|
||||
response, err := sdk.Run(context.Background(), computation)
|
||||
response, err := sdk.Run(cmd.Context(), computation)
|
||||
if err != nil {
|
||||
log.Println("Error running computation:", err)
|
||||
return
|
||||
log.Fatalf("Error running computation: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Response:", response)
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"github.com/ultravioletrs/cocos-ai/pkg/sdk"
|
||||
"github.com/ultravioletrs/cocos-ai/agent"
|
||||
)
|
||||
|
||||
func SetSDK(s sdk.SDK) {
|
||||
func SetSDK(s agent.Service) {
|
||||
}
|
||||
|
||||
+3
-3
@@ -71,7 +71,7 @@ func main() {
|
||||
}()
|
||||
tracer := tp.Tracer(svcName)
|
||||
|
||||
svc := newService(logger, tracer)
|
||||
svc := newService(ctx, logger, tracer)
|
||||
|
||||
httpServerConfig := server.Config{Port: defSvcHTTPPort}
|
||||
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
|
||||
@@ -102,8 +102,8 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(logger mflog.Logger, tracer trace.Tracer) agent.Service {
|
||||
svc := agent.New()
|
||||
func newService(ctx context.Context, logger mflog.Logger, tracer trace.Tracer) agent.Service {
|
||||
svc := agent.New(ctx, logger)
|
||||
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := internal.MakeMetrics(svcName, "api")
|
||||
|
||||
+14
-34
@@ -5,44 +5,18 @@ package sdk
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
"github.com/ultravioletrs/cocos-ai/agent"
|
||||
)
|
||||
|
||||
type SDK interface {
|
||||
Run(ctx context.Context, computation Computation) (string, error)
|
||||
UploadAlgorithm(ctx context.Context, algorithm []byte) (string, error)
|
||||
UploadDataset(ctx context.Context, dataset []byte) (string, error)
|
||||
Result(ctx context.Context) ([]byte, error)
|
||||
Attestation(ctx context.Context) ([]byte, error)
|
||||
}
|
||||
var _ agent.Service = (*agentSDK)(nil)
|
||||
|
||||
type agentSDK struct {
|
||||
client agent.AgentServiceClient
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
type Computation struct {
|
||||
ID string `json:"id,omitempty" db:"id"`
|
||||
Name string `json:"name,omitempty" db:"name"`
|
||||
Description string `json:"description,omitempty" db:"description"`
|
||||
Status string `json:"status,omitempty" db:"status"`
|
||||
Owner string `json:"owner,omitempty" db:"owner"`
|
||||
StartTime time.Time `json:"start_time,omitempty" db:"start_time"`
|
||||
EndTime time.Time `json:"end_time,omitempty" db:"end_time"`
|
||||
Datasets []string `json:"datasets,omitempty" db:"datasets"`
|
||||
Algorithms []string `json:"algorithms,omitempty" db:"algorithms"`
|
||||
DatasetProviders []string `json:"dataset_providers,omitempty" db:"dataset_providers"`
|
||||
AlgorithmProviders []string `json:"algorithm_providers,omitempty" db:"algorithm_providers"`
|
||||
ResultConsumers []string `json:"result_consumers,omitempty" db:"result_consumers"`
|
||||
Ttl int `json:"ttl,omitempty" db:"ttl"`
|
||||
Metadata Metadata `json:"metadata,omitempty" db:"metadata"`
|
||||
}
|
||||
|
||||
type Metadata map[string]interface{}
|
||||
|
||||
func NewAgentSDK(log logger.Logger, agentClient agent.AgentServiceClient) *agentSDK {
|
||||
return &agentSDK{
|
||||
client: agentClient,
|
||||
@@ -50,7 +24,7 @@ func NewAgentSDK(log logger.Logger, agentClient agent.AgentServiceClient) *agent
|
||||
}
|
||||
}
|
||||
|
||||
func (sdk *agentSDK) Run(ctx context.Context, computation Computation) (string, error) {
|
||||
func (sdk *agentSDK) Run(ctx context.Context, computation agent.Computation) (string, error) {
|
||||
computationBytes, err := json.Marshal(computation)
|
||||
if err != nil {
|
||||
sdk.logger.Error("Failed to marshal computation")
|
||||
@@ -69,9 +43,11 @@ func (sdk *agentSDK) Run(ctx context.Context, computation Computation) (string,
|
||||
return response.Computation, nil
|
||||
}
|
||||
|
||||
func (sdk *agentSDK) UploadAlgorithm(ctx context.Context, algorithm []byte) (string, error) {
|
||||
func (sdk *agentSDK) Algo(ctx context.Context, algorithm agent.Algorithm) (string, error) {
|
||||
request := &agent.AlgoRequest{
|
||||
Algorithm: algorithm,
|
||||
Algorithm: algorithm.Algorithm,
|
||||
Provider: algorithm.Provider,
|
||||
Id: algorithm.ID,
|
||||
}
|
||||
|
||||
response, err := sdk.client.Algo(ctx, request)
|
||||
@@ -83,9 +59,11 @@ func (sdk *agentSDK) UploadAlgorithm(ctx context.Context, algorithm []byte) (str
|
||||
return response.AlgorithmID, nil
|
||||
}
|
||||
|
||||
func (sdk *agentSDK) UploadDataset(ctx context.Context, dataset []byte) (string, error) {
|
||||
func (sdk *agentSDK) Data(ctx context.Context, dataset agent.Dataset) (string, error) {
|
||||
request := &agent.DataRequest{
|
||||
Dataset: dataset,
|
||||
Dataset: dataset.Dataset,
|
||||
Provider: dataset.Provider,
|
||||
Id: dataset.ID,
|
||||
}
|
||||
|
||||
response, err := sdk.client.Data(ctx, request)
|
||||
@@ -97,8 +75,10 @@ func (sdk *agentSDK) UploadDataset(ctx context.Context, dataset []byte) (string,
|
||||
return response.DatasetID, nil
|
||||
}
|
||||
|
||||
func (sdk *agentSDK) Result(ctx context.Context) ([]byte, error) {
|
||||
request := &agent.ResultRequest{}
|
||||
func (sdk *agentSDK) Result(ctx context.Context, consumer string) ([]byte, error) {
|
||||
request := &agent.ResultRequest{
|
||||
Consumer: consumer,
|
||||
}
|
||||
|
||||
response, err := sdk.client.Result(ctx, request)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,337 @@
|
||||
mode: atomic
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:34.30,36.29 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:36.29,40.3 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:43.38,45.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:47.36,47.37 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:49.58,51.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:51.41,53.34 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:53.34,55.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:56.3,56.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:58.2,58.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:62.49,64.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:66.46,67.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:67.14,69.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:70.2,70.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:81.31,83.29 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:83.29,87.3 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:90.39,92.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:94.37,94.38 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:96.59,98.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:98.41,100.34 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:100.34,102.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:103.3,103.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:105.2,105.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:109.50,111.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:113.47,114.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:114.14,116.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:117.2,117.11 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:129.31,131.29 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:131.29,135.3 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:138.39,140.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:142.37,142.38 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:144.59,146.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:146.41,148.34 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:148.34,150.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:151.3,151.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:153.2,153.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:157.50,159.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:161.45,162.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:162.14,164.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:165.2,165.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:168.44,169.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:169.14,171.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:172.2,172.11 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:183.32,185.29 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:185.29,189.3 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:192.40,194.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:196.38,196.39 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:198.60,200.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:200.41,202.34 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:202.34,204.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:205.3,205.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:207.2,207.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:211.51,213.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:215.48,216.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:216.14,218.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:219.2,219.11 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:231.31,233.29 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:233.29,237.3 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:240.39,242.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:244.37,244.38 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:246.59,248.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:248.41,250.34 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:250.34,252.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:253.3,253.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:255.2,255.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:259.50,261.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:263.43,264.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:264.14,266.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:267.2,267.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:270.44,271.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:271.14,273.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:274.2,274.11 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:285.32,287.29 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:287.29,291.3 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:294.40,296.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:298.38,298.39 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:300.60,302.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:302.41,304.34 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:304.34,306.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:307.3,307.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:309.2,309.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:313.51,315.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:317.46,318.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:318.14,320.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:321.2,321.11 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:332.33,334.29 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:334.29,338.3 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:341.41,343.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:345.39,345.40 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:347.61,349.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:349.41,351.34 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:351.34,353.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:354.3,354.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:356.2,356.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:360.52,362.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:364.46,365.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:365.14,367.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:368.2,368.11 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:379.34,381.29 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:381.29,385.3 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:388.42,390.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:392.40,392.41 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:394.62,396.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:396.41,398.34 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:398.34,400.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:401.3,401.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:403.2,403.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:407.53,409.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:411.43,412.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:412.14,414.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:415.2,415.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:424.38,426.29 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:426.29,430.3 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:433.46,435.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:437.44,437.45 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:439.66,441.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:441.41,443.34 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:443.34,445.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:446.3,446.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:448.2,448.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:452.57,454.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:464.39,466.29 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:466.29,470.3 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:473.47,475.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:477.45,477.46 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:479.67,481.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:481.41,483.34 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:483.34,485.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:486.3,486.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:488.2,488.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:492.58,494.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:496.48,497.14 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:497.14,499.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:500.2,500.12 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:565.50,566.47 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:566.47,568.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:569.2,569.43 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:603.13,603.46 1 1
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:604.36,605.35 1 1
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:605.35,607.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:608.2,608.30 1 1
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:608.30,609.88 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:609.88,610.35 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:611.11,612.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:613.11,614.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:615.11,616.28 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:617.12,618.15 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:621.3,621.88 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:621.88,622.36 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:623.11,624.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:625.11,626.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:627.11,628.28 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:629.12,630.15 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:633.3,633.88 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:633.88,634.36 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:635.11,636.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:637.11,638.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:639.11,640.28 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:641.12,642.15 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:645.3,645.88 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:645.88,646.37 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:647.11,648.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:649.11,650.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:651.11,652.28 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:653.12,654.15 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:657.3,657.88 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:657.88,658.36 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:659.11,660.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:661.11,662.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:663.11,664.28 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:665.12,666.15 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:669.3,669.88 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:669.88,670.37 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:671.11,672.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:673.11,674.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:675.11,676.28 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:677.12,678.15 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:681.3,681.88 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:681.88,682.38 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:683.11,684.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:685.11,686.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:687.11,688.28 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:689.12,690.15 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:693.3,693.88 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:693.88,694.39 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:695.11,696.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:697.11,698.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:699.11,700.28 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:701.12,702.15 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:705.3,705.88 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:705.88,706.43 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:707.11,708.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:709.11,710.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:711.11,712.28 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:713.12,714.15 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:717.3,717.88 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:717.88,718.44 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:719.11,720.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:721.11,722.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:723.11,724.28 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:725.12,726.15 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent.pb.go:730.2,747.38 6 1
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:47.76,49.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:51.118,54.16 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:54.16,56.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:57.2,57.17 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:60.121,63.16 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:63.16,65.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:66.2,66.17 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:69.121,72.16 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:72.16,74.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:75.2,75.17 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:78.127,81.16 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:81.16,83.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:84.2,84.17 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:87.142,90.16 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:90.16,92.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:93.2,93.17 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:112.96,114.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:115.99,117.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:118.99,120.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:121.105,123.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:124.120,126.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:127.84,127.85 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:136.82,138.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:140.161,142.32 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:142.32,144.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:145.2,145.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:145.24,147.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:148.2,152.77 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:152.77,154.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:155.2,155.44 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:158.162,160.32 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:160.32,162.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:163.2,163.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:163.24,165.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:166.2,170.77 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:170.77,172.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:173.2,173.44 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:176.162,178.32 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:178.32,180.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:181.2,181.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:181.24,183.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:184.2,188.77 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:188.77,190.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:191.2,191.44 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:194.164,196.32 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:196.32,198.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:199.2,199.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:199.24,201.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:202.2,206.77 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:206.77,208.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:209.2,209.44 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:212.169,214.32 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:214.32,216.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:217.2,217.24 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:217.24,219.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:220.2,224.77 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:224.77,226.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/agent_grpc.pb.go:227.2,227.44 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/computations.go:37.51,39.39 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/computations.go:39.39,42.18 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/computations.go:42.18,43.27 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/computations.go:43.27,45.5 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/computations.go:48.2,48.11 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:73.61,81.2 5 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:83.83,85.16 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:85.16,87.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:89.2,96.21 5 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:99.88,100.41 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:100.41,102.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:103.2,104.15 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:105.10,106.36 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:107.10,108.70 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:108.70,110.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:111.3,111.87 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:114.2,116.41 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:116.41,118.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:121.2,125.27 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:128.84,129.39 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:129.39,131.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:132.2,133.15 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:134.10,135.34 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:136.10,137.66 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:137.66,139.4 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:140.3,140.83 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:143.2,145.39 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:145.39,147.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:150.2,154.25 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:157.86,158.46 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:158.46,160.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:161.2,162.15 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:163.10,164.41 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:165.10,166.97 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:169.2,169.33 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:169.33,171.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:173.2,173.46 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:173.46,175.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:177.2,177.31 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:180.74,182.2 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:184.42,187.16 3 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:187.16,190.3 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:191.2,191.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:194.66,196.16 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:196.16,198.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:199.2,211.36 8 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:211.36,213.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:215.2,216.9 2 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:217.30,217.30 0 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:218.28,219.58 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:222.2,222.35 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:222.35,224.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/service.go:226.2,226.20 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:47.58,75.2 14 7
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:78.52,79.6 1 7
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:79.6,80.10 1 24
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:81.32,83.13 2 17
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:83.13,88.5 4 6
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:88.10,90.5 1 11
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:92.4,93.14 2 17
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:93.14,95.5 1 0
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:96.21,97.10 1 7
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:103.48,105.2 1 7
|
||||
github.com/ultravioletrs/cocos-ai/agent/state.go:107.42,112.2 4 6
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:12.69,18.16 3 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:18.16,20.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:22.2,24.22 2 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:27.96,29.16 2 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:29.16,31.3 1 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:33.2,33.51 1 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:36.88,43.6 4 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:43.6,46.17 2 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:46.17,47.21 1 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:47.21,48.10 1 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:50.4,50.23 1 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:52.3,52.38 1 0
|
||||
github.com/ultravioletrs/cocos-ai/pkg/socket/socket.go:55.2,55.23 1 0
|
||||
@@ -25,18 +25,22 @@ AGENT_LOG_LEVEL=info AGENT_GRPC_URL=10.0.2.15:7002 go run cmd/agent/main.go
|
||||
Open console on the host, and run
|
||||
|
||||
```sh
|
||||
export AGENT_GRPC_URL=localhost:7020
|
||||
export AGENT_GRPC_URL=localhost:7002
|
||||
|
||||
# Run CLI to provide manifest
|
||||
go run cmd/cli/main.go run --computation '{"id":"123","name":"Sample Computation","description":"A sample computation","status":"Processing","owner":"John Doe","start_time":"2023-11-03T12:03:21.705171284+03:00","end_time":"2023-11-03T13:03:21.705171532+03:00","datasets":[{"provider":"Provider1","id":"Dataset1"},{"provider":"Provider2","id":"Dataset2"}],"algorithms":[{"provider":"AlgorithmProvider1","id":"Algorithm1"}],"result_consumers":["Consumer1","Consumer2"],"ttl":3600,"metadata":{"key1":"value1","key2":42}, "timeout": "2m"}'
|
||||
|
||||
# Run the CLI program with algorithm input
|
||||
go run cmd/cli/main.go algo test/manual/algo/lin_reg.py
|
||||
go run cmd/cli/main.go algo test/manual/algo/lin_reg.py Algorithm1 AlgorithmProvider1
|
||||
# 2023/09/21 10:43:53 Uploading algorithm binary: test/manual/algo/lin_reg.py
|
||||
|
||||
# Run the CLI program with dataset input
|
||||
go run cmd/cli/main.go data test/manual/data/iris.csv
|
||||
go run cmd/cli/main.go data test/manual/data/iris.csv Dataset1 Provider1
|
||||
go run cmd/cli/main.go data test/manual/data/iris.csv Dataset2 Provider2
|
||||
# 2023/09/21 10:45:25 Uploading dataset CSV: test/manual/data/iris.csv
|
||||
|
||||
# Run the CLI program to fetch computation result
|
||||
go run cmd/cli/main.go result
|
||||
go run cmd/cli/main.go result Consumer1
|
||||
# 2023/09/21 10:45:39 Retrieving computation result file
|
||||
# 2023/09/21 10:45:40 Computation result retrieved and saved successfully!
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user