Skip to content

Commit

Permalink
update to task management for remote execution (#130)
Browse files Browse the repository at this point in the history
* update imporvement of task execution
* update runtaskinremote
* update Improving the processing of tasks determined by the agent to be executed
* update check the status of the task executed on the remote
* update version
  • Loading branch information
Jaehoon Khim authored Oct 1, 2021
1 parent 717ab65 commit e15a488
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 139 deletions.
23 changes: 0 additions & 23 deletions pkg/agent/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package agent
import (
"crypto/rand"
"encoding/hex"
"encoding/json"
"io"
"io/ioutil"
"log"
Expand All @@ -12,7 +11,6 @@ import (
"strconv"
"time"

"github.com/Klevry/klevr/pkg/common"
"github.com/NexClipper/logger"
"github.com/shirou/gopsutil/disk"
netutil "k8s.io/apimachinery/pkg/util/net"
Expand Down Expand Up @@ -90,27 +88,6 @@ func diskUsage(path string) (d DiskStatus) {
return
}

func jsonMarshal(a interface{}) []byte {
b, err := json.Marshal(a)
if err != nil {
logger.Debugf("%v", string(b))
logger.Error(err)
}

return b
}

func jsonUnmarshal(a []byte) (*common.Body, error) {
var body common.Body

err := json.Unmarshal(a, &body)
if err != nil {
return nil, err
}

return &body, nil
}

func readFile(path string) []byte {
data, err := ioutil.ReadFile(path)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (agent *KlevrAgent) handShake() *common.Primary {
rb := &common.Body{}
agent.setBodyMeInfo(rb)
logger.Debugf("%v", rb)
b := jsonMarshal(rb)
b := common.JsonMarshal(rb)
// put in & get out
httpHandler := communicator.Http{
URL: uri,
Expand All @@ -38,7 +38,7 @@ func (agent *KlevrAgent) handShake() *common.Primary {

logger.Debugf("%s", string(result))

body, unmarshalError := jsonUnmarshal(result)
body, unmarshalError := common.JsonUnmarshal(result)
if unmarshalError != nil {
logger.Debugf("Handshake url:%s, agent:%s, api:%s, zone:%s",
uri, agent.AgentKey, agent.ApiKey, agent.Zone)
Expand Down
3 changes: 2 additions & 1 deletion pkg/agent/primary_status_report.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agent

import (
"github.com/Klevry/klevr/pkg/common"
"github.com/Klevry/klevr/pkg/communicator"
"github.com/NexClipper/logger"
)
Expand All @@ -27,7 +28,7 @@ func (agent *KlevrAgent) primaryStatusReport() {
return
}

body, err := jsonUnmarshal(result)
body, err := common.JsonUnmarshal(result)
if err != nil {
logger.Debugf("PrimaryStatusReport url:%s, agent:%s, api:%s, zone:%s", uri, agent.AgentKey, agent.ApiKey, agent.Zone)
logger.Errorf("The content of payload passed after primarystatusreport is unknown (%v)", err)
Expand Down
106 changes: 56 additions & 50 deletions pkg/agent/protobuf/task.pb.go

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

1 change: 1 addition & 0 deletions pkg/agent/protobuf/task.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package agent;
service TaskSend{
rpc SendTask(Message) returns (Message) {}
rpc StatusCheck(Status) returns (Status) {}
rpc GetUpdatedTasks(Message) returns (Message) {}
}

message Message{
Expand Down
38 changes: 37 additions & 1 deletion pkg/agent/protobuf/task_grpc.pb.go

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

Loading

0 comments on commit e15a488

Please sign in to comment.