Initial support for generating Thermos data objects.
This commit is contained in:
parent
51597ecb32
commit
afcdaa84b8
2 changed files with 115 additions and 0 deletions
49
thermos.go
Normal file
49
thermos.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package realis
|
||||
|
||||
|
||||
type ThermosExecutor struct {
|
||||
Task ThermosTask `json:"task""`
|
||||
}
|
||||
|
||||
type ThermosTask struct {
|
||||
Processes []ThermosProcess `json:"processes"`
|
||||
Constraints []ThermosConstraint `json:"constraints"`
|
||||
Resources ThermosResources `json:"resources"`
|
||||
}
|
||||
|
||||
type ThermosConstraint struct {
|
||||
Order []string `json:"order"`
|
||||
}
|
||||
|
||||
type ThermosResources struct {
|
||||
CPU float64 `json:"cpu"`
|
||||
Disk int `json:"disk"`
|
||||
RAM int `json:"ram"`
|
||||
GPU int `json:"gpu"`
|
||||
}
|
||||
|
||||
type ThermosProcess struct {
|
||||
Daemon bool `json:"daemon"`
|
||||
Name string `json:"name"`
|
||||
Ephemeral bool `json:"ephemeral"`
|
||||
MaxFailures int `json:"max_failures"`
|
||||
MinDuration int `json:"min_duration"`
|
||||
Cmdline string `json:"cmdline"`
|
||||
Final bool `json:"final`
|
||||
}
|
||||
|
||||
|
66
thermos_test.go
Normal file
66
thermos_test.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package realis_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/paypal/gorealis/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestThermosTask(t *testing.T) {
|
||||
|
||||
// Test that we can successfully deserialize a minimum subset of an Aurora generated thermos payload
|
||||
thermosJSON := []byte(
|
||||
`{
|
||||
"task": {
|
||||
"processes": [
|
||||
{
|
||||
"daemon": false,
|
||||
"name": "hello",
|
||||
"ephemeral": false,
|
||||
"max_failures": 1,
|
||||
"min_duration": 5,
|
||||
"cmdline": "\n while true; do\n echo hello world from gorealis\n sleep 10\n done\n ",
|
||||
"final": false
|
||||
}
|
||||
],
|
||||
"resources": {
|
||||
"gpu": 0,
|
||||
"disk": 134217728,
|
||||
"ram": 134217728,
|
||||
"cpu": 1.1
|
||||
},
|
||||
"constraints": [
|
||||
{
|
||||
"order": [
|
||||
"hello"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}`)
|
||||
thermos := realis.ThermosExecutor{}
|
||||
|
||||
err := json.Unmarshal(thermosJSON, &thermos)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
thermosExpected := realis.ThermosExecutor{
|
||||
Task: realis.ThermosTask{
|
||||
Processes: []realis.ThermosProcess{
|
||||
{
|
||||
Daemon: false,
|
||||
Name: "hello",
|
||||
Ephemeral: false,
|
||||
MaxFailures: 1,
|
||||
MinDuration: 5,
|
||||
Cmdline: "\n while true; do\n echo hello world from gorealis\n sleep 10\n done\n ",
|
||||
Final: false,
|
||||
},
|
||||
},
|
||||
Constraints: []realis.ThermosConstraint{{Order: []string{"hello"}}},
|
||||
Resources: realis.ThermosResources{CPU: 1.1, Disk: 134217728, RAM: 134217728, GPU: 0}}}
|
||||
|
||||
assert.ObjectsAreEqual(thermosExpected, thermos)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue