Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Forward user information from GUI and coconut to Kafka for use by Bookkeeping #591

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions coconut/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"text/template"
"time"

commonpb "github.com/AliceO2Group/Control/common/protos"
"github.com/fatih/color"

"github.com/xlab/treeprint"
Expand Down Expand Up @@ -365,7 +366,13 @@ func CreateEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.C
WithError(err).
Fatal("command finished with error")
}
_, err = rpc.NewAutoEnvironment(cxt, &pb.NewAutoEnvironmentRequest{WorkflowTemplate: wfPath, Vars: extraVarsMap, Id: id}, grpc.EmptyCallOption{})
_, err = rpc.NewAutoEnvironment(cxt, &pb.NewAutoEnvironmentRequest{
WorkflowTemplate: wfPath,
Vars: extraVarsMap,
Id: id,
RequestUser: &commonpb.User{
Name: getUserAndHost(),
}}, grpc.EmptyCallOption{})
if err != nil {
return err
}
Expand Down Expand Up @@ -424,9 +431,23 @@ func CreateEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.C

var response *pb.NewEnvironmentReply
if asynchronous {
response, err = rpc.NewEnvironmentAsync(cxt, &pb.NewEnvironmentRequest{WorkflowTemplate: wfPath, Vars: extraVarsMap, Public: public}, grpc.EmptyCallOption{})
response, err = rpc.NewEnvironmentAsync(cxt, &pb.NewEnvironmentRequest{
WorkflowTemplate: wfPath,
Vars: extraVarsMap,
Public: public,
RequestUser: &commonpb.User{
Name: getUserAndHost(),
},
}, grpc.EmptyCallOption{})
} else {
response, err = rpc.NewEnvironment(cxt, &pb.NewEnvironmentRequest{WorkflowTemplate: wfPath, Vars: extraVarsMap, Public: public}, grpc.EmptyCallOption{})
response, err = rpc.NewEnvironment(cxt, &pb.NewEnvironmentRequest{
WorkflowTemplate: wfPath,
Vars: extraVarsMap,
Public: public,
RequestUser: &commonpb.User{
Name: getUserAndHost(),
},
}, grpc.EmptyCallOption{})
}
if err != nil {
return
Expand Down Expand Up @@ -588,7 +609,13 @@ func ControlEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.
}

var response *pb.ControlEnvironmentReply
response, err = rpc.ControlEnvironment(cxt, &pb.ControlEnvironmentRequest{Id: args[0], Type: pb.ControlEnvironmentRequest_Optype(pb.ControlEnvironmentRequest_Optype_value[event])}, grpc.EmptyCallOption{})
response, err = rpc.ControlEnvironment(cxt, &pb.ControlEnvironmentRequest{
Id: args[0],
Type: pb.ControlEnvironmentRequest_Optype(pb.ControlEnvironmentRequest_Optype_value[event]),
RequestUser: &commonpb.User{
Name: getUserAndHost(),
},
}, grpc.EmptyCallOption{})
if err != nil {
return
}
Expand Down Expand Up @@ -717,7 +744,15 @@ func DestroyEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.
keepTasks = false
}

_, err = rpc.DestroyEnvironment(cxt, &pb.DestroyEnvironmentRequest{Id: envId, KeepTasks: keepTasks, AllowInRunningState: allowInRunningState, Force: force}, grpc.EmptyCallOption{})
_, err = rpc.DestroyEnvironment(cxt, &pb.DestroyEnvironmentRequest{
Id: envId,
KeepTasks: keepTasks,
AllowInRunningState: allowInRunningState,
Force: force,
RequestUser: &commonpb.User{
Name: getUserAndHost(),
},
}, grpc.EmptyCallOption{})
if err != nil {
return
}
Expand Down
19 changes: 19 additions & 0 deletions coconut/control/controlutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"os/user"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -191,3 +193,20 @@ func formatNumber(numberOfMachines int32) string {
}
return nMString
}

func getUserAndHost() string {
userName := "unknown"
hostName := "unknown"

currentUser, err := user.Current()
if err == nil {
userName = currentUser.Username
}

currentHost, err := os.Hostname()
if err == nil {
hostName = currentHost
}

return fmt.Sprintf("%s@%s", userName, hostName)
}
261 changes: 155 additions & 106 deletions coconut/protos/o2control.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions common/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
package common

//go:generate protoc -I=./ --go_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --go-grpc_out=require_unimplemented_servers=false:. protos/events.proto
//go:generate protoc -I=./ --go_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --go-grpc_out=require_unimplemented_servers=false:. protos/common.proto
193 changes: 193 additions & 0 deletions common/protos/common.pb.go

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

41 changes: 41 additions & 0 deletions common/protos/common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* === This file is part of ALICE O² ===
*
* Copyright 2024 CERN and copyright holders of ALICE O².
* Author: Teo Mrnjavac <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In applying this license CERN does not waive the privileges and
* immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*/


syntax = "proto3";

package common;
option java_package = "ch.cern.alice.o2.control.common";
option go_package = "github.com/AliceO2Group/Control/common/protos;pb";

//////////////// Common types ///////////////

message User {
// The unique CERN identifier of this user.
int32 externalId = 1;
// The unique identifier of this entity.
optional int32 id = 2;
// Name of the user.
string name = 3;
}
Loading
Loading