nomad: working on allocation schema

This commit is contained in:
Armon Dadgar 2015-07-03 17:11:53 -07:00
parent 00df4837bb
commit 2c694c7e4c
2 changed files with 95 additions and 6 deletions

View File

@ -19,6 +19,7 @@ func stateStoreSchema() *memdb.DBSchema {
jobTableSchema,
taskGroupTableSchema,
taskTableSchema,
allocTableSchema,
}
// Add each of the tables
@ -124,7 +125,7 @@ func taskGroupTableSchema() *memdb.TableSchema {
AllowMissing: false,
Indexes: []memdb.Indexer{
&memdb.StringFieldIndex{
Field: "Job",
Field: "JobName",
Lowercase: true,
},
&memdb.StringFieldIndex{
@ -153,11 +154,11 @@ func taskTableSchema() *memdb.TableSchema {
AllowMissing: false,
Indexes: []memdb.Indexer{
&memdb.StringFieldIndex{
Field: "Job",
Field: "JobName",
Lowercase: true,
},
&memdb.StringFieldIndex{
Field: "TaskGroup",
Field: "TaskGroupName",
Lowercase: true,
},
&memdb.StringFieldIndex{
@ -170,3 +171,55 @@ func taskTableSchema() *memdb.TableSchema {
},
}
}
// allocTableSchema returns the MemDB schema for the allocation table.
// This table is used to store all the task allocations between task groups
// and nodes.
func allocTableSchema() *memdb.TableSchema {
return &memdb.TableSchema{
Name: "allocs",
Indexes: map[string]*memdb.IndexSchema{
// Primary index is a UUID
"id": &memdb.IndexSchema{
Name: "ID",
AllowMissing: false,
Unique: true,
Indexer: &memdb.UUIDFieldIndex{
Field: "ID",
},
},
// Job index is used to lookup allocations by job.
// It is a compound index on {JobName, TaskGroupName}
"job": &memdb.IndexSchema{
Name: "job",
AllowMissing: false,
Unique: false,
Indexer: &memdb.CompoundIndex{
AllowMissing: false,
Indexes: []memdb.Indexer{
&memdb.StringFieldIndex{
Field: "JobName",
Lowercase: true,
},
&memdb.StringFieldIndex{
Field: "TaskGroupName",
Lowercase: true,
},
},
},
},
// Node index is used to lookup allocations by node
"node": &memdb.IndexSchema{
Name: "node",
AllowMissing: false,
Unique: false,
Indexer: &memdb.StringFieldIndex{
Field: "NodeID",
Lowercase: true,
},
},
},
}
}

View File

@ -250,7 +250,7 @@ type Job struct {
// in many replicas using the same configuration..
type TaskGroup struct {
// Name of the parent job
Job string
JobName string
// Name of the task group
Name string
@ -277,10 +277,10 @@ type TaskGroup struct {
// Task is a single process typically that is executed as part of a task group.
type Task struct {
// Name of the parent job
Job string
JobName string
// Name of the partent task group
TaskGroup string
TaskGroupName string
// Name of the task
Name string
@ -314,6 +314,42 @@ type Constraint struct {
Weight int // Soft constraints can vary the weight
}
const (
AllocStatusPending = "pending"
AllocStatusInit = "initializing"
AllocStatusRunning = "running"
AllocStatusComplete = "complete"
AllocStatusDead = "dead"
)
// Allocation is used to allocate the placement of a task group to a node.
type Allocation struct {
// ID of the allocation (UUID)
ID string
// NodeID is the node this is being placed on
NodeID string
// Job is the parent job of the task group being allocated.
// This is copied at allocation time to avoid issues if the job
// definition is updated.
JobName string
Job *Job
// TaskGroup is the task being allocated to the node
// This is copied at allocation time to avoid issues if the job
// definition is updated.
TaskGroupName string
TaskGroup *TaskGroup
// Resources is the set of resources allocated as part
// of this allocation of the task group.
Resources *Resources
// Status of the allocation
Status string
}
// msgpackHandle is a shared handle for encoding/decoding of structs
var msgpackHandle = &codec.MsgpackHandle{}