diff --git a/agent/agent.pb.go b/agent/agent.pb.go index 85b6ecd1..7721c72f 100644 --- a/agent/agent.pb.go +++ b/agent/agent.pb.go @@ -422,203 +422,6 @@ func (x *AttestationResponse) GetFile() []byte { return nil } -type ComputationReq struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` - Datasets []*DatasetReq `protobuf:"bytes,4,rep,name=datasets,proto3" json:"datasets,omitempty"` - Algorithms []*AlgorithmReq `protobuf:"bytes,5,rep,name=algorithms,proto3" json:"algorithms,omitempty"` - ResultConsumers []string `protobuf:"bytes,6,rep,name=result_consumers,json=resultConsumers,proto3" json:"result_consumers,omitempty"` -} - -func (x *ComputationReq) Reset() { - *x = ComputationReq{} - if protoimpl.UnsafeEnabled { - mi := &file_agent_agent_proto_msgTypes[8] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ComputationReq) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ComputationReq) ProtoMessage() {} - -func (x *ComputationReq) ProtoReflect() protoreflect.Message { - mi := &file_agent_agent_proto_msgTypes[8] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ComputationReq.ProtoReflect.Descriptor instead. -func (*ComputationReq) Descriptor() ([]byte, []int) { - return file_agent_agent_proto_rawDescGZIP(), []int{8} -} - -func (x *ComputationReq) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -func (x *ComputationReq) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *ComputationReq) GetDescription() string { - if x != nil { - return x.Description - } - return "" -} - -func (x *ComputationReq) GetDatasets() []*DatasetReq { - if x != nil { - return x.Datasets - } - return nil -} - -func (x *ComputationReq) GetAlgorithms() []*AlgorithmReq { - if x != nil { - return x.Algorithms - } - return nil -} - -func (x *ComputationReq) GetResultConsumers() []string { - if x != nil { - return x.ResultConsumers - } - return nil -} - -type DatasetReq struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Provider string `protobuf:"bytes,1,opt,name=provider,proto3" json:"provider,omitempty"` - Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` -} - -func (x *DatasetReq) Reset() { - *x = DatasetReq{} - if protoimpl.UnsafeEnabled { - mi := &file_agent_agent_proto_msgTypes[9] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DatasetReq) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DatasetReq) ProtoMessage() {} - -func (x *DatasetReq) ProtoReflect() protoreflect.Message { - mi := &file_agent_agent_proto_msgTypes[9] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DatasetReq.ProtoReflect.Descriptor instead. -func (*DatasetReq) Descriptor() ([]byte, []int) { - return file_agent_agent_proto_rawDescGZIP(), []int{9} -} - -func (x *DatasetReq) GetProvider() string { - if x != nil { - return x.Provider - } - return "" -} - -func (x *DatasetReq) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -type AlgorithmReq struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Provider string `protobuf:"bytes,1,opt,name=provider,proto3" json:"provider,omitempty"` - Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` -} - -func (x *AlgorithmReq) Reset() { - *x = AlgorithmReq{} - if protoimpl.UnsafeEnabled { - mi := &file_agent_agent_proto_msgTypes[10] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *AlgorithmReq) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*AlgorithmReq) ProtoMessage() {} - -func (x *AlgorithmReq) ProtoReflect() protoreflect.Message { - mi := &file_agent_agent_proto_msgTypes[10] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use AlgorithmReq.ProtoReflect.Descriptor instead. -func (*AlgorithmReq) Descriptor() ([]byte, []int) { - return file_agent_agent_proto_rawDescGZIP(), []int{10} -} - -func (x *AlgorithmReq) GetProvider() string { - if x != nil { - return x.Provider - } - return "" -} - -func (x *AlgorithmReq) GetId() string { - if x != nil { - return x.Id - } - return "" -} - var File_agent_agent_proto protoreflect.FileDescriptor var file_agent_agent_proto_rawDesc = []byte{ @@ -649,46 +452,24 @@ var file_agent_agent_proto_rawDesc = []byte{ 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x29, 0x0a, 0x13, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0xe5, 0x01, 0x0a, - 0x0e, 0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, - 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, - 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, - 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2d, 0x0a, 0x08, 0x64, 0x61, 0x74, 0x61, 0x73, 0x65, 0x74, - 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, - 0x44, 0x61, 0x74, 0x61, 0x73, 0x65, 0x74, 0x52, 0x65, 0x71, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, - 0x73, 0x65, 0x74, 0x73, 0x12, 0x33, 0x0a, 0x0a, 0x61, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, - 0x6d, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, - 0x2e, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x52, 0x65, 0x71, 0x52, 0x0a, 0x61, - 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x73, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x73, - 0x75, 0x6c, 0x74, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x73, 0x18, 0x06, 0x20, - 0x03, 0x28, 0x09, 0x52, 0x0f, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x43, 0x6f, 0x6e, 0x73, 0x75, - 0x6d, 0x65, 0x72, 0x73, 0x22, 0x38, 0x0a, 0x0a, 0x44, 0x61, 0x74, 0x61, 0x73, 0x65, 0x74, 0x52, - 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x0e, - 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x3a, - 0x0a, 0x0c, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x52, 0x65, 0x71, 0x12, 0x1a, - 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x32, 0xf5, 0x01, 0x0a, 0x0c, 0x41, - 0x67, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x41, - 0x6c, 0x67, 0x6f, 0x12, 0x12, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x41, 0x6c, 0x67, 0x6f, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, - 0x41, 0x6c, 0x67, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x31, - 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x12, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x44, - 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x61, 0x67, 0x65, - 0x6e, 0x74, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x00, 0x12, 0x37, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x14, 0x2e, 0x61, 0x67, - 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x15, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x0b, 0x41, 0x74, - 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x67, 0x65, 0x6e, - 0x74, 0x2e, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x41, 0x74, 0x74, - 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x32, 0xf5, 0x01, 0x0a, + 0x0c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x31, 0x0a, + 0x04, 0x41, 0x6c, 0x67, 0x6f, 0x12, 0x12, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x41, 0x6c, + 0x67, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x61, 0x67, 0x65, 0x6e, + 0x74, 0x2e, 0x41, 0x6c, 0x67, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x31, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x12, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, + 0x2e, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x61, + 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x14, 0x2e, + 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x75, + 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x0b, + 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x67, + 0x65, 0x6e, 0x74, 0x2e, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x41, + 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -703,7 +484,7 @@ func file_agent_agent_proto_rawDescGZIP() []byte { return file_agent_agent_proto_rawDescData } -var file_agent_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_agent_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_agent_agent_proto_goTypes = []interface{}{ (*AlgoRequest)(nil), // 0: agent.AlgoRequest (*AlgoResponse)(nil), // 1: agent.AlgoResponse @@ -713,26 +494,21 @@ var file_agent_agent_proto_goTypes = []interface{}{ (*ResultResponse)(nil), // 5: agent.ResultResponse (*AttestationRequest)(nil), // 6: agent.AttestationRequest (*AttestationResponse)(nil), // 7: agent.AttestationResponse - (*ComputationReq)(nil), // 8: agent.ComputationReq - (*DatasetReq)(nil), // 9: agent.DatasetReq - (*AlgorithmReq)(nil), // 10: agent.AlgorithmReq } var file_agent_agent_proto_depIdxs = []int32{ - 9, // 0: agent.ComputationReq.datasets:type_name -> agent.DatasetReq - 10, // 1: agent.ComputationReq.algorithms:type_name -> agent.AlgorithmReq - 0, // 2: agent.AgentService.Algo:input_type -> agent.AlgoRequest - 2, // 3: agent.AgentService.Data:input_type -> agent.DataRequest - 4, // 4: agent.AgentService.Result:input_type -> agent.ResultRequest - 6, // 5: agent.AgentService.Attestation:input_type -> agent.AttestationRequest - 1, // 6: agent.AgentService.Algo:output_type -> agent.AlgoResponse - 3, // 7: agent.AgentService.Data:output_type -> agent.DataResponse - 5, // 8: agent.AgentService.Result:output_type -> agent.ResultResponse - 7, // 9: agent.AgentService.Attestation:output_type -> agent.AttestationResponse - 6, // [6:10] is the sub-list for method output_type - 2, // [2:6] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 0, // 0: agent.AgentService.Algo:input_type -> agent.AlgoRequest + 2, // 1: agent.AgentService.Data:input_type -> agent.DataRequest + 4, // 2: agent.AgentService.Result:input_type -> agent.ResultRequest + 6, // 3: agent.AgentService.Attestation:input_type -> agent.AttestationRequest + 1, // 4: agent.AgentService.Algo:output_type -> agent.AlgoResponse + 3, // 5: agent.AgentService.Data:output_type -> agent.DataResponse + 5, // 6: agent.AgentService.Result:output_type -> agent.ResultResponse + 7, // 7: agent.AgentService.Attestation:output_type -> agent.AttestationResponse + 4, // [4:8] is the sub-list for method output_type + 0, // [0:4] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } func init() { file_agent_agent_proto_init() } @@ -837,42 +613,6 @@ func file_agent_agent_proto_init() { return nil } } - file_agent_agent_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ComputationReq); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_agent_agent_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DatasetReq); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_agent_agent_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AlgorithmReq); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } } type x struct{} out := protoimpl.TypeBuilder{ @@ -880,7 +620,7 @@ func file_agent_agent_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_agent_agent_proto_rawDesc, NumEnums: 0, - NumMessages: 11, + NumMessages: 8, NumExtensions: 0, NumServices: 1, }, diff --git a/agent/agent.proto b/agent/agent.proto index 2a8370c8..a37fb438 100644 --- a/agent/agent.proto +++ b/agent/agent.proto @@ -39,22 +39,3 @@ message ResultResponse { bytes file = 1; } message AttestationRequest { } message AttestationResponse { bytes file = 1; } - -message ComputationReq { - string id = 1; - string name = 2; - string description = 3; - repeated DatasetReq datasets = 4; - repeated AlgorithmReq algorithms = 5; - repeated string result_consumers = 6; -} - -message DatasetReq { - string provider = 1; - string id = 2; -} - -message AlgorithmReq { - string provider = 1; - string id = 2; -} diff --git a/agent/computations.go b/agent/computations.go index 3f017c42..1dca2316 100644 --- a/agent/computations.go +++ b/agent/computations.go @@ -13,13 +13,24 @@ var ( _ fmt.Stringer = (*Algorithms)(nil) ) +type AgentConfig struct { + LogLevel string `json:"log_level"` + InstanceID string `json:"instance_id"` + NotificationServerURL string `json:"notification_server_url"` + Host string `json:"host"` + Port string `json:"port"` + CertFile string `json:"cert_file"` + KeyFile string `json:"server_key"` +} + type Computation struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Datasets Datasets `json:"datasets,omitempty"` - Algorithms Algorithms `json:"algorithms,omitempty"` - ResultConsumers []string `json:"result_consumers,omitempty"` + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Datasets Datasets `json:"datasets,omitempty"` + Algorithms Algorithms `json:"algorithms,omitempty"` + ResultConsumers []string `json:"result_consumers,omitempty"` + AgentConfig AgentConfig `json:"agent_config,omitempty"` } func (d *Datasets) String() string { diff --git a/api/manager.yml b/api/manager.yml index 2f0a10cb..9faeecd9 100644 --- a/api/manager.yml +++ b/api/manager.yml @@ -108,9 +108,23 @@ components: type: array items: type: string - timeout: - type: string - example: "2s" + agent_config: + type: object + properties: + log_level: + type: string + instance_id: + type: string + notification_server_url: + type: string + host: + type: string + port: + type: string + cert_file: + type: string + key_file: + type: string responses: ServiceError: diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 02661119..2d496889 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -5,22 +5,21 @@ package main import ( "context" "encoding/json" - "errors" "fmt" "log" "os" - "strings" mglog "github.com/absmach/magistrala/logger" "github.com/absmach/magistrala/pkg/uuid" + "github.com/mdlayher/vsock" "github.com/ultravioletrs/cocos/agent" "github.com/ultravioletrs/cocos/agent/api" agentgrpc "github.com/ultravioletrs/cocos/agent/api/grpc" "github.com/ultravioletrs/cocos/internal" - "github.com/ultravioletrs/cocos/internal/env" "github.com/ultravioletrs/cocos/internal/events" "github.com/ultravioletrs/cocos/internal/server" grpcserver "github.com/ultravioletrs/cocos/internal/server/grpc" + "github.com/ultravioletrs/cocos/manager" "golang.org/x/sync/errgroup" "google.golang.org/grpc" "google.golang.org/grpc/reflection" @@ -28,60 +27,47 @@ import ( const ( svcName = "agent" - envPrefixHTTP = "AGENT_HTTP_" - envPrefixGRPC = "AGENT_GRPC_" - defSvcHTTPPort = "9031" defSvcGRPCPort = "7002" ) -var errComputationNotFound = errors.New("computation not found in command line") - -type config struct { - LogLevel string `env:"AGENT_LOG_LEVEL" envDefault:"info"` - InstanceID string `env:"AGENT_INSTANCE_ID" envDefault:""` - NotificationServerURL string `env:"COCOS_NOTIFICATION_SERVER_URL" envDefault:"http://localhost:9000"` -} - func main() { ctx, cancel := context.WithCancel(context.Background()) g, ctx := errgroup.WithContext(ctx) - var cfg config - if err := env.Parse(&cfg); err != nil { - log.Fatalf("failed to load %s configuration : %s", svcName, err) + cfg, err := readConfig() + if err != nil { + log.Fatalf("failed to read agent configuration from vsock %s", err.Error()) } - logger, err := mglog.New(os.Stdout, cfg.LogLevel) + logger, err := mglog.New(os.Stdout, cfg.AgentConfig.LogLevel) if err != nil { log.Fatalf(err.Error()) } - if cfg.InstanceID == "" { - cfg.InstanceID, err = uuid.New().ID() + if cfg.AgentConfig.InstanceID == "" { + cfg.AgentConfig.InstanceID, err = uuid.New().ID() if err != nil { log.Fatalf("Failed to generate instanceID: %s", err) } } - eventSvc := events.New(svcName, cfg.NotificationServerURL) + eventSvc := events.New(svcName, cfg.AgentConfig.NotificationServerURL) svc := newService(ctx, logger, eventSvc) - ac, err := extractComputationValue() - if err != nil { - logger.Fatal(fmt.Sprintf("computation not loaded from cmdline : %s", err.Error())) - } - if _, err := svc.Run(ctx, ac); err != nil { - if err := eventSvc.SendEvent("init", ac.ID, "failed", json.RawMessage{}); err != nil { + if _, err := svc.Run(ctx, cfg); err != nil { + if err := eventSvc.SendEvent("init", cfg.ID, "failed", json.RawMessage{}); err != nil { logger.Warn(err.Error()) } logger.Fatal(fmt.Sprintf("failed to run computation with err: %s", err)) } - grpcServerConfig := server.Config{Port: defSvcGRPCPort} - if err := env.Parse(&grpcServerConfig, env.Options{Prefix: envPrefixGRPC}); err != nil { - log.Printf("failed to load %s gRPC server configuration : %s", svcName, err.Error()) - return + grpcServerConfig := server.Config{ + Port: cfg.AgentConfig.Port, + Host: cfg.AgentConfig.Host, + CertFile: cfg.AgentConfig.CertFile, + KeyFile: cfg.AgentConfig.KeyFile, } + registerAgentServiceServer := func(srv *grpc.Server) { reflection.Register(srv) agent.RegisterAgentServiceServer(srv, agentgrpc.NewServer(svc)) @@ -111,30 +97,29 @@ func newService(ctx context.Context, logger mglog.Logger, eventSvc events.Servic return svc } -// extractComputationValue to extract computation value from the command line. -func extractComputationValue() (agent.Computation, error) { - cmdLineBytes, err := os.ReadFile("/proc/cmdline") +func readConfig() (agent.Computation, error) { + l, err := vsock.Listen(manager.ManagerPort, nil) if err != nil { return agent.Computation{}, err } - cmdLine := string(cmdLineBytes) - paramPrefix := "computation=" - index := strings.Index(string(cmdLine), paramPrefix) - - if index == -1 { - return agent.Computation{}, errComputationNotFound + defer l.Close() + conn, err := l.Accept() + if err != nil { + return agent.Computation{}, err } - - start := index + len(paramPrefix) - end := strings.Index(cmdLine[start:], " ") - - cmpUnescaped := cmdLine[start : start+end] - var ac agent.Computation - if end == -1 { - cmpUnescaped = cmdLine[start:] + defer conn.Close() + b := make([]byte, 1024) + n, err := conn.Read(b) + if err != nil { + return agent.Computation{}, err } - - if err := json.Unmarshal([]byte(cmpUnescaped), &ac); err != nil { + ac := agent.Computation{ + AgentConfig: agent.AgentConfig{ + LogLevel: "info", + Port: defSvcGRPCPort, + }, + } + if err := json.Unmarshal(b[:n], &ac); err != nil { return agent.Computation{}, err } return ac, nil diff --git a/cmd/manager/main.go b/cmd/manager/main.go index a76b3541..3eba408d 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -12,7 +12,6 @@ import ( mglog "github.com/absmach/magistrala/logger" "github.com/absmach/magistrala/pkg/uuid" - "github.com/ultravioletrs/cocos/agent" "github.com/ultravioletrs/cocos/internal" "github.com/ultravioletrs/cocos/internal/env" "github.com/ultravioletrs/cocos/internal/events" @@ -86,7 +85,7 @@ func main() { if err := env.Parse(&qemuCfg, env.Options{Prefix: envPrefixQemu}); err != nil { logger.Fatal(fmt.Sprintf("failed to load QEMU configuration: %s", err)) } - exe, args, err := qemu.ExecutableAndArgs(qemuCfg, agent.Computation{}) + exe, args, err := qemu.ExecutableAndArgs(qemuCfg) if err != nil { logger.Fatal(fmt.Sprintf("failed to parse QEMU configuration: %s", err)) } diff --git a/go.mod b/go.mod index 1b03f6ec..4d2ff4ef 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/go-kit/kit v0.13.0 github.com/go-zoo/bone v1.3.0 github.com/gofrs/uuid v4.4.0+incompatible + github.com/mdlayher/vsock v1.2.1 github.com/prometheus/client_golang v1.18.0 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 @@ -38,6 +39,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect + github.com/mdlayher/socket v0.4.1 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect diff --git a/go.sum b/go.sum index 2c961710..8d90a26e 100644 --- a/go.sum +++ b/go.sum @@ -55,6 +55,10 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= +github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U= +github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= +github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ= +github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnENvE+SE= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/manager/README.md b/manager/README.md index de7e0222..795ce8e5 100644 --- a/manager/README.md +++ b/manager/README.md @@ -47,6 +47,17 @@ sudo apt install qemu-kvm Create `img` directory in `cmd/manager`. Create `tmp` directory in `cmd/manager`. +#### Add V-sock +The necessary kernel modules must be loaded on the hypervisor. +```shell +sudo modprobe vhost_vsock +ls -l /dev/vhost-vsock +# crw-rw-rw- 1 root kvm 10, 241 Jan 16 12:05 /dev/vhost-vsock +ls -l /dev/vsock +# crw-rw-rw- 1 root root 10, 121 Jan 16 12:05 /dev/vsock +``` + + ### Prepare Cocos HAL Cocos HAL for Linux is framework for building custom in-enclave Linux distribution. Use the instructions in [Readme](https://github.com/ultravioletrs/cocos/blob/main/hal/linux/README.md). @@ -78,8 +89,9 @@ qemu-system-x86_64 \ -drive if=pflash,format=raw,unit=0,file=$OVMF_CODE,readonly=on \ -netdev user,id=vmnic,hostfwd=tcp::2222-:22,hostfwd=tcp::9301-:9031,hostfwd=tcp::7020-:7002 \ -device virtio-net-pci,disable-legacy=on,iommu_platform=true,netdev=vmnic,romfile= \ + -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3 -vnc :0 \ -kernel $KERNEL \ - -append "earlyprintk=serial console=ttyS0 computation={\"id\":\"c0d15c5e-e37d-4426-b3b7-b432c966fb09\",\"name\":\"Sample_Computation\",\"description\":\"A_sample_computation\",\"datasets\":[{\"provider\":\"Provider1\",\"id\":\"Dataset1\"},{\"provider\":\"Provider2\",\"id\":\"Dataset2\"}],\"algorithms\":[{\"provider\":\"AlgorithmProvider1\",\"id\":\"Algorithm1\"}],\"result_consumers\":[\"Consumer1\"], \"timeout\":\"10m\"}" \ + -append "earlyprintk=serial console=ttyS0" \ -initrd $INITRD \ -nographic \ -monitor pty \ diff --git a/manager/manager.pb.go b/manager/manager.pb.go index 475eb81a..a2cd3b50 100644 --- a/manager/manager.pb.go +++ b/manager/manager.pb.go @@ -81,6 +81,7 @@ type Computation struct { Datasets []*Dataset `protobuf:"bytes,4,rep,name=datasets,proto3" json:"datasets,omitempty"` Algorithms []*Algorithm `protobuf:"bytes,5,rep,name=algorithms,proto3" json:"algorithms,omitempty"` ResultConsumers []string `protobuf:"bytes,6,rep,name=result_consumers,json=resultConsumers,proto3" json:"result_consumers,omitempty"` + AgentConfig *AgentConfig `protobuf:"bytes,7,opt,name=agent_config,json=agentConfig,proto3" json:"agent_config,omitempty"` } func (x *Computation) Reset() { @@ -157,6 +158,13 @@ func (x *Computation) GetResultConsumers() []string { return nil } +func (x *Computation) GetAgentConfig() *AgentConfig { + if x != nil { + return x.AgentConfig + } + return nil +} + type Dataset struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -314,6 +322,101 @@ func (x *RunResponse) GetAgentAddress() string { return "" } +type AgentConfig struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Port string `protobuf:"bytes,1,opt,name=port,proto3" json:"port,omitempty"` + Host string `protobuf:"bytes,2,opt,name=host,proto3" json:"host,omitempty"` + CertFile string `protobuf:"bytes,3,opt,name=cert_file,json=certFile,proto3" json:"cert_file,omitempty"` + KeyFile string `protobuf:"bytes,4,opt,name=key_file,json=keyFile,proto3" json:"key_file,omitempty"` + LogLevel string `protobuf:"bytes,5,opt,name=log_level,json=logLevel,proto3" json:"log_level,omitempty"` + NotificationsUrl string `protobuf:"bytes,6,opt,name=notifications_url,json=notificationsUrl,proto3" json:"notifications_url,omitempty"` + InstanceId string `protobuf:"bytes,7,opt,name=instance_id,json=instanceId,proto3" json:"instance_id,omitempty"` +} + +func (x *AgentConfig) Reset() { + *x = AgentConfig{} + if protoimpl.UnsafeEnabled { + mi := &file_manager_manager_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AgentConfig) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AgentConfig) ProtoMessage() {} + +func (x *AgentConfig) ProtoReflect() protoreflect.Message { + mi := &file_manager_manager_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AgentConfig.ProtoReflect.Descriptor instead. +func (*AgentConfig) Descriptor() ([]byte, []int) { + return file_manager_manager_proto_rawDescGZIP(), []int{5} +} + +func (x *AgentConfig) GetPort() string { + if x != nil { + return x.Port + } + return "" +} + +func (x *AgentConfig) GetHost() string { + if x != nil { + return x.Host + } + return "" +} + +func (x *AgentConfig) GetCertFile() string { + if x != nil { + return x.CertFile + } + return "" +} + +func (x *AgentConfig) GetKeyFile() string { + if x != nil { + return x.KeyFile + } + return "" +} + +func (x *AgentConfig) GetLogLevel() string { + if x != nil { + return x.LogLevel + } + return "" +} + +func (x *AgentConfig) GetNotificationsUrl() string { + if x != nil { + return x.NotificationsUrl + } + return "" +} + +func (x *AgentConfig) GetInstanceId() string { + if x != nil { + return x.InstanceId + } + return "" +} + var File_manager_manager_proto protoreflect.FileDescriptor var file_manager_manager_proto_rawDesc = []byte{ @@ -323,7 +426,7 @@ var file_manager_manager_proto_rawDesc = []byte{ 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x63, 0x6f, 0x6d, 0x70, 0x75, - 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xe0, 0x01, 0x0a, 0x0b, 0x43, 0x6f, 0x6d, 0x70, 0x75, + 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x99, 0x02, 0x0a, 0x0b, 0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, @@ -337,23 +440,40 @@ var file_manager_manager_proto_rawDesc = []byte{ 0x68, 0x6d, 0x52, 0x0a, 0x61, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x73, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0f, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, - 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x73, 0x22, 0x35, 0x0a, 0x07, 0x44, 0x61, 0x74, - 0x61, 0x73, 0x65, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, - 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, - 0x22, 0x37, 0x0a, 0x09, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x12, 0x1a, 0x0a, + 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x73, 0x12, 0x37, 0x0a, 0x0c, 0x61, 0x67, 0x65, + 0x6e, 0x74, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x14, 0x2e, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0b, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x22, 0x35, 0x0a, 0x07, 0x44, 0x61, 0x74, 0x61, 0x73, 0x65, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x32, 0x0a, 0x0b, 0x52, 0x75, 0x6e, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x61, 0x67, 0x65, 0x6e, - 0x74, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0c, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x32, 0x44, 0x0a, - 0x0e, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, - 0x32, 0x0a, 0x03, 0x52, 0x75, 0x6e, 0x12, 0x13, 0x2e, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, - 0x2e, 0x52, 0x75, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x6d, 0x61, - 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x52, 0x75, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x00, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x37, 0x0a, 0x09, 0x41, 0x6c, 0x67, + 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, + 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, + 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, + 0x69, 0x64, 0x22, 0x32, 0x0a, 0x0b, 0x52, 0x75, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x41, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0xd8, 0x01, 0x0a, 0x0b, 0x41, 0x67, 0x65, 0x6e, 0x74, + 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, + 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x12, 0x1b, + 0x0a, 0x09, 0x63, 0x65, 0x72, 0x74, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x63, 0x65, 0x72, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x6b, + 0x65, 0x79, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6b, + 0x65, 0x79, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6c, 0x6f, 0x67, 0x5f, 0x6c, 0x65, + 0x76, 0x65, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6c, 0x6f, 0x67, 0x4c, 0x65, + 0x76, 0x65, 0x6c, 0x12, 0x2b, 0x0a, 0x11, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, + 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x55, 0x72, 0x6c, + 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, + 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, + 0x64, 0x32, 0x44, 0x0a, 0x0e, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x32, 0x0a, 0x03, 0x52, 0x75, 0x6e, 0x12, 0x13, 0x2e, 0x6d, 0x61, 0x6e, + 0x61, 0x67, 0x65, 0x72, 0x2e, 0x52, 0x75, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x14, 0x2e, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x52, 0x75, 0x6e, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x6d, 0x61, 0x6e, + 0x61, 0x67, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -368,25 +488,27 @@ func file_manager_manager_proto_rawDescGZIP() []byte { return file_manager_manager_proto_rawDescData } -var file_manager_manager_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_manager_manager_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_manager_manager_proto_goTypes = []interface{}{ (*RunRequest)(nil), // 0: manager.RunRequest (*Computation)(nil), // 1: manager.Computation (*Dataset)(nil), // 2: manager.Dataset (*Algorithm)(nil), // 3: manager.Algorithm (*RunResponse)(nil), // 4: manager.RunResponse + (*AgentConfig)(nil), // 5: manager.AgentConfig } var file_manager_manager_proto_depIdxs = []int32{ 1, // 0: manager.RunRequest.computation:type_name -> manager.Computation 2, // 1: manager.Computation.datasets:type_name -> manager.Dataset 3, // 2: manager.Computation.algorithms:type_name -> manager.Algorithm - 0, // 3: manager.ManagerService.Run:input_type -> manager.RunRequest - 4, // 4: manager.ManagerService.Run:output_type -> manager.RunResponse - 4, // [4:5] is the sub-list for method output_type - 3, // [3:4] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 5, // 3: manager.Computation.agent_config:type_name -> manager.AgentConfig + 0, // 4: manager.ManagerService.Run:input_type -> manager.RunRequest + 4, // 5: manager.ManagerService.Run:output_type -> manager.RunResponse + 5, // [5:6] is the sub-list for method output_type + 4, // [4:5] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_manager_manager_proto_init() } @@ -455,6 +577,18 @@ func file_manager_manager_proto_init() { return nil } } + file_manager_manager_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AgentConfig); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -462,7 +596,7 @@ func file_manager_manager_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_manager_manager_proto_rawDesc, NumEnums: 0, - NumMessages: 5, + NumMessages: 6, NumExtensions: 0, NumServices: 1, }, diff --git a/manager/manager.proto b/manager/manager.proto index 6a2d9e3d..b50bbe29 100644 --- a/manager/manager.proto +++ b/manager/manager.proto @@ -22,6 +22,7 @@ message Computation { repeated Dataset datasets = 4; repeated Algorithm algorithms = 5; repeated string result_consumers = 6; + AgentConfig agent_config = 7; } message Dataset { @@ -37,3 +38,13 @@ message Algorithm { message RunResponse { string agent_address = 1; } + +message AgentConfig { + string port = 1; + string host = 2; + string cert_file = 3; + string key_file = 4; + string log_level = 5; + string notifications_url = 6; + string instance_id = 7; +} diff --git a/manager/qemu/config.go b/manager/qemu/config.go index 910d34fb..a42c4e7c 100644 --- a/manager/qemu/config.go +++ b/manager/qemu/config.go @@ -56,6 +56,12 @@ type SevConfig struct { ReducedPhysBits int `env:"SEV_REDUCED_PHYS_BITS" envDefault:"1"` } +type VSockConfig struct { + ID string `env:"VSOCK_ID" envDefault:"vhost-vsock-pci0"` + GuestCID int `env:"VSOCK_GUEST_CID" envDefault:"3"` + vnc int `env:"VSOCK_VNC" envDefault:"0"` +} + type Config struct { TmpFileLoc string `env:"TMP_FILE_LOC" envDefault:"tmp"` UseSudo bool `env:"USE_SUDO" envDefault:"false"` @@ -78,6 +84,9 @@ type Config struct { NetDevConfig VirtioNetPciConfig + // Vsock + VSockConfig + // disk VirtioScsiPciConfig DiskImgConfig @@ -90,7 +99,7 @@ type Config struct { Monitor string `env:"MONITOR" envDefault:"pty"` } -func constructQemuArgs(config Config, computation string) []string { +func constructQemuArgs(config Config) []string { args := []string{} // virtualization @@ -137,9 +146,11 @@ func constructQemuArgs(config Config, computation string) []string { config.VirtioScsiPciConfig.DisableLegacy, config.VirtioScsiPciConfig.IOMMUPlatform)) + args = append(args, "-device", fmt.Sprintf("vhost-vsock-pci,id=%s,guest-cid=%d -vnc :%d", config.VSockConfig.ID, config.VSockConfig.GuestCID, config.VSockConfig.vnc)) + args = append(args, "-kernel", config.DiskImgConfig.KernelFile) - args = append(args, "-append", fmt.Sprintf("earlyprintk=serial console=ttyS0 computation=%s", computation)) + args = append(args, "-append", "earlyprintk=serial console=ttyS0") args = append(args, "-initrd", config.DiskImgConfig.RootFsFile) diff --git a/manager/qemu/qemu.go b/manager/qemu/qemu.go index 1816dfa5..06fc29f0 100644 --- a/manager/qemu/qemu.go +++ b/manager/qemu/qemu.go @@ -4,13 +4,10 @@ package qemu import ( "context" - "encoding/json" "fmt" "os/exec" - "strconv" "github.com/gofrs/uuid" - "github.com/ultravioletrs/cocos/agent" "github.com/ultravioletrs/cocos/internal" ) @@ -21,7 +18,7 @@ const ( rootfsFile = "rootfs.cpio" ) -func CreateVM(ctx context.Context, cfg Config, ac agent.Computation) (*exec.Cmd, error) { +func CreateVM(ctx context.Context, cfg Config) (*exec.Cmd, error) { // Create unique emu device identifiers. id, err := uuid.NewV4() if err != nil { @@ -58,7 +55,7 @@ func CreateVM(ctx context.Context, cfg Config, ac agent.Computation) (*exec.Cmd, } qemuCfg.DiskImgConfig.RootFsFile = dstFile - exe, args, err := ExecutableAndArgs(qemuCfg, ac) + exe, args, err := ExecutableAndArgs(qemuCfg) if err != nil { return &exec.Cmd{}, err } @@ -70,18 +67,13 @@ func CreateVM(ctx context.Context, cfg Config, ac agent.Computation) (*exec.Cmd, return cmd, nil } -func ExecutableAndArgs(cfg Config, ac agent.Computation) (string, []string, error) { +func ExecutableAndArgs(cfg Config) (string, []string, error) { exe, err := exec.LookPath(qemuRelPath) if err != nil { return "", nil, err } - cmpBytes, err := json.Marshal(ac) - if err != nil { - return "", nil, err - } - - args := constructQemuArgs(cfg, strconv.Quote(string(cmpBytes))) + args := constructQemuArgs(cfg) if cfg.UseSudo { args = append([]string{exe}, args...) diff --git a/manager/service.go b/manager/service.go index bb09c059..a5711932 100644 --- a/manager/service.go +++ b/manager/service.go @@ -64,6 +64,15 @@ func (ms *managerService) Run(ctx context.Context, c *Computation) (string, erro Name: c.Name, Description: c.Description, ResultConsumers: c.ResultConsumers, + AgentConfig: agent.AgentConfig{ + Port: c.AgentConfig.Port, + Host: c.AgentConfig.Host, + KeyFile: c.AgentConfig.KeyFile, + CertFile: c.AgentConfig.CertFile, + LogLevel: c.AgentConfig.LogLevel, + InstanceID: c.AgentConfig.InstanceId, + NotificationServerURL: c.AgentConfig.NotificationsUrl, + }, } for _, algo := range c.Algorithms { ac.Algorithms = append(ac.Algorithms, agent.Algorithm{ID: algo.Id, Provider: algo.Provider}) @@ -80,11 +89,16 @@ func (ms *managerService) Run(ctx context.Context, c *Computation) (string, erro ms.qemuCfg.HostFwdAgent = agentPort ms.publishEvent("vm-provision", c.Id, "in-progress", json.RawMessage{}) - if _, err = qemu.CreateVM(ctx, ms.qemuCfg, ac); err != nil { + if _, err = qemu.CreateVM(ctx, ms.qemuCfg); err != nil { ms.publishEvent("vm-provision", c.Id, "failed", json.RawMessage{}) return "", err } + if err := SendAgentConfig(uint32(ms.qemuCfg.VSockConfig.GuestCID), ac); err != nil { + return "", err + } + ms.qemuCfg.VSockConfig.GuestCID++ + ms.publishEvent("vm-provision", c.Id, "complete", json.RawMessage{}) return fmt.Sprintf("%s:%d", ms.hostIP, ms.qemuCfg.HostFwdAgent), nil } diff --git a/manager/vsock.go b/manager/vsock.go new file mode 100644 index 00000000..1fa6aeeb --- /dev/null +++ b/manager/vsock.go @@ -0,0 +1,28 @@ +// Copyright (c) Ultraviolet +// SPDX-License-Identifier: Apache-2.0 +package manager + +import ( + "encoding/json" + + "github.com/mdlayher/vsock" + "github.com/ultravioletrs/cocos/agent" +) + +const ManagerPort uint32 = 9999 + +func SendAgentConfig(cid uint32, ac agent.Computation) error { + conn, err := vsock.Dial(cid, ManagerPort, nil) + if err != nil { + return err + } + defer conn.Close() + payload, err := json.Marshal(ac) + if err != nil { + return err + } + if _, err := conn.Write(payload); err != nil { + return err + } + return nil +}