Example #1
0
func Run(clusterData data.Shared) *data.Policy {
	log.WithField("status", "init").Debugln("Gru Planner")
	defer log.WithField("status", "done").Debugln("Gru Planner")

	var chosenPolicy *data.Policy

	if len(clusterData.Service) == 0 {
		log.Warnln("No cluster data for policy computation")
		return chosenPolicy
	}

	srvList := getServicesListFromClusterData(clusterData)
	policies := policy.CreatePolicies(srvList, clusterData)
	chosenPolicy = currentStrategy.MakeDecision(policies)
	data.SavePolicy(*chosenPolicy)
	displayPolicy(chosenPolicy)

	return chosenPolicy
}
Example #2
0
func TestUpdateMetrics(t *testing.T) {
	cfg.SetServices(service.CreateMockServices())

	updateMetrics()
	assert.Equal(t, 0.0, Metrics().Service["service1"].Stats.BaseMetrics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, 0.0, Metrics().Service["service2"].Analytics.BaseAnalytics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, "noaction", Metrics().Policy.Name)

	data.SaveMockStats()
	data.SaveMockAnalytics()
	data.SaveSharedCluster(data.CreateMockShared())
	plc := data.CreateMockPolicy("policy", 1.0, []string{"pippo"}, map[string][]enum.Action{})
	data.SavePolicy(plc)
	updateMetrics()
	assert.Equal(t, 0.6, Metrics().Service["service1"].Stats.BaseMetrics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, 0.1, Metrics().Service["service2"].Analytics.BaseAnalytics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, 0.6, metrics.Service["service1"].Shared.BaseShared[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, "policy", Metrics().Policy.Name)
}