Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
08cc4c24
Commit
08cc4c24
authored
8 years ago
by
Alex Dadgar
Browse files
Options
Download
Email Patches
Plain Diff
Split reconcile file
parent
d0ea2034
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scheduler/reconcile.go
+0
-127
scheduler/reconcile.go
scheduler/reconcile_util.go
+123
-0
scheduler/reconcile_util.go
with
123 additions
and
127 deletions
+123
-127
scheduler/reconcile.go
+
0
-
127
View file @
08cc4c24
package
scheduler
import
(
"fmt"
"sort"
memdb
"github.com/hashicorp/go-memdb"
...
...
@@ -497,129 +496,3 @@ func (a *allocReconciler) computeUpdates(group *structs.TaskGroup, untainted all
return
}
type
allocMatrix
map
[
string
]
allocSet
func
newAllocMatrix
(
job
*
structs
.
Job
,
allocs
[]
*
structs
.
Allocation
)
allocMatrix
{
m
:=
allocMatrix
(
make
(
map
[
string
]
allocSet
))
for
_
,
a
:=
range
allocs
{
s
,
ok
:=
m
[
a
.
TaskGroup
]
if
!
ok
{
s
=
make
(
map
[
string
]
*
structs
.
Allocation
)
m
[
a
.
TaskGroup
]
=
s
}
s
[
a
.
ID
]
=
a
}
for
_
,
tg
:=
range
job
.
TaskGroups
{
s
,
ok
:=
m
[
tg
.
Name
]
if
!
ok
{
s
=
make
(
map
[
string
]
*
structs
.
Allocation
)
m
[
tg
.
Name
]
=
s
}
}
return
m
}
type
allocSet
map
[
string
]
*
structs
.
Allocation
func
(
a
allocSet
)
GoString
()
string
{
if
len
(
a
)
==
0
{
return
"[]"
}
start
:=
fmt
.
Sprintf
(
"len(%d) [
\n
"
,
len
(
a
))
for
k
:=
range
a
{
start
+=
k
+
",
\n
"
}
return
start
+
"]"
}
func
newAllocSet
(
allocs
[]
*
structs
.
Allocation
)
allocSet
{
s
:=
make
(
map
[
string
]
*
structs
.
Allocation
,
len
(
allocs
))
for
_
,
a
:=
range
allocs
{
s
[
a
.
ID
]
=
a
}
return
s
}
func
(
a
allocSet
)
difference
(
others
...
allocSet
)
allocSet
{
diff
:=
make
(
map
[
string
]
*
structs
.
Allocation
)
OUTER
:
for
k
,
v
:=
range
a
{
for
_
,
other
:=
range
others
{
if
_
,
ok
:=
other
[
k
];
ok
{
continue
OUTER
}
}
diff
[
k
]
=
v
}
return
diff
}
func
(
a
allocSet
)
filterByTainted
(
nodes
map
[
string
]
*
structs
.
Node
)
(
untainted
,
migrate
,
lost
allocSet
)
{
untainted
=
make
(
map
[
string
]
*
structs
.
Allocation
)
migrate
=
make
(
map
[
string
]
*
structs
.
Allocation
)
lost
=
make
(
map
[
string
]
*
structs
.
Allocation
)
for
_
,
alloc
:=
range
a
{
n
,
ok
:=
nodes
[
alloc
.
NodeID
]
switch
{
case
!
ok
:
untainted
[
alloc
.
ID
]
=
alloc
case
n
==
nil
||
n
.
TerminalStatus
()
:
lost
[
alloc
.
ID
]
=
alloc
default
:
migrate
[
alloc
.
ID
]
=
alloc
}
}
return
}
func
(
a
allocSet
)
filterByCanary
()
allocSet
{
canaries
:=
make
(
map
[
string
]
*
structs
.
Allocation
)
for
_
,
alloc
:=
range
a
{
if
alloc
.
Canary
{
canaries
[
alloc
.
ID
]
=
alloc
}
}
return
canaries
}
func
(
a
allocSet
)
filterByDeployment
(
id
string
)
(
match
,
nonmatch
allocSet
)
{
match
=
make
(
map
[
string
]
*
structs
.
Allocation
)
nonmatch
=
make
(
map
[
string
]
*
structs
.
Allocation
)
for
_
,
alloc
:=
range
a
{
if
alloc
.
DeploymentID
==
id
{
match
[
alloc
.
ID
]
=
alloc
}
else
{
nonmatch
[
alloc
.
ID
]
=
alloc
}
}
return
}
func
(
a
allocSet
)
filterByDeploymentHealthy
()
allocSet
{
healthy
:=
make
(
map
[
string
]
*
structs
.
Allocation
)
for
_
,
alloc
:=
range
a
{
if
alloc
.
DeploymentStatus
!=
nil
&&
alloc
.
DeploymentStatus
.
Healthy
!=
nil
&&
*
alloc
.
DeploymentStatus
.
Healthy
{
healthy
[
alloc
.
ID
]
=
alloc
}
}
return
healthy
}
func
(
a
allocSet
)
filterByUpdateType
(
ctx
Context
,
stack
Stack
,
eval
*
structs
.
Evaluation
,
job
*
structs
.
Job
)
(
ignore
,
inplace
,
destructive
allocSet
)
{
ignore
=
make
(
map
[
string
]
*
structs
.
Allocation
)
inplace
=
make
(
map
[
string
]
*
structs
.
Allocation
)
destructive
=
make
(
map
[
string
]
*
structs
.
Allocation
)
for
_
,
alloc
:=
range
a
{
if
alloc
.
Job
.
JobModifyIndex
==
job
.
JobModifyIndex
{
ignore
[
alloc
.
ID
]
=
alloc
continue
}
}
return
}
This diff is collapsed.
Click to expand it.
scheduler/reconcile_util.go
0 → 100644
+
123
-
0
View file @
08cc4c24
package
scheduler
import
(
"fmt"
"github.com/hashicorp/nomad/nomad/structs"
)
// allocMatrix is a mapping of task groups to their allocation set.
type
allocMatrix
map
[
string
]
allocSet
// newAllocMatrix takes a job and the existing allocations for the job and
// creates an allocMatrix
func
newAllocMatrix
(
job
*
structs
.
Job
,
allocs
[]
*
structs
.
Allocation
)
allocMatrix
{
m
:=
allocMatrix
(
make
(
map
[
string
]
allocSet
))
for
_
,
a
:=
range
allocs
{
s
,
ok
:=
m
[
a
.
TaskGroup
]
if
!
ok
{
s
=
make
(
map
[
string
]
*
structs
.
Allocation
)
m
[
a
.
TaskGroup
]
=
s
}
s
[
a
.
ID
]
=
a
}
for
_
,
tg
:=
range
job
.
TaskGroups
{
s
,
ok
:=
m
[
tg
.
Name
]
if
!
ok
{
s
=
make
(
map
[
string
]
*
structs
.
Allocation
)
m
[
tg
.
Name
]
=
s
}
}
return
m
}
// allocSet is a set of allocations with a series of helper functions defined
// that help reconcile state.
type
allocSet
map
[
string
]
*
structs
.
Allocation
// newAllocSet creates an allocation set given a set of allocations
func
newAllocSet
(
allocs
[]
*
structs
.
Allocation
)
allocSet
{
s
:=
make
(
map
[
string
]
*
structs
.
Allocation
,
len
(
allocs
))
for
_
,
a
:=
range
allocs
{
s
[
a
.
ID
]
=
a
}
return
s
}
// GoString provides a human readable view of the set
func
(
a
allocSet
)
GoString
()
string
{
if
len
(
a
)
==
0
{
return
"[]"
}
start
:=
fmt
.
Sprintf
(
"len(%d) [
\n
"
,
len
(
a
))
for
k
:=
range
a
{
start
+=
k
+
",
\n
"
}
return
start
+
"]"
}
// difference returns a new allocSet that has all the existing item except those
// contained within the other allocation sets
func
(
a
allocSet
)
difference
(
others
...
allocSet
)
allocSet
{
diff
:=
make
(
map
[
string
]
*
structs
.
Allocation
)
OUTER
:
for
k
,
v
:=
range
a
{
for
_
,
other
:=
range
others
{
if
_
,
ok
:=
other
[
k
];
ok
{
continue
OUTER
}
}
diff
[
k
]
=
v
}
return
diff
}
// fitlerByTainted takes a set of tainted nodes and filters the allocation set
// into three groups:
// 1. Those that exist on untainted nodes
// 2. Those exist on nodes that are draining
// 3. Those that exist on lost nodes
func
(
a
allocSet
)
filterByTainted
(
nodes
map
[
string
]
*
structs
.
Node
)
(
untainted
,
migrate
,
lost
allocSet
)
{
untainted
=
make
(
map
[
string
]
*
structs
.
Allocation
)
migrate
=
make
(
map
[
string
]
*
structs
.
Allocation
)
lost
=
make
(
map
[
string
]
*
structs
.
Allocation
)
for
_
,
alloc
:=
range
a
{
n
,
ok
:=
nodes
[
alloc
.
NodeID
]
switch
{
case
!
ok
:
untainted
[
alloc
.
ID
]
=
alloc
case
n
==
nil
||
n
.
TerminalStatus
()
:
lost
[
alloc
.
ID
]
=
alloc
default
:
migrate
[
alloc
.
ID
]
=
alloc
}
}
return
}
// filterByCanary returns a new allocation set that contains only canaries
func
(
a
allocSet
)
filterByCanary
()
allocSet
{
canaries
:=
make
(
map
[
string
]
*
structs
.
Allocation
)
for
_
,
alloc
:=
range
a
{
if
alloc
.
Canary
{
canaries
[
alloc
.
ID
]
=
alloc
}
}
return
canaries
}
// filterByDeployment filters allocations into two sets, those that match the
// given deployment ID and those that don't
func
(
a
allocSet
)
filterByDeployment
(
id
string
)
(
match
,
nonmatch
allocSet
)
{
match
=
make
(
map
[
string
]
*
structs
.
Allocation
)
nonmatch
=
make
(
map
[
string
]
*
structs
.
Allocation
)
for
_
,
alloc
:=
range
a
{
if
alloc
.
DeploymentID
==
id
{
match
[
alloc
.
ID
]
=
alloc
}
else
{
nonmatch
[
alloc
.
ID
]
=
alloc
}
}
return
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help