Skip to content

Commit

Permalink
Refactor constraints to improve reuse (#4387)
Browse files Browse the repository at this point in the history
* Refactor constraints to improve reuse, To #60096268

Signed-off-by: cheyang <[email protected]>

* Refactor constraints to improve reuse, To #60096268

Signed-off-by: cheyang <[email protected]>

* Refactor constraints to improve reuse, To #60096268

Signed-off-by: cheyang <[email protected]>

* Refactor constraints to improve reuse, To #60096268

Signed-off-by: cheyang <[email protected]>

* Refactor constraints to improve reuse, To #60096268

Signed-off-by: cheyang <[email protected]>

---------

Signed-off-by: cheyang <[email protected]>
  • Loading branch information
cheyang authored Nov 4, 2024
1 parent 98a1946 commit 299452e
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 36 deletions.
4 changes: 0 additions & 4 deletions pkg/ddc/alluxio/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ const (

metricsPrefixBytesReadUfsThroughput = "Cluster.BytesReadUfsThroughput "

summaryPrefixTotalCapacity = "Total Capacity: "

summaryPrefixUsedCapacity = "Used Capacity: "

metadataSyncNotDoneMsg = "[Calculating]"

alluxioRuntimeMetricsLabel = "alluxio_runtime_metrics"
Expand Down
9 changes: 5 additions & 4 deletions pkg/ddc/alluxio/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"github.com/fluid-cloudnative/fluid/pkg/ddc/alluxio/operations"
ddctypes "github.com/fluid-cloudnative/fluid/pkg/ddc/types"
"github.com/fluid-cloudnative/fluid/pkg/utils"
)

Expand All @@ -40,14 +41,14 @@ func (e AlluxioEngine) parseReportSummary(s string) cacheStates {
strs := strings.Split(s, "\n")
for _, str := range strs {
str = strings.TrimSpace(str)
if strings.HasPrefix(str, summaryPrefixTotalCapacity) {
totalCacheCapacityAlluxio, _ := utils.FromHumanSize(strings.TrimPrefix(str, summaryPrefixTotalCapacity))
if strings.HasPrefix(str, ddctypes.SummaryPrefixTotalCapacity) {
totalCacheCapacityAlluxio, _ := utils.FromHumanSize(strings.TrimPrefix(str, ddctypes.SummaryPrefixTotalCapacity))
// Convert Alluxio's binary byte units to Fluid's binary byte units
// e.g. 10KB -> 10KiB, 2GB -> 2GiB
states.cacheCapacity = utils.BytesSize(float64(totalCacheCapacityAlluxio))
}
if strings.HasPrefix(str, summaryPrefixUsedCapacity) {
usedCacheCapacityAlluxio, _ := utils.FromHumanSize(strings.TrimPrefix(str, summaryPrefixUsedCapacity))
if strings.HasPrefix(str, ddctypes.SummaryPrefixUsedCapacity) {
usedCacheCapacityAlluxio, _ := utils.FromHumanSize(strings.TrimPrefix(str, ddctypes.SummaryPrefixUsedCapacity))
// Convert Alluxio's binary byte units to Fluid's binary byte units
// e.g. 10KB -> 10KiB, 2GB -> 2GiB
states.cached = utils.BytesSize(float64(usedCacheCapacityAlluxio))
Expand Down
4 changes: 0 additions & 4 deletions pkg/ddc/goosefs/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ const (

METRICS_PREFIX_BYTES_READ_UFS_THROUGHPUT = "Cluster.BytesReadUfsThroughput "

SUMMARY_PREFIX_TOTAL_CAPACITY = "Total Capacity: "

SUMMARY_PREFIX_USED_CAPACITY = "Used Capacity: "

METADATA_SYNC_NOT_DONE_MSG = "[Calculating]"

GOOSEFS_RUNTIME_METRICS_LABEL = "goosefs_runtime_metrics"
Expand Down
9 changes: 5 additions & 4 deletions pkg/ddc/goosefs/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"github.com/fluid-cloudnative/fluid/pkg/ddc/goosefs/operations"
ddctypes "github.com/fluid-cloudnative/fluid/pkg/ddc/types"
"github.com/fluid-cloudnative/fluid/pkg/utils"
)

Expand All @@ -40,14 +41,14 @@ func (e GooseFSEngine) ParseReportSummary(s string) cacheStates {
strs := strings.Split(s, "\n")
for _, str := range strs {
str = strings.TrimSpace(str)
if strings.HasPrefix(str, SUMMARY_PREFIX_TOTAL_CAPACITY) {
totalCacheCapacityGooseFS, _ := utils.FromHumanSize(strings.TrimPrefix(str, SUMMARY_PREFIX_TOTAL_CAPACITY))
if strings.HasPrefix(str, ddctypes.SummaryPrefixTotalCapacity) {
totalCacheCapacityGooseFS, _ := utils.FromHumanSize(strings.TrimPrefix(str, ddctypes.SummaryPrefixTotalCapacity))
// Convert GooseFS's binary byte units to Fluid's binary byte units
// e.g. 10KB -> 10KiB, 2GB -> 2GiB
states.cacheCapacity = utils.BytesSize(float64(totalCacheCapacityGooseFS))
}
if strings.HasPrefix(str, SUMMARY_PREFIX_USED_CAPACITY) {
usedCacheCapacityGooseFS, _ := utils.FromHumanSize(strings.TrimPrefix(str, SUMMARY_PREFIX_USED_CAPACITY))
if strings.HasPrefix(str, ddctypes.SummaryPrefixUsedCapacity) {
usedCacheCapacityGooseFS, _ := utils.FromHumanSize(strings.TrimPrefix(str, ddctypes.SummaryPrefixUsedCapacity))
// Convert GooseFS's binary byte units to Fluid's binary byte units
// e.g. 10KB -> 10KiB, 2GB -> 2GiB
states.cached = utils.BytesSize(float64(usedCacheCapacityGooseFS))
Expand Down
9 changes: 5 additions & 4 deletions pkg/ddc/jindo/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/fluid-cloudnative/fluid/pkg/ddc/jindo/operations"
ddctypes "github.com/fluid-cloudnative/fluid/pkg/ddc/types"
"github.com/fluid-cloudnative/fluid/pkg/utils"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
)
Expand All @@ -37,14 +38,14 @@ func (e *JindoEngine) queryCacheStatus() (states cacheStates, err error) {
strs := strings.Split(summary, "\n")
for _, str := range strs {
str = strings.TrimSpace(str)
if strings.HasPrefix(str, SUMMARY_PREFIX_TOTAL_CAPACITY) {
totalCacheCapacityJindo, _ := utils.FromHumanSize(strings.TrimPrefix(str, SUMMARY_PREFIX_TOTAL_CAPACITY))
if strings.HasPrefix(str, ddctypes.SummaryPrefixTotalCapacity) {
totalCacheCapacityJindo, _ := utils.FromHumanSize(strings.TrimPrefix(str, ddctypes.SummaryPrefixTotalCapacity))
// Convert JindoFS's binary byte units to Fluid's binary byte units
// e.g. 10KB -> 10KiB, 2GB -> 2GiB
states.cacheCapacity = utils.BytesSize(float64(totalCacheCapacityJindo))
}
if strings.HasPrefix(str, SUMMARY_PREFIX_USED_CAPACITY) {
usedCacheCapacityJindo, _ := utils.FromHumanSize(strings.TrimPrefix(str, SUMMARY_PREFIX_USED_CAPACITY))
if strings.HasPrefix(str, ddctypes.SummaryPrefixUsedCapacity) {
usedCacheCapacityJindo, _ := utils.FromHumanSize(strings.TrimPrefix(str, ddctypes.SummaryPrefixUsedCapacity))
// Convert JindoFS's binary byte units to Fluid's binary byte units
// e.g. 10KB -> 10KiB, 2GB -> 2GiB
states.cached = utils.BytesSize(float64(usedCacheCapacityJindo))
Expand Down
4 changes: 0 additions & 4 deletions pkg/ddc/jindo/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ limitations under the License.
package jindo

const (
SUMMARY_PREFIX_TOTAL_CAPACITY = "Total Capacity: "

SUMMARY_PREFIX_USED_CAPACITY = "Used Capacity: "

METADATA_SYNC_NOT_DONE_MSG = "[Calculating]"

CHECK_METADATA_SYNC_DONE_TIMEOUT_MILLISEC = 500
Expand Down
5 changes: 3 additions & 2 deletions pkg/ddc/jindocache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/fluid-cloudnative/fluid/pkg/ddc/jindocache/operations"
ddctypes "github.com/fluid-cloudnative/fluid/pkg/ddc/types"
"github.com/fluid-cloudnative/fluid/pkg/utils"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
)
Expand All @@ -40,8 +41,8 @@ func (e *JindoCacheEngine) queryCacheStatus() (states cacheStates, err error) {
totalCapacityLabel = SUMMARY_PREFIX_TOTAL_MEM_CAPACITY
usedCapacityLabel = SUMMARY_PREFIX_USED_MEM_CAPACITY
} else {
totalCapacityLabel = SUMMARY_PREFIX_TOTAL_CAPACITY
usedCapacityLabel = SUMMARY_PREFIX_USED_CAPACITY
totalCapacityLabel = ddctypes.SummaryPrefixTotalDiskCapacity
usedCapacityLabel = ddctypes.SummaryPrefixUsedDiskCapacity
}
strs := strings.Split(summary, "\n")
for _, str := range strs {
Expand Down
4 changes: 0 additions & 4 deletions pkg/ddc/jindocache/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ const (

Mount_TYPE = "mount_type"

SUMMARY_PREFIX_TOTAL_CAPACITY = "Total Disk Capacity: "

SUMMARY_PREFIX_USED_CAPACITY = "Used Disk Capacity: "

SUMMARY_PREFIX_TOTAL_MEM_CAPACITY = "Total MEM Capacity: "

SUMMARY_PREFIX_USED_MEM_CAPACITY = "Used MEM Capacity: "
Expand Down
5 changes: 3 additions & 2 deletions pkg/ddc/jindofsx/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/fluid-cloudnative/fluid/pkg/ddc/jindofsx/operations"
ddctypes "github.com/fluid-cloudnative/fluid/pkg/ddc/types"
"github.com/fluid-cloudnative/fluid/pkg/utils"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
)
Expand All @@ -40,8 +41,8 @@ func (e *JindoFSxEngine) queryCacheStatus() (states cacheStates, err error) {
totalCapacityLabel = SUMMARY_PREFIX_TOTAL_MEM_CAPACITY
usedCapacityLabel = SUMMARY_PREFIX_USED_MEM_CAPACITY
} else {
totalCapacityLabel = SUMMARY_PREFIX_TOTAL_CAPACITY
usedCapacityLabel = SUMMARY_PREFIX_USED_CAPACITY
totalCapacityLabel = ddctypes.SummaryPrefixTotalDiskCapacity
usedCapacityLabel = ddctypes.SummaryPrefixUsedDiskCapacity
}
strs := strings.Split(summary, "\n")
for _, str := range strs {
Expand Down
4 changes: 0 additions & 4 deletions pkg/ddc/jindofsx/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ const (

Mount_TYPE = "mount_type"

SUMMARY_PREFIX_TOTAL_CAPACITY = "Total Disk Capacity: "

SUMMARY_PREFIX_USED_CAPACITY = "Used Disk Capacity: "

SUMMARY_PREFIX_TOTAL_MEM_CAPACITY = "Total MEM Capacity: "

SUMMARY_PREFIX_USED_MEM_CAPACITY = "Used MEM Capacity: "
Expand Down
27 changes: 27 additions & 0 deletions pkg/ddc/types/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2024 The Fluid Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package types

const (
SummaryPrefixTotalCapacity = "Total Capacity: "

SummaryPrefixUsedCapacity = "Used Capacity: "

SummaryPrefixTotalDiskCapacity = "Total Disk Capacity: "

SummaryPrefixUsedDiskCapacity = "Used Disk Capacity: "
)

0 comments on commit 299452e

Please sign in to comment.