Esempio n. 1
0
func SystemUpdate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	rack, err := provider.SystemGet()

	if err != nil {
		return httperr.Server(err)
	}

	notifyData := map[string]string{}

	if count := GetForm(r, "count"); count != "" {
		count, err := strconv.Atoi(count)

		if err != nil {
			return httperr.Server(err)
		}

		rack.Count = count

		notifyData["count"] = strconv.Itoa(count)
	}

	if t := GetForm(r, "type"); t != "" {
		rack.Type = t

		notifyData["type"] = t
	}

	if version := GetForm(r, "version"); version != "" {
		rack.Version = version

		notifyData["version"] = version
	}

	err = provider.SystemSave(*rack)

	if err != nil {
		return httperr.Server(err)
	}

	rack, err = provider.SystemGet()

	if err != nil {
		return httperr.Server(err)
	}

	models.NotifySuccess("rack:update", notifyData)

	return RenderJson(rw, rack)
}
Esempio n. 2
0
func autoscaleRack() {
	log := logger.New("ns=workers.autoscale at=autoscaleRack")

	capacity, err := provider.CapacityGet()

	if err != nil {
		log.Log("fn=models.GetSystemCapacity err=%q", err)
		return
	}

	log.Log("autoscale=%t", autoscale)

	if !autoscale {
		return
	}

	system, err := provider.SystemGet()

	if err != nil {
		log.Log("fn=models.GetSystem err=%q", err)
		return
	}

	// calaculate instance requirements based on total process memory needed divided by the memory
	// on an individual instance
	instances := int(math.Ceil(float64(capacity.ProcessMemory) / float64(capacity.InstanceMemory)))

	// instance count cant be less than 2
	if instances < 2 {
		instances = 2
	}

	// instance count must be at least maxconcurrency+1
	if instances < (int(capacity.ProcessWidth) + 1) {
		instances = int(capacity.ProcessWidth) + 1
	}

	log.Log("process.memory=%d instance.memory=%d instances=%d change=%d", capacity.ProcessMemory, capacity.InstanceMemory, instances, (instances - system.Count))

	// if no change then exit
	if system.Count == instances {
		return
	}

	system.Count = instances

	err = provider.SystemSave(*system)

	if err != nil {
		log.Log("fn=system.Save err=%q", err)
		return
	}
}
Esempio n. 3
0
func SystemShow(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	rack, err := provider.SystemGet()

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such stack: %s", rack)
	}

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, rack)
}
Esempio n. 4
0
func SystemReleaseList(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	rack, err := provider.SystemGet()

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such stack: %s", rack)
	}

	if err != nil {
		return httperr.Server(err)
	}

	releases, err := models.ListReleases(rack.Name)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, releases)
}
Esempio n. 5
0
func heartbeat() {
	system, err := provider.SystemGet()

	if err != nil {
		log.Error(err)
		return
	}

	apps, err := models.ListApps()

	if err != nil {
		log.Error(err)
		return
	}

	helpers.TrackEvent("kernel-heartbeat", map[string]interface{}{
		"app_count":      len(apps),
		"instance_count": system.Count,
		"instance_type":  system.Type,
		"region":         os.Getenv("AWS_REGION"),
		"version":        system.Version,
	})
}
Esempio n. 6
0
func InstanceTerminate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	rack, err := provider.SystemGet()

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such stack: %s", rack)
	}

	if err != nil {
		return httperr.Server(err)
	}

	instanceId := mux.Vars(r)["id"]

	_, err = models.EC2().TerminateInstances(&ec2.TerminateInstancesInput{
		InstanceIds: []*string{&instanceId},
	})

	if err != nil {
		return httperr.Server(err)
	}

	return RenderSuccess(rw)
}