Skip to content

Commit

Permalink
Add new built-in function for AssignTask
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-son committed Jun 12, 2024
1 parent f8b3bc6 commit 87f9335
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/core/mcis/remoteCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ func RemoteCommandToMcis(nsId string, mcisId string, subGroupId string, vmId str

// Preprocess commands for each VM
vmCommands := make(map[string][]string)
for _, vmId := range vmList {
for i, vmId := range vmList {
processedCommands := make([]string, len(req.Command))
for i, cmd := range req.Command {
processedCmd, err := processCommand(cmd, nsId, mcisId, vmId)
for j, cmd := range req.Command {
processedCmd, err := processCommand(cmd, nsId, mcisId, vmId, i)
if err != nil {
return nil, err
}
processedCommands[i] = processedCmd
processedCommands[j] = processedCmd
}
vmCommands[vmId] = processedCommands
}
Expand Down Expand Up @@ -809,7 +809,7 @@ func findMatchingParenthesis(command string, start int) int {
}

// processCommand is function to replace the keywords with actual values
func processCommand(command, nsId, mcisId, vmId string) (string, error) {
func processCommand(command, nsId, mcisId, vmId string, vmIndex int) (string, error) {
start := 0
for {
start = strings.Index(command[start:], "$$Func(")
Expand Down Expand Up @@ -885,6 +885,13 @@ func processCommand(command, nsId, mcisId, vmId string) (string, error) {
return "", fmt.Errorf("Built-in function getPublicIPs error: %s", err.Error())
}

} else if strings.EqualFold(funcName, "AssignTask") {
taskListParam, ok := params["task"]
if !ok {
return "", fmt.Errorf("Built-in function AssignTask error: no task list provided")
}
tasks := splitParams(taskListParam)
replacement = tasks[vmIndex%len(tasks)]
} else {
return "", fmt.Errorf("Built-in function error in command: Unknown function: %s", funcName)
}
Expand Down

0 comments on commit 87f9335

Please sign in to comment.