Skip to content
This repository was archived by the owner on Jul 28, 2020. It is now read-only.

Commit cdd1ba4

Browse files
xtreme-stevehiehnAndreas Voellmer
authored andcommitted
Warn if system memory is less than required
Signed-off-by: Andreas Voellmer <[email protected]>
1 parent 6163c4c commit cdd1ba4

File tree

3 files changed

+358
-108
lines changed

3 files changed

+358
-108
lines changed

cmd/start/start.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -401,33 +401,49 @@ func (s *Start) isServiceSupported(service string, services []provision.Service)
401401
return false
402402
}
403403

404-
func (s *Start) allocateMemory(isoConfig iso.Metadata, memoryArg int) (int, error) {
405-
memoryToAllocate := defaultMemory
404+
func (s *Start) allocateMemory(isoConfig iso.Metadata, requestedMem int) (int, error) {
405+
baseMem := defaultMemory
406406
if isoConfig.DefaultMemory > 0 {
407-
fmt.Printf("isoConfig.DefaultMemory %v \n", isoConfig.DefaultMemory)
408-
memoryToAllocate = isoConfig.DefaultMemory
407+
baseMem = isoConfig.DefaultMemory
409408
}
410409

411410
availableMem, err := s.Profiler.GetAvailableMemory()
412411
if err != nil {
413412
return 0, errors.SafeWrap(err, "error retrieving available system memory")
414413
}
415414

416-
customMemProvided := memoryArg > 0
415+
customMemProvided := requestedMem > 0
417416
if customMemProvided {
418-
memoryToAllocate = memoryArg
419-
}
417+
if requestedMem >= baseMem {
418+
if availableMem >= uint64(requestedMem) {
419+
return requestedMem, nil
420+
}
421+
422+
if availableMem < uint64(requestedMem) {
423+
s.UI.Say("WARNING: This machine does not have enough available RAM to run with what is specified.")
424+
return requestedMem, nil
425+
}
426+
}
427+
428+
if requestedMem < baseMem {
429+
s.UI.Say(fmt.Sprintf("WARNING: It is recommended that you run %s Dev with at least %v MB of RAM", strings.ToUpper(isoConfig.DeploymentName), baseMem))
430+
if availableMem >= uint64(requestedMem) {
431+
return requestedMem, nil
432+
}
420433

421-
if !customMemProvided {
422-
if availableMem < uint64(memoryToAllocate) {
423-
s.UI.Say(fmt.Sprintf("WARNING : It is recommended that you run (P) CF Dev with at least %v", memoryToAllocate))
424-
return memoryToAllocate, errors.SafeWrap(err, "not enough system memory")
434+
if availableMem < uint64(requestedMem) {
435+
s.UI.Say("WARNING: This machine does not have enough available RAM to run with what is specified.")
436+
return requestedMem, nil
437+
}
425438
}
426439
} else {
427-
if availableMem < uint64(memoryToAllocate) {
428-
s.UI.Say(fmt.Sprintf("This machine does not have the enough available RAM to run with what is specified."))
440+
if availableMem >= uint64(baseMem) {
441+
return baseMem, nil
442+
} else {
443+
s.UI.Say("WARNING: This machine does not have enough available RAM to run with what is specified.")
444+
return baseMem, nil
429445
}
430446
}
431447

432-
return memoryToAllocate, nil
448+
return 0, nil
433449
}

0 commit comments

Comments
 (0)