Achilleas Tzenetopoulos 5 gadi atpakaļ
vecāks
revīzija
414b3653dd

+ 26 - 49
kubernetes-v1.15.4/pkg/scheduler/algorithm/priorities/custom_resource_allocation.go

@@ -93,33 +93,45 @@ var sockets = map[string]int{
 	"kube-08": 1,
 }
 
-func readFile(cfg *Config, file string) {
-	f, err := os.Open("/etc/kubernetes/scheduler-monitoringDB.yaml")
+func readFile(cfg *Config, file string) error {
+	f, err := os.Open(file)
 	if err != nil {
-		panic(err.Error())
+		klog.Infof("Config file for scheduler not found. Error: %v", err)
+		return err
 	}
 	defer f.Close()
 
 	decoder := yaml.NewDecoder(f)
 	err = decoder.Decode(&cfg)
 	if err != nil {
-		panic(err.Error())
+		klog.Infof("Unable to decode the config file. Error: %v", err)
+		return err
 	}
+	return nil
 }
 
 func customScoreFn(metrics map[string]float64) float64 {
-	return metrics["mem_read"] * metrics["mem_write"] / metrics["ipc"]
+	return metrics["ipc"] / metrics["mem_read"] * metrics["mem_write"]
+}
+
+func onlyIPC(metrics map[string]float64) float64 {
+	return metrics["ipc"]
+}
+
+func onlyL3(metrics map[string]float64) float64 {
+	return 1 / metrics["l3m"]
+}
+
+func onlyNrg(metrics map[string]float64) float64 {
+	return 1 / metrics["procnrg"]
 }
 
 func calculateScore(results map[string]float64,
 	logicFn func(map[string]float64) float64) float64 {
 
 	res := logicFn(results)
-	klog.Infof("Has score (in float) %v\n", res)
+	//klog.Infof("Has score (in float) %v\n", res)
 
-	// TODO
-	// While the final score should be an integer,
-	// find a solution about resolving the float prflduced
 	return res
 }
 
@@ -183,9 +195,12 @@ func customResourceScorer(nodeName string) (float64, error) {
 
 	//read database information
 	var cfg Config
-	readFile(&cfg, "/etc/kubernetes/scheduler-monitoringDB.yaml")
+	err := readFile(&cfg, "/etc/kubernetes/scheduler-monitoringDB.yaml")
+	if err != nil {
+		return 0, err
+	}
 	/*-------------------------------------
-	//TODO read also nodes to uuid mappings
+	//TODO read also nodes to uuid mappings for EVOLVE
 	-------------------------------------*/
 
 	// InfluxDB
@@ -213,42 +228,4 @@ func customResourceScorer(nodeName string) (float64, error) {
 		klog.Infof("Error finding the uuid: %v", ok)
 		return 0, nil
 	}
-
-	// //Close the database connection in the end of the execution
-	// defer db.Close()
-
-	// //Get the uuid of this node in order to query in the database
-	// curr_uuid, ok := nodes[nodeName]
-
-	// //Get the metrics for the current node
-	// if ok {
-	// 	results, err := db.Query("SELECT id, num_sockets, num_cores FROM systems WHERE uuid = ?", curr_uuid)
-
-	// 	if err != nil {
-	// 		panic(err.Error()) // proper error handling instead of panic in your app
-	// 	}
-	// 	sys := System{}
-	// 	sys.Uuid = curr_uuid
-
-	// 	for results.Next() {
-	// 		// for each row, scan the result into our tag composite object
-	// 		err = results.Scan(&sys.ID, &sys.numSockets, &sys.numCores)
-	// 		if err != nil {
-	// 			panic(err.Error()) // proper error handling instead of panic in your app
-	// 		}
-	// 		// and then print out the tag's Name attribute
-	// 		klog.Infof("This is the system with name: %s, id: %d and  number of cores: %d", nodeName, sys.ID, sys.numCores)
-	// 	}
-	// }
-
-	// res := customRequestedScore(nodeName)
-	// klog.Infof("Node name %s, has score %d\n", nodeName, res)
-	// return res, nil
-}
-
-func customRequestedScore(nodeName string) int64 {
-	if nodeName == "kube-01" {
-		return 10
-	}
-	return 0
 }