Пример #1
0
func appsFromResponse(b []byte) (tasks []*demand.Task, maxContainers int, err error) {
	var appsMessage AppsMessage

	err = json.Unmarshal(b, &appsMessage)
	if err != nil {
		log.Debugf("Error unmarshalling from %s", string(b[:]))
	}

	maxContainers = appsMessage.MaxContainers

	for _, a := range appsMessage.Apps {
		task := demand.Task{
			Name:          a.Name,
			Image:         a.Config.Image,
			Command:       a.Config.Command,
			Priority:      a.Priority,
			MinContainers: a.MinContainers,
			MaxContainers: a.MaxContainers,
			MaxDelta:      (a.MaxContainers - a.MinContainers),
			IsScalable:    true,

			// TODO!! Settings that need to be made configurable via the API.
			// Default PublishAllPorts to true.
			PublishAllPorts: true,
			// Set Network mode to host only. This won't work for load balancer metrics.
			NetworkMode: "host",
		}

		switch a.RuleType {
		case "Queue":
			task.Target = target.NewQueueLengthTarget(a.Config.QueueLength)
			switch a.MetricType {
			case "AzureQueue":
				task.Metric = metric.NewAzureQueueMetric(a.Config.QueueName)
			case "NSQ":
				task.Metric = metric.NewNSQMetric(a.Config.TopicName, a.Config.ChannelName)
			default:
				log.Errorf("Unexpected queue metricType %s", a.MetricType)
			}
		default:
			task.Target = target.NewRemainderTarget(a.MaxContainers)
			task.Metric = metric.NewNullMetric()
		}

		tasks = append(tasks, &task)
	}

	if err != nil {
		log.Debugf("Apps message: %v", appsMessage)
	}

	return
}
Пример #2
0
// GetApps returns hardcoded task config
func (c *HardcodedConfig) GetApps(userID string) (tasks []*demand.Task, maxContainers int, err error) {

	task := &demand.Task{
		Name:            "consumer",
		Image:           "microscaling/queue-demo:latest",
		Priority:        1,
		MinContainers:   1,
		MaxContainers:   10,
		MaxDelta:        9,
		IsScalable:      true,
		PublishAllPorts: true,
		NetworkMode:     "host",
		Target:          target.NewQueueLengthTarget(50),
		Metric:          metric.NewNSQMetric("microscaling-demo", "microscaling-demo"),
	}

	tasks = append(tasks, task)

	task = &demand.Task{
		Name:            "remainder",
		Image:           "microscaling/priority-2:latest",
		Priority:        2,
		MinContainers:   1,
		MaxContainers:   10,
		MaxDelta:        9,
		IsScalable:      true,
		PublishAllPorts: true,
		NetworkMode:     "host",
		Target:          target.NewRemainderTarget(10),
		Metric:          metric.NewNullMetric(),
	}

	tasks = append(tasks, task)

	maxContainers = 10

	return
}