Skip to content

Commit

Permalink
Add task implementations for by-passing the java delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
vistaarjuneja committed Jul 6, 2022
1 parent 7819b5d commit becf81a
Show file tree
Hide file tree
Showing 10 changed files with 736 additions and 0 deletions.
2 changes: 2 additions & 0 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/drone-runners/drone-runner-aws/command/daemon"
"github.com/drone-runners/drone-runner-aws/command/delegate"
"github.com/drone-runners/drone-runner-aws/command/dlite"
"github.com/drone-runners/drone-runner-aws/command/setup"

"gopkg.in/alecthomas/kingpin.v2"
Expand All @@ -28,6 +29,7 @@ func Command() {
registerExec(app)
daemon.Register(app)
delegate.RegisterDelegate(app)
dlite.RegisterDlite(app)
setup.Register(app)

kingpin.Version(version)
Expand Down
7 changes: 7 additions & 0 deletions command/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ type EnvConfig struct {
Acme bool `envconfig:"DRONE_HTTP_ACME"`
}

Dlite struct {
AccountID string `envconfig:"DRONE_DELEGATE_ACCOUNT_ID"`
AccountSecret string `envconfig:"DRONE_DELEGATE_ACCOUNT_SECRET"`
ManagerEndpoint string `envconfig:"DRONE_DELEGATE_MANAGER_ENDPOINT"`
Name string `envconfig:"DRONE_DELEGATE_NAME"`
}

Runner struct {
Name string `envconfig:"DRONE_RUNNER_NAME"`
Capacity int `envconfig:"DRONE_RUNNER_CAPACITY" default:"6"`
Expand Down
46 changes: 46 additions & 0 deletions command/dlite/cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dlite

import (
"context"
"encoding/json"
"net/http"

"github.com/wings-software/dlite/client"
"github.com/wings-software/dlite/logger"
)

type VmCleanupTask struct {
c *dliteCommand
}

type VmCleanupRequest struct {
PoolID string `json:"pool_id"`
StageRuntimeID string `json:"stage_runtime_id"`
}

func (t *VmCleanupTask) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := context.Background() // TODO: Get this from http Request
task := &client.Task{}
err := json.NewDecoder(r.Body).Decode(task)
if err != nil {
logger.WriteBadRequest(w, err)
return
}
// Unmarshal the task data
taskBytes, err := task.Data.MarshalJSON()
if err != nil {
logger.WriteBadRequest(w, err)
return
}
req := &VmCleanupRequest{}
err = json.Unmarshal(taskBytes, req)
if err != nil {
logger.WriteBadRequest(w, err)
return
}
err = t.c.handleDestroy(ctx, req)
if err != nil {
logger.WriteJSON(w, failedResponse(err.Error()), 500)
}
logger.WriteJSON(w, VmTaskExecutionResponse{CommandExecutionStatus: Success}, 200)
}
Loading

0 comments on commit becf81a

Please sign in to comment.