浏览代码

changed custom scoring function

iwita 5 年之前
父节点
当前提交
7598ccb2d0

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+kubernetes/

+ 1 - 0
kubernetes-v1.17/go.mod

@@ -60,6 +60,7 @@ require (
 	github.com/go-openapi/strfmt v0.19.3
 	github.com/go-openapi/validate v0.19.5
 	github.com/go-ozzo/ozzo-validation v3.5.0+incompatible // indirect
+	github.com/go-sql-driver/mysql v1.5.0
 	github.com/godbus/dbus v0.0.0-20181101234600-2ff6f7ffd60f // indirect
 	github.com/gogo/protobuf v1.3.1
 	github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903

+ 2 - 0
kubernetes-v1.17/go.sum

@@ -200,6 +200,8 @@ github.com/go-openapi/validate v0.19.5 h1:QhCBKRYqZR+SKo4gl1lPhPahope8/RLt6EVgY8
 github.com/go-openapi/validate v0.19.5/go.mod h1:8DJv2CVJQ6kGNpFW6eV9N3JviE1C85nY1c2z52x1Gk4=
 github.com/go-ozzo/ozzo-validation v3.5.0+incompatible h1:sUy/in/P6askYr16XJgTKq/0SZhiWsdg4WZGaLsGQkM=
 github.com/go-ozzo/ozzo-validation v3.5.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
+github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
+github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
 github.com/go-toolsmith/astcast v1.0.0/go.mod h1:mt2OdQTeAQcY4DQgPSArJjHCcOwlX+Wl/kwN+LbLGQ4=

+ 51 - 1
kubernetes-v1.17/pkg/scheduler/framework/plugins/noderesources/custom_resource_allocation.go

@@ -27,8 +27,9 @@ package noderesources
 
 import (
 	"context"
+	"database/sql"
 	"fmt"
-
+	_ "github.com/go-sql-driver/mysql"
 	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/klog"
@@ -50,10 +51,27 @@ type nodeMetrics struct {
 	averageIPC    float32
 }
 
+type System struct {
+	ID         int    `json:"id"`
+	Uuid       string `json:"uuid"`
+	numSockets int    `json:"num_sockets"`
+	numCores   int    `json:"num_cores`
+}
+
 type wrongValueError struct{}
 
 var _ = framework.ScorePlugin(&CustomAllocated{})
 
+//Map nodes to uuid
+//var nodes = make(map[string]string)
+
+var nodes = map[string]string{
+	"kube-01": "c4766d29-4dc1-11ea-9d98-0242ac110002",
+	"kube-02": "2",
+	"kube-03": "2",
+	"kube-04": "2",
+}
+
 // CustomAllocatedName is the name of the plugin used in the plugin registry and configurations.
 const CustomAllocatedName = "NodeResourcesCustomAllocated"
 
@@ -64,7 +82,39 @@ func (ca *CustomAllocated) Name() string {
 
 func getCustomMetrics(name string) *nodeMetrics {
 
+	//Open the database connection
+	db, err := sql.Open("mysql", "client:password@tcp(147.102.37.161:3306)/evolve")
+	if err != nil {
+		panic(err.Error())
+	}
+
+	defer db.Close()
+
+	curr_uuid, ok := nodes[name]
+
 	nd := nodeMetrics{}
+
+	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", name, sys.ID, sys.numCores)
+		}
+	}
+	//nd := nodeMetrics{}
 	if name == "kube-01" {
 		nd.L3cacheMisses = 1
 		nd.memoryReads = 1