-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add task implementations for by-passing the java delegate
- Loading branch information
1 parent
7819b5d
commit becf81a
Showing
10 changed files
with
736 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.