@@ -51,9 +51,14 @@ const (
5151 HookUpdateNodeDmp = "hookUpdateNodeDmp"
5252 HookDeleteNodeDmp = "hookDeleteNodeDmp"
5353
54- BaetylCoreLogLevel = "BaetylCoreLogLevel"
55- LogLevelDebug = "debug"
56- UserID = "UserId"
54+ BaetylCoreLogLevel = "BaetylCoreLogLevel"
55+ BaetylCoreByteUnit = "BaetylCoreByteUint"
56+ BaetylCoreSpeedLimit = "BaetylCoreSpeedLimit"
57+ LogLevelDebug = "debug"
58+ UserID = "UserId"
59+
60+ ByteUnitKB = "KB"
61+ ByteUnitMB = "MB"
5762)
5863
5964var (
@@ -717,12 +722,16 @@ func (api *API) UpdateCoreApp(c *common.Context) (interface{}, error) {
717722 }
718723
719724 logLevel := api .getLogLevel (node )
725+ byteUnit := api .getByteUnit (node )
726+ speedLimit := api .getSpeedLimit (node )
720727
721728 if coreConfig .Version == version &&
722729 coreConfig .Frequency == freq &&
723730 coreConfig .APIPort == port &&
724731 coreConfig .AgentPort == agentPort &&
725- coreConfig .LogLevel == logLevel {
732+ coreConfig .LogLevel == logLevel &&
733+ coreConfig .ByteUnit == byteUnit &&
734+ coreConfig .SpeedLimit == speedLimit {
726735 return api .ToApplicationView (app )
727736 }
728737
@@ -740,8 +749,10 @@ func (api *API) UpdateCoreApp(c *common.Context) (interface{}, error) {
740749 }
741750 node .Attributes [v1 .BaetylCoreAPIPort ] = fmt .Sprintf ("%d" , coreConfig .APIPort )
742751 node .Attributes [BaetylCoreLogLevel ] = coreConfig .LogLevel
752+ node .Attributes [BaetylCoreByteUnit ] = coreConfig .ByteUnit
753+ node .Attributes [BaetylCoreSpeedLimit ] = coreConfig .SpeedLimit
743754
744- err = api .updateCoreAppConfig (app , node , coreConfig . Frequency , coreConfig . AgentPort , coreConfig . LogLevel )
755+ err = api .updateCoreAppConfig (app , node , coreConfig )
745756 if err != nil {
746757 return nil , err
747758 }
@@ -860,6 +871,10 @@ func (api *API) GetCoreAppConfigs(c *common.Context) (interface{}, error) {
860871 }
861872
862873 coreInfo .LogLevel = api .getLogLevel (node )
874+ // get byte unit
875+ coreInfo .ByteUnit = api .getByteUnit (node )
876+ // get s
877+ coreInfo .SpeedLimit = api .getSpeedLimit (node )
863878
864879 return coreInfo , nil
865880}
@@ -1239,21 +1254,23 @@ func (api *API) updateCoreVersions(node *v1.Node, currentVersion, updateVersion
12391254 node .Attributes [BaetylCorePrevVersion ] = currentVersion
12401255}
12411256
1242- func (api * API ) updateCoreAppConfig (app * v1.Application , node * v1.Node , freq , agentPort int , logLevel string ) error {
1257+ func (api * API ) updateCoreAppConfig (app * v1.Application , node * v1.Node , coreConfig * models. NodeCoreConfigs ) error {
12431258 config , err := api .getAppConfig (app , BaetylCoreConfPrefix )
12441259 if err != nil {
12451260 return err
12461261 }
12471262 params := map [string ]interface {}{
1248- "CoreConfName" : config .Name ,
1249- "CoreAppName" : app .Name ,
1250- "NodeMode" : node .NodeMode ,
1251- "CoreFrequency" : fmt .Sprintf ("%ds" , freq ),
1252- "AgentPort" : fmt .Sprintf ("%d" , agentPort ),
1253- "GPUStats" : node .Accelerator != "" ,
1254- "DiskNetStats" : node .NodeMode == context .RunModeKube ,
1255- "QPSStats" : node .NodeMode == context .RunModeKube ,
1256- BaetylCoreLogLevel : logLevel ,
1263+ "CoreConfName" : config .Name ,
1264+ "CoreAppName" : app .Name ,
1265+ "NodeMode" : node .NodeMode ,
1266+ "CoreFrequency" : fmt .Sprintf ("%ds" , coreConfig .Frequency ),
1267+ "AgentPort" : fmt .Sprintf ("%d" , coreConfig .AgentPort ),
1268+ "GPUStats" : node .Accelerator != "" ,
1269+ "DiskNetStats" : node .NodeMode == context .RunModeKube ,
1270+ "QPSStats" : node .NodeMode == context .RunModeKube ,
1271+ BaetylCoreLogLevel : coreConfig .LogLevel ,
1272+ BaetylCoreSpeedLimit : coreConfig .SpeedLimit ,
1273+ BaetylCoreByteUnit : coreConfig .ByteUnit ,
12571274 }
12581275 res , err := api .Init .GetResource (config .Namespace , node .Name , service .TemplateCoreConfYaml , params )
12591276 if err != nil {
@@ -1428,6 +1445,26 @@ func (api *API) getLogLevel(node *v1.Node) string {
14281445 return node .Attributes [BaetylCoreLogLevel ].(string )
14291446}
14301447
1448+ func (api * API ) getByteUnit (node * v1.Node ) string {
1449+ if node .Attributes == nil {
1450+ return ByteUnitKB
1451+ }
1452+ if _ , ok := node .Attributes [BaetylCoreByteUnit ]; ! ok {
1453+ node .Attributes [BaetylCoreByteUnit ] = ByteUnitKB
1454+ }
1455+ return node .Attributes [BaetylCoreByteUnit ].(string )
1456+ }
1457+
1458+ func (api * API ) getSpeedLimit (node * v1.Node ) int {
1459+ if node .Attributes == nil {
1460+ return 0
1461+ }
1462+ if _ , ok := node .Attributes [BaetylCoreSpeedLimit ]; ! ok {
1463+ node .Attributes [BaetylCoreSpeedLimit ] = 0
1464+ }
1465+ return node .Attributes [BaetylCoreSpeedLimit ].(int )
1466+ }
1467+
14311468func (api * API ) updateAgentAppPort (ns string , agent * v1.Application , oldPort , newPort int ) error {
14321469 for i , v := range agent .Services [0 ].Ports {
14331470 if v .HostPort == int32 (oldPort ) {
@@ -1505,7 +1542,17 @@ func (api *API) UpdateConfigByAccelerator(ns string, node *v1.Node) error {
15051542 return err
15061543 }
15071544 logLevel := api .getLogLevel (node )
1508- err = api .updateCoreAppConfig (core , node , freq , agentPort , logLevel )
1545+ speedLimit := api .getSpeedLimit (node )
1546+ byteUint := api .getByteUnit (node )
1547+ err = api .updateCoreAppConfig (core , node , & models.NodeCoreConfigs {
1548+ Version : "" ,
1549+ Frequency : freq ,
1550+ APIPort : 0 ,
1551+ AgentPort : agentPort ,
1552+ LogLevel : logLevel ,
1553+ ByteUnit : byteUint ,
1554+ SpeedLimit : speedLimit ,
1555+ })
15091556 if err != nil {
15101557 return err
15111558 }
0 commit comments