nomad: Adding Eval model

This commit is contained in:
Armon Dadgar
2015-07-23 15:27:13 -07:00
parent 9f89121751
commit 928ef51130
3 changed files with 40 additions and 69 deletions

View File

@@ -18,8 +18,7 @@ func stateStoreSchema() *memdb.DBSchema {
indexTableSchema,
nodeTableSchema,
jobTableSchema,
taskGroupTableSchema,
taskTableSchema,
evalTableSchema,
allocTableSchema,
}
@@ -129,62 +128,31 @@ func jobTableSchema() *memdb.TableSchema {
}
}
// taskGroupTableSchema returns the MemDB schema for the task group table.
// This table is used to store all the task groups belonging to a job.
func taskGroupTableSchema() *memdb.TableSchema {
// evalTableSchema returns the MemDB schema for the eval table.
// This table is used to store all the evaluations that are pending
// or recently completed.
func evalTableSchema() *memdb.TableSchema {
return &memdb.TableSchema{
Name: "groups",
Name: "evals",
Indexes: map[string]*memdb.IndexSchema{
// Primary index is compount of {Job, Name}
// Primary index is used for direct lookup.
"id": &memdb.IndexSchema{
Name: "id",
AllowMissing: false,
Unique: true,
Indexer: &memdb.CompoundIndex{
AllowMissing: false,
Indexes: []memdb.Indexer{
&memdb.StringFieldIndex{
Field: "JobName",
Lowercase: true,
},
&memdb.StringFieldIndex{
Field: "Name",
Lowercase: true,
},
},
Indexer: &memdb.UUIDFieldIndex{
Field: "ID",
},
},
},
}
}
// taskTableSchema returns the MemDB schema for the tasks table.
// This table is used to store all the task groups belonging to a job.
func taskTableSchema() *memdb.TableSchema {
return &memdb.TableSchema{
Name: "tasks",
Indexes: map[string]*memdb.IndexSchema{
// Primary index is compount of {Job, TaskGroup, Name}
"id": &memdb.IndexSchema{
Name: "id",
// Status is used to scan for evaluations that are in need
// of scheduling attention.
"status": &memdb.IndexSchema{
Name: "status",
AllowMissing: false,
Unique: true,
Indexer: &memdb.CompoundIndex{
AllowMissing: false,
Indexes: []memdb.Indexer{
&memdb.StringFieldIndex{
Field: "JobName",
Lowercase: true,
},
&memdb.StringFieldIndex{
Field: "TaskGroupName",
Lowercase: true,
},
&memdb.StringFieldIndex{
Field: "Name",
Lowercase: true,
},
},
Unique: false,
Indexer: &memdb.StringFieldIndex{
Field: "Status",
},
},
},

View File

@@ -100,7 +100,6 @@ func mockJob() *structs.Job {
"elb_check_interval": "30s",
"elb_check_min": "3",
},
Status: structs.JobStatusPending,
},
},
Meta: map[string]string{

View File

@@ -323,9 +323,6 @@ type Job struct {
// a job and may contain any number of tasks. A task group support running
// in many replicas using the same configuration..
type TaskGroup struct {
// Name of the parent job
JobID string
// Name of the task group
Name string
@@ -343,23 +340,10 @@ type TaskGroup struct {
// Meta is used to associate arbitrary metadata with this
// task group. This is opaque to Nomad.
Meta map[string]string
// Task group status
Status string
// Raft Indexes
CreateIndex uint64
ModifyIndex uint64
}
// Task is a single process typically that is executed as part of a task group.
type Task struct {
// Name of the parent job
JobID string
// Name of the partent task group
TaskGroupName string
// Name of the task
Name string
@@ -379,10 +363,6 @@ type Task struct {
// Meta is used to associate arbitrary metadata with this
// task. This is opaque to Nomad.
Meta map[string]string
// Raft Indexes
CreateIndex uint64
ModifyIndex uint64
}
// Constraints are used to restrict placement options in the case of
@@ -476,6 +456,30 @@ type AllocMetric struct {
AllocationTime time.Duration
}
const (
EvalStatusPending = "pending"
EvalStatusComplete = "complete"
EvalStatusCanceled = "canceled"
)
// Evaluation is used anytime we need to apply business logic as a result
// of a change to our desired state (job specification) or the emergent state
// (registered nodes). When the inputs change, we need to "evaluate" them,
// potentially taking action (allocation of work) or doing nothing if the state
// of the world does not require it.
type Evaluation struct {
// ID is a randonly generated UUID used for this evaluation. This
// is assigned upon the creation of the evaluation.
ID string
// Status of the evaluation
Status string
// Raft Indexes
CreateIndex uint64
ModifyIndex uint64
}
// msgpackHandle is a shared handle for encoding/decoding of structs
var msgpackHandle = &codec.MsgpackHandle{}