Merge branch 'f-fix-resource-type' of github.com:hashicorp/nomad into f-fix-resource-type

This commit is contained in:
Preetha Appan 2018-10-16 18:30:12 -05:00
commit 22aee7294e
No known key found for this signature in database
GPG Key ID: 9F7C19990A50EAFC
15 changed files with 61 additions and 71 deletions

View File

@ -171,15 +171,15 @@ type AllocatedTaskResources struct {
}
type AllocatedSharedResources struct {
DiskMB int
DiskMB int64
}
type AllocatedCpuResources struct {
CpuShares int
CpuShares int64
}
type AllocatedMemoryResources struct {
MemoryMB int
MemoryMB int64
}
// AllocIndexSort reverse sorts allocs by CreateIndex.

View File

@ -471,15 +471,15 @@ type NodeResources struct {
}
type NodeCpuResources struct {
TotalShares int
TotalShares int64
}
type NodeMemoryResources struct {
MemoryMB int
MemoryMB int64
}
type NodeDiskResources struct {
DiskMB int
DiskMB int64
}
type NodeReservedResources struct {

View File

@ -207,8 +207,8 @@ type Builder struct {
// secretsDir from task's perspective; eg /secrets
secretsDir string
cpuLimit int
memLimit int
cpuLimit int64
memLimit int64
taskName string
allocIndex int
datacenter string
@ -272,10 +272,10 @@ func (b *Builder) Build() *TaskEnv {
// Add the resource limits
if b.memLimit != 0 {
envMap[MemLimit] = strconv.FormatInt(int64(b.memLimit), 10)
envMap[MemLimit] = strconv.FormatInt(b.memLimit, 10)
}
if b.cpuLimit != 0 {
envMap[CpuLimit] = strconv.FormatInt(int64(b.cpuLimit), 10)
envMap[CpuLimit] = strconv.FormatInt(b.cpuLimit, 10)
}
// Add the task metadata
@ -377,8 +377,8 @@ func (b *Builder) setTask(task *structs.Task) *Builder {
b.cpuLimit = 0
b.networks = []*structs.NetworkResource{}
} else {
b.memLimit = task.Resources.MemoryMB
b.cpuLimit = task.Resources.CPU
b.memLimit = int64(task.Resources.MemoryMB)
b.cpuLimit = int64(task.Resources.CPU)
// Copy networks to prevent sharing
b.networks = make([]*structs.NetworkResource, len(task.Resources.Networks))
for i, n := range task.Resources.Networks {

View File

@ -31,7 +31,7 @@ func (f *CPUFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *cst
resp.NodeResources = &structs.NodeResources{
Cpu: structs.NodeCpuResources{
CpuShares: totalCompute,
CpuShares: int64(totalCompute),
},
}
}

View File

@ -100,7 +100,7 @@ func TestCPUFingerprint_OverrideCompute(t *testing.T) {
if response.Resources.CPU != cfg.CpuCompute {
t.Fatalf("expected override cpu of %d but found %d", cfg.CpuCompute, response.Resources.CPU)
}
if response.NodeResources.Cpu.CpuShares != uint64(cfg.CpuCompute) {
if response.NodeResources.Cpu.CpuShares != int64(cfg.CpuCompute) {
t.Fatalf("expected override cpu of %d but found %d", cfg.CpuCompute, response.NodeResources.Cpu.CpuShares)
}
}

View File

@ -51,7 +51,7 @@ func (f *MemoryFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *
resp.NodeResources = &structs.NodeResources{
Memory: structs.NodeMemoryResources{
MemoryMB: totalMemory / bytesInMB,
MemoryMB: int64(totalMemory / bytesInMB),
},
}
}

View File

@ -53,7 +53,7 @@ func (f *StorageFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp
}
resp.NodeResources = &structs.NodeResources{
Disk: structs.NodeDiskResources{
DiskMB: int(free / bytesPerMegabyte),
DiskMB: int64(free / bytesPerMegabyte),
},
}
resp.Detected = true

View File

@ -266,7 +266,7 @@ func (a *AllocGarbageCollector) MakeRoomFor(allocations []*structs.Allocation) e
if alloc.AllocatedResources != nil {
totalResource.Add(&alloc.AllocatedResources.Shared)
} else {
totalResource.DiskMB += alloc.Resources.DiskMB
totalResource.DiskMB += int64(alloc.Resources.DiskMB)
}
}
@ -284,7 +284,7 @@ func (a *AllocGarbageCollector) MakeRoomFor(allocations []*structs.Allocation) e
}
}
var diskCleared int
var diskCleared int64
for {
select {
case <-a.shutdownCh:
@ -322,11 +322,11 @@ func (a *AllocGarbageCollector) MakeRoomFor(allocations []*structs.Allocation) e
alloc := ar.Alloc()
// COMPAT(0.11): Remove in 0.11
var allocDiskMB int
var allocDiskMB int64
if alloc.AllocatedResources != nil {
allocDiskMB = alloc.AllocatedResources.Shared.DiskMB
} else {
allocDiskMB = alloc.Resources.DiskMB
allocDiskMB = int64(alloc.Resources.DiskMB)
}
// Destroy the alloc runner and wait until it exits

View File

@ -4,6 +4,7 @@ import (
"fmt"
"io"
"io/ioutil"
golog "log"
"net"
"os"
"path/filepath"
@ -13,16 +14,13 @@ import (
"sync/atomic"
"time"
golog "log"
metrics "github.com/armon/go-metrics"
log "github.com/hashicorp/go-hclog"
uuidparse "github.com/hashicorp/go-uuid"
clientconfig "github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/lib"
log "github.com/hashicorp/go-hclog"
uuidparse "github.com/hashicorp/go-uuid"
"github.com/hashicorp/nomad/client"
clientconfig "github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/command/agent/consul"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad"
@ -434,9 +432,9 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) {
res = new(structs.NodeReservedResources)
conf.Node.ReservedResources = res
}
res.Cpu.CpuShares = a.config.Client.Reserved.CPU
res.Memory.MemoryMB = a.config.Client.Reserved.MemoryMB
res.Disk.DiskMB = a.config.Client.Reserved.DiskMB
res.Cpu.CpuShares = int64(a.config.Client.Reserved.CPU)
res.Memory.MemoryMB = int64(a.config.Client.Reserved.MemoryMB)
res.Disk.DiskMB = int64(a.config.Client.Reserved.DiskMB)
res.Networks.ReservedHostPorts = a.config.Client.Reserved.ReservedPorts
conf.Version = a.config.Version

View File

@ -2,6 +2,7 @@ package structs
import (
"bytes"
"container/heap"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
@ -11,6 +12,7 @@ import (
"errors"
"fmt"
"io"
"math"
"net"
"net/url"
"os"
@ -22,26 +24,20 @@ import (
"strings"
"time"
"golang.org/x/crypto/blake2b"
"container/heap"
"math"
hcodec "github.com/hashicorp/go-msgpack/codec"
multierror "github.com/hashicorp/go-multierror"
psstructs "github.com/hashicorp/nomad/plugins/shared/structs"
"github.com/gorhill/cronexpr"
"github.com/hashicorp/consul/api"
hcodec "github.com/hashicorp/go-msgpack/codec"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-version"
"github.com/hashicorp/nomad/acl"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/args"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/lib/kheap"
psstructs "github.com/hashicorp/nomad/plugins/shared/structs"
"github.com/mitchellh/copystructure"
"github.com/ugorji/go/codec"
"golang.org/x/crypto/blake2b"
)
var (
@ -1600,14 +1596,14 @@ func (n *Node) ComparableReservedResources() *ComparableResources {
return &ComparableResources{
Flattened: AllocatedTaskResources{
Cpu: AllocatedCpuResources{
CpuShares: n.Reserved.CPU,
CpuShares: int64(n.Reserved.CPU),
},
Memory: AllocatedMemoryResources{
MemoryMB: n.Reserved.MemoryMB,
MemoryMB: int64(n.Reserved.MemoryMB),
},
},
Shared: AllocatedSharedResources{
DiskMB: n.Reserved.DiskMB,
DiskMB: int64(n.Reserved.DiskMB),
},
}
}
@ -1626,14 +1622,14 @@ func (n *Node) ComparableResources() *ComparableResources {
return &ComparableResources{
Flattened: AllocatedTaskResources{
Cpu: AllocatedCpuResources{
CpuShares: n.Resources.CPU,
CpuShares: int64(n.Resources.CPU),
},
Memory: AllocatedMemoryResources{
MemoryMB: n.Resources.MemoryMB,
MemoryMB: int64(n.Resources.MemoryMB),
},
},
Shared: AllocatedSharedResources{
DiskMB: n.Resources.DiskMB,
DiskMB: int64(n.Resources.DiskMB),
},
}
}
@ -2263,7 +2259,7 @@ func (n *NodeResources) Equals(o *NodeResources) bool {
type NodeCpuResources struct {
// CpuShares is the CPU shares available. This is calculated by number of
// cores multiplied by the core frequency.
CpuShares int
CpuShares int64
}
func (n *NodeCpuResources) Merge(o *NodeCpuResources) {
@ -2295,7 +2291,7 @@ func (n *NodeCpuResources) Equals(o *NodeCpuResources) bool {
// NodeMemoryResources captures the memory resources of the node
type NodeMemoryResources struct {
// MemoryMB is the total available memory on the node
MemoryMB int
MemoryMB int64
}
func (n *NodeMemoryResources) Merge(o *NodeMemoryResources) {
@ -2327,7 +2323,7 @@ func (n *NodeMemoryResources) Equals(o *NodeMemoryResources) bool {
// NodeDiskResources captures the disk resources of the node
type NodeDiskResources struct {
// DiskMB is the total available disk space on the node
DiskMB int
DiskMB int64
}
func (n *NodeDiskResources) Merge(o *NodeDiskResources) {
@ -2601,17 +2597,17 @@ func (n *NodeReservedResources) Comparable() *ComparableResources {
// NodeReservedCpuResources captures the reserved CPU resources of the node.
type NodeReservedCpuResources struct {
CpuShares int
CpuShares int64
}
// NodeReservedMemoryResources captures the reserved memory resources of the node.
type NodeReservedMemoryResources struct {
MemoryMB int
MemoryMB int64
}
// NodeReservedDiskResources captures the reserved disk resources of the node.
type NodeReservedDiskResources struct {
DiskMB int
DiskMB int64
}
// NodeReservedNetworkResources captures the reserved network resources of the node.
@ -2771,7 +2767,7 @@ func (a *AllocatedTaskResources) Subtract(delta *AllocatedTaskResources) {
// AllocatedSharedResources are the set of resources allocated to a task group.
type AllocatedSharedResources struct {
DiskMB int
DiskMB int64
}
func (a *AllocatedSharedResources) Add(delta *AllocatedSharedResources) {
@ -2792,7 +2788,7 @@ func (a *AllocatedSharedResources) Subtract(delta *AllocatedSharedResources) {
// AllocatedCpuResources captures the allocated CPU resources.
type AllocatedCpuResources struct {
CpuShares int
CpuShares int64
}
func (a *AllocatedCpuResources) Add(delta *AllocatedCpuResources) {
@ -2813,7 +2809,7 @@ func (a *AllocatedCpuResources) Subtract(delta *AllocatedCpuResources) {
// AllocatedMemoryResources captures the allocated memory resources.
type AllocatedMemoryResources struct {
MemoryMB int
MemoryMB int64
}
func (a *AllocatedMemoryResources) Add(delta *AllocatedMemoryResources) {
@ -7361,14 +7357,14 @@ func (a *Allocation) ComparableResources() *ComparableResources {
return &ComparableResources{
Flattened: AllocatedTaskResources{
Cpu: AllocatedCpuResources{
CpuShares: resources.CPU,
CpuShares: int64(resources.CPU),
},
Memory: AllocatedMemoryResources{
MemoryMB: resources.MemoryMB,
MemoryMB: int64(resources.MemoryMB),
},
},
Shared: AllocatedSharedResources{
DiskMB: resources.DiskMB,
DiskMB: int64(resources.DiskMB),
},
}
}

View File

@ -6,7 +6,6 @@ import (
log "github.com/hashicorp/go-hclog"
memdb "github.com/hashicorp/go-memdb"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/structs"
@ -482,7 +481,7 @@ func (s *GenericScheduler) computePlacements(destructive, place []placementResul
resources := &structs.AllocatedResources{
Tasks: option.TaskResources,
Shared: structs.AllocatedSharedResources{
DiskMB: tg.EphemeralDisk.SizeMB,
DiskMB: int64(tg.EphemeralDisk.SizeMB),
},
}

View File

@ -2,7 +2,6 @@ package scheduler
import (
"fmt"
"math"
"github.com/hashicorp/nomad/nomad/structs"
@ -193,17 +192,17 @@ OUTER:
Tasks: make(map[string]*structs.AllocatedTaskResources,
len(iter.taskGroup.Tasks)),
Shared: structs.AllocatedSharedResources{
DiskMB: iter.taskGroup.EphemeralDisk.SizeMB,
DiskMB: int64(iter.taskGroup.EphemeralDisk.SizeMB),
},
}
for _, task := range iter.taskGroup.Tasks {
// Allocate the resources
taskResources := &structs.AllocatedTaskResources{
Cpu: structs.AllocatedCpuResources{
CpuShares: task.Resources.CPU,
CpuShares: int64(task.Resources.CPU),
},
Memory: structs.AllocatedMemoryResources{
MemoryMB: task.Resources.MemoryMB,
MemoryMB: int64(task.Resources.MemoryMB),
},
}

View File

@ -51,7 +51,7 @@ func allocUpdateFnInplace(existing *structs.Allocation, _ *structs.Job, newTG *s
newAlloc.AllocatedResources = &structs.AllocatedResources{
Tasks: map[string]*structs.AllocatedTaskResources{},
Shared: structs.AllocatedSharedResources{
DiskMB: newTG.EphemeralDisk.SizeMB,
DiskMB: int64(newTG.EphemeralDisk.SizeMB),
},
}
@ -60,10 +60,10 @@ func allocUpdateFnInplace(existing *structs.Allocation, _ *structs.Job, newTG *s
networks := existing.AllocatedResources.Tasks[task.Name].Copy().Networks
newAlloc.AllocatedResources.Tasks[task.Name] = &structs.AllocatedTaskResources{
Cpu: structs.AllocatedCpuResources{
CpuShares: task.Resources.CPU,
CpuShares: int64(task.Resources.CPU),
},
Memory: structs.AllocatedMemoryResources{
MemoryMB: task.Resources.MemoryMB,
MemoryMB: int64(task.Resources.MemoryMB),
},
Networks: networks,
}

View File

@ -5,7 +5,6 @@ import (
log "github.com/hashicorp/go-hclog"
memdb "github.com/hashicorp/go-memdb"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/structs"
)
@ -318,7 +317,7 @@ func (s *SystemScheduler) computePlacements(place []allocTuple) error {
resources := &structs.AllocatedResources{
Tasks: option.TaskResources,
Shared: structs.AllocatedSharedResources{
DiskMB: missing.TaskGroup.EphemeralDisk.SizeMB,
DiskMB: int64(missing.TaskGroup.EphemeralDisk.SizeMB),
},
}

View File

@ -7,7 +7,6 @@ import (
log "github.com/hashicorp/go-hclog"
memdb "github.com/hashicorp/go-memdb"
"github.com/hashicorp/nomad/nomad/structs"
)
@ -553,7 +552,7 @@ func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job,
newAlloc.AllocatedResources = &structs.AllocatedResources{
Tasks: option.TaskResources,
Shared: structs.AllocatedSharedResources{
DiskMB: update.TaskGroup.EphemeralDisk.SizeMB,
DiskMB: int64(update.TaskGroup.EphemeralDisk.SizeMB),
},
}
newAlloc.Metrics = ctx.Metrics()
@ -829,7 +828,7 @@ func genericAllocUpdateFn(ctx Context, stack Stack, evalID string) allocUpdateTy
newAlloc.AllocatedResources = &structs.AllocatedResources{
Tasks: option.TaskResources,
Shared: structs.AllocatedSharedResources{
DiskMB: newTG.EphemeralDisk.SizeMB,
DiskMB: int64(newTG.EphemeralDisk.SizeMB),
},
}
newAlloc.Metrics = ctx.Metrics()