コード例 #1
0
func (e *UnregisterSupervisorExecutor) Execute(t *Task) error {
	if e.arg.Host == "" {
		return errors.New("Please specify a host to unregister")
	}
	// TODO(edanaher): With appropriate confirmation (--force?), tear down containers on the host and delete
	// metadata.  Until then, cowardly refuse to tear down supervisors with containers.
	listResponse, err := supervisor.List(e.arg.Host)
	if err != nil {
		return err
	}
	containerCount := len(listResponse.Containers)
	if containerCount > 0 {
		plural := ""
		if containerCount > 1 {
			plural = "s"
		}
		return errors.New(fmt.Sprintf("Supervisor still has %d running container%s", +containerCount, plural))
	}
	supervisor.Teardown(e.arg.Host, []string{}, true)
	err = datamodel.Supervisor(e.arg.Host).Delete()
	if err != nil {
		return err
	}
	e.reply.Status = StatusOk
	return nil
}
コード例 #2
0
ファイル: status.go プロジェクト: irregular/atlantis-manager
func GetUsage() (map[string]*SupervisorUsage, error) {
	// for each supervisor
	//   get health check to figure out total CPUShares, Memory, Price
	//   get list of containers
	//   fill in data in SupervisorUsage
	supers, err := datamodel.ListSupervisors()
	if err != nil {
		return nil, err
	}
	usageMap := map[string]*SupervisorUsage{}
	for _, super := range supers {
		usage := &SupervisorUsage{Containers: map[string]*ContainerUsage{}}
		hreply, err := supervisor.HealthCheck(super)
		if err != nil {
			return nil, err
		}
		usage.Host = super
		price := hreply.Price
		total_cpu := hreply.CPUShares.Total
		total_mem := hreply.Memory.Total
		usage.TotalPrice = price
		usage.TotalContainers = hreply.Containers.Total
		usage.TotalCPUShares = total_cpu
		usage.TotalMemory = total_mem
		lreply, err := supervisor.List(super)
		if err != nil {
			return nil, err
		}
		var conts uint = 0
		var cpu uint = 0
		var mem uint = 0
		var cpu_price float64 = 0.0
		var mem_price float64 = 0.0
		for id, cont := range lreply.Containers {
			conts += 1
			cpu += cont.Manifest.CPUShares
			mem += cont.Manifest.MemoryLimit
			c := price * (float64(cont.Manifest.CPUShares) / float64(total_cpu))
			m := price * (float64(cont.Manifest.MemoryLimit) / float64(total_mem))
			cpu_price += c
			mem_price += m
			usage.Containers[id] = &ContainerUsage{
				ID:        id,
				App:       cont.App,
				Sha:       cont.Sha,
				Env:       cont.Env,
				CPUShares: cont.Manifest.CPUShares,
				Memory:    cont.Manifest.MemoryLimit,
				CPUPrice:  toPrice(c),
				MemPrice:  toPrice(m),
			}
		}
		usage.UsedContainers = conts
		usage.UsedCPUShares = cpu
		usage.UsedMemory = mem
		usage.UsedCPUPrice = toPrice(cpu_price)
		usage.UsedMemPrice = toPrice(mem_price)
		usageMap[super] = usage
	}
	return usageMap, nil
}