volcano.sh/volcano@v1.9.0/pkg/scheduler/api/cluster_info.go (about)

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package api
    18  
    19  import (
    20  	"fmt"
    21  )
    22  
    23  // ClusterInfo is a snapshot of cluster by cache.
    24  type ClusterInfo struct {
    25  	Jobs           map[JobID]*JobInfo
    26  	Nodes          map[string]*NodeInfo
    27  	Queues         map[QueueID]*QueueInfo
    28  	NamespaceInfo  map[NamespaceName]*NamespaceInfo
    29  	RevocableNodes map[string]*NodeInfo
    30  	NodeList       []string
    31  	CSINodesStatus map[string]*CSINodeStatusInfo
    32  }
    33  
    34  func (ci ClusterInfo) String() string {
    35  	str := "Cache:\n"
    36  
    37  	if len(ci.Nodes) != 0 {
    38  		str += "Nodes:\n"
    39  		for _, n := range ci.Nodes {
    40  			str += fmt.Sprintf("\t %s: idle(%v) used(%v) allocatable(%v) pods(%d)\n",
    41  				n.Name, n.Idle, n.Used, n.Allocatable, len(n.Tasks))
    42  
    43  			i := 0
    44  			for _, p := range n.Tasks {
    45  				str += fmt.Sprintf("\t\t %d: %v\n", i, p)
    46  				i++
    47  			}
    48  		}
    49  	}
    50  
    51  	if len(ci.Jobs) != 0 {
    52  		str += "Jobs:\n"
    53  		for _, job := range ci.Jobs {
    54  			str += fmt.Sprintf("\t Job(%s) name(%s) minAvailable(%v)\n",
    55  				job.UID, job.Name, job.MinAvailable)
    56  
    57  			i := 0
    58  			for _, task := range job.Tasks {
    59  				str += fmt.Sprintf("\t\t %d: %v\n", i, task)
    60  				i++
    61  			}
    62  		}
    63  	}
    64  
    65  	if len(ci.NamespaceInfo) != 0 {
    66  		str += "Namespaces:\n"
    67  		for _, ns := range ci.NamespaceInfo {
    68  			str += fmt.Sprintf("\t Namespace(%s)\n", ns.Name)
    69  		}
    70  	}
    71  
    72  	if len(ci.NodeList) != 0 {
    73  		str += fmt.Sprintf("NodeList: %v\n", ci.NodeList)
    74  	}
    75  
    76  	return str
    77  }