From a1cb96b433782b40b1d3e57bf4a68bb352b8c76e Mon Sep 17 00:00:00 2001 From: Henry Haase Date: Fri, 1 Nov 2024 20:22:59 -0500 Subject: [PATCH 1/5] Required metadata to be set on all root nodes for both tree and block topology Signed-off-by: Henry Haase --- pkg/common/const.go | 8 +- pkg/common/types_test.go | 2 +- pkg/engines/k8s/labeler_test.go | 2 + pkg/engines/slurm/slurm.go | 2 +- pkg/factory/engine.go | 8 +- pkg/factory/provider.go | 2 +- pkg/ib/ib.go | 9 +- pkg/models/model.go | 20 +- pkg/models/model_test.go | 2 + pkg/protos/topology.pb.go | 449 +++++++------------- pkg/protos/topology_grpc.pb.go | 2 +- pkg/providers/aws/instance_topology.go | 3 + pkg/providers/aws/instance_topology_test.go | 12 +- pkg/providers/baremetal/mnnvl.go | 6 +- pkg/providers/gcp/instance_topology.go | 3 + pkg/providers/oci/instance_topology.go | 3 + pkg/server/grpc_client.go | 9 +- pkg/server/grpc_client_test.go | 20 +- pkg/translate/output.go | 29 +- pkg/translate/output_test.go | 8 + tests/models/medium-block.yaml | 1 + tests/models/medium-h100.yaml | 1 + tests/models/small-h100.yaml | 1 + 23 files changed, 262 insertions(+), 340 deletions(-) diff --git a/pkg/common/const.go b/pkg/common/const.go index 118cf38..b67f629 100644 --- a/pkg/common/const.go +++ b/pkg/common/const.go @@ -37,8 +37,8 @@ const ( KeySkipReload = "skip_reload" KeyModelPath = "model_path" - KeyPlugin = "plugin" - ValTopologyTree = "topology/tree" - ValTopologyBlock = "topology/block" - NoTopology = "no-topology" + KeyPlugin = "plugin" + TopologyTree = "topology/tree" + TopologyBlock = "topology/block" + NoTopology = "no-topology" ) diff --git a/pkg/common/types_test.go b/pkg/common/types_test.go index d8fb2eb..c50d72b 100644 --- a/pkg/common/types_test.go +++ b/pkg/common/types_test.go @@ -101,7 +101,7 @@ func TestPayload(t *testing.T) { Engine: engine{ Name: "slurm", Params: map[string]string{ - KeyPlugin: ValTopologyBlock, + KeyPlugin: TopologyBlock, KeyBlockSizes: "30,120", }, }, diff --git a/pkg/engines/k8s/labeler_test.go b/pkg/engines/k8s/labeler_test.go index ceb563f..f1f2fb3 100644 --- a/pkg/engines/k8s/labeler_test.go +++ b/pkg/engines/k8s/labeler_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/NVIDIA/topograph/pkg/common" "github.com/NVIDIA/topograph/pkg/translate" ) @@ -40,6 +41,7 @@ func (l *testLabeler) AddNodeLabels(_ context.Context, nodeName string, labels m func TestApplyNodeLabels(t *testing.T) { root, _ := translate.GetTreeTestSet(true) + require.Equal(t, root.Metadata[common.KeyPlugin], common.TopologyTree) labeler := &testLabeler{data: make(map[string]map[string]string)} data := map[string]map[string]string{ "Node201": {"topology.kubernetes.io/network-level-1": "S2", "topology.kubernetes.io/network-level-2": "S1"}, diff --git a/pkg/engines/slurm/slurm.go b/pkg/engines/slurm/slurm.go index 3d58f4c..b365084 100644 --- a/pkg/engines/slurm/slurm.go +++ b/pkg/engines/slurm/slurm.go @@ -79,7 +79,7 @@ func GenerateOutput(ctx context.Context, tree *common.Vertex, params map[string] plugin = tree.Metadata[common.KeyPlugin] } if len(plugin) == 0 { - plugin = common.ValTopologyTree + plugin = common.TopologyTree } if _, err := buf.WriteString(fmt.Sprintf(TopologyHeader, plugin)); err != nil { return nil, err diff --git a/pkg/factory/engine.go b/pkg/factory/engine.go index 9f5d034..c2567f8 100644 --- a/pkg/factory/engine.go +++ b/pkg/factory/engine.go @@ -62,7 +62,11 @@ func (eng *testEngine) GenerateOutput(ctx context.Context, tree *common.Vertex, tree.Metadata = make(map[string]string) } - tree.Metadata[common.KeyPlugin] = params[common.KeyPlugin] - tree.Metadata[common.KeyBlockSizes] = params[common.KeyBlockSizes] + if len(params[common.KeyPlugin]) != 0 { + tree.Metadata[common.KeyPlugin] = params[common.KeyPlugin] + } + if len(params[common.KeyBlockSizes]) != 0 { + tree.Metadata[common.KeyBlockSizes] = params[common.KeyBlockSizes] + } return slurm.GenerateOutput(ctx, tree, params) } diff --git a/pkg/factory/provider.go b/pkg/factory/provider.go index e17cd29..817ebe6 100644 --- a/pkg/factory/provider.go +++ b/pkg/factory/provider.go @@ -79,7 +79,7 @@ func GetTestProvider(params map[string]string) (*testProvider, error) { if err != nil { return nil, err // Wrapped by models.NewModelFromFile } - p.tree, p.instance2node = model.ToTree() + p.tree, p.instance2node = model.ToGraph() } return p, nil } diff --git a/pkg/ib/ib.go b/pkg/ib/ib.go index 1152be5..aad4245 100644 --- a/pkg/ib/ib.go +++ b/pkg/ib/ib.go @@ -65,7 +65,14 @@ func GenerateTopologyConfig(data []byte) (*common.Vertex, error) { } seen = make(map[int]map[string]*Switch) root.simplify(root.getHeight()) - return root.toGraph() + rootNode, err := root.toGraph() + if err != nil { + rootNode.Metadata = map[string]string{ + common.KeyPlugin: common.TopologyTree, + } + return rootNode, nil + } + return nil, err } func (sw *Switch) toGraph() (*common.Vertex, error) { diff --git a/pkg/models/model.go b/pkg/models/model.go index 1b562c0..52d2d23 100644 --- a/pkg/models/model.go +++ b/pkg/models/model.go @@ -26,6 +26,7 @@ import ( ) type Model struct { + Topology string `yaml:"topology"` Switches []Switch `yaml:"switches"` CapacityBlocks []CapacityBlock `yaml:"capacity_blocks"` @@ -64,6 +65,10 @@ func NewModelFromFile(fname string) (*Model, error) { return nil, fmt.Errorf("failed to parse %s: %v", fname, err) } + if model.Topology != common.TopologyTree && model.Topology != common.TopologyBlock { + return nil, fmt.Errorf("unsupported topology type set in model: %s", model.Topology) + } + if err = model.setNodeMap(); err != nil { return nil, err } @@ -140,7 +145,7 @@ func getNetworkLayers(name string, swmap map[string]string) ([]string, error) { } } -func (model *Model) ToTree() (*common.Vertex, map[string]string) { +func (model *Model) ToGraph() (*common.Vertex, map[string]string) { instance2node := make(map[string]string) nodeVertexMap := make(map[string]*common.Vertex) swVertexMap := make(map[string]*common.Vertex) @@ -185,7 +190,7 @@ func (model *Model) ToTree() (*common.Vertex, map[string]string) { } } - // Connects all root vertices to the hidden root + // Connects all root vertices to the hideen tree root treeRoot := &common.Vertex{Vertices: make(map[string]*common.Vertex)} for k, v := range swRootMap { if v { @@ -196,8 +201,13 @@ func (model *Model) ToTree() (*common.Vertex, map[string]string) { for k, v := range blockVertexMap { blockRoot.Vertices[k] = v } - root := &common.Vertex{ - Vertices: map[string]*common.Vertex{common.ValTopologyBlock: blockRoot, common.ValTopologyTree: treeRoot}, + if model.Topology == common.TopologyBlock { + root := &common.Vertex{ + Vertices: map[string]*common.Vertex{common.TopologyBlock: blockRoot, common.TopologyTree: treeRoot}, + Metadata: map[string]string{common.KeyPlugin: common.TopologyTree}, + } + return root, instance2node } - return root, instance2node + treeRoot.Metadata = map[string]string{common.KeyPlugin: common.TopologyTree} + return treeRoot, instance2node } diff --git a/pkg/models/model_test.go b/pkg/models/model_test.go index 3d2a2ce..180f62a 100644 --- a/pkg/models/model_test.go +++ b/pkg/models/model_test.go @@ -19,6 +19,7 @@ package models import ( "testing" + "github.com/NVIDIA/topograph/pkg/common" "github.com/stretchr/testify/require" ) @@ -27,6 +28,7 @@ func TestNewModelFromFile(t *testing.T) { require.NoError(t, err) expected := &Model{ + Topology: common.TopologyTree, Switches: []Switch{ { Name: "sw3", diff --git a/pkg/protos/topology.pb.go b/pkg/protos/topology.pb.go index 8c8029e..3d49c10 100644 --- a/pkg/protos/topology.pb.go +++ b/pkg/protos/topology.pb.go @@ -1,373 +1,236 @@ -// -// Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. -// -// 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. - // Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.34.2 -// protoc v5.27.0 // source: topology.proto package protos import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" ) -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf -type TopologyRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - Provider string `protobuf:"bytes,1,opt,name=provider,proto3" json:"provider,omitempty"` - Region string `protobuf:"bytes,2,opt,name=region,proto3" json:"region,omitempty"` - InstanceIds []string `protobuf:"bytes,3,rep,name=instance_ids,json=instanceIds,proto3" json:"instance_ids,omitempty"` +type TopologyRequest struct { + Provider string `protobuf:"bytes,1,opt,name=provider,proto3" json:"provider,omitempty"` + Region string `protobuf:"bytes,2,opt,name=region,proto3" json:"region,omitempty"` + InstanceIds []string `protobuf:"bytes,3,rep,name=instance_ids,json=instanceIds,proto3" json:"instance_ids,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (x *TopologyRequest) Reset() { - *x = TopologyRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_topology_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } +func (m *TopologyRequest) Reset() { *m = TopologyRequest{} } +func (m *TopologyRequest) String() string { return proto.CompactTextString(m) } +func (*TopologyRequest) ProtoMessage() {} +func (*TopologyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_a326f5bb56fea2fc, []int{0} } -func (x *TopologyRequest) String() string { - return protoimpl.X.MessageStringOf(x) +func (m *TopologyRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_TopologyRequest.Unmarshal(m, b) } - -func (*TopologyRequest) ProtoMessage() {} - -func (x *TopologyRequest) ProtoReflect() protoreflect.Message { - mi := &file_topology_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) +func (m *TopologyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_TopologyRequest.Marshal(b, m, deterministic) } - -// Deprecated: Use TopologyRequest.ProtoReflect.Descriptor instead. -func (*TopologyRequest) Descriptor() ([]byte, []int) { - return file_topology_proto_rawDescGZIP(), []int{0} +func (m *TopologyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_TopologyRequest.Merge(m, src) +} +func (m *TopologyRequest) XXX_Size() int { + return xxx_messageInfo_TopologyRequest.Size(m) } +func (m *TopologyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_TopologyRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_TopologyRequest proto.InternalMessageInfo -func (x *TopologyRequest) GetProvider() string { - if x != nil { - return x.Provider +func (m *TopologyRequest) GetProvider() string { + if m != nil { + return m.Provider } return "" } -func (x *TopologyRequest) GetRegion() string { - if x != nil { - return x.Region +func (m *TopologyRequest) GetRegion() string { + if m != nil { + return m.Region } return "" } -func (x *TopologyRequest) GetInstanceIds() []string { - if x != nil { - return x.InstanceIds +func (m *TopologyRequest) GetInstanceIds() []string { + if m != nil { + return m.InstanceIds } return nil } type TopologyResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Instances []*Instance `protobuf:"bytes,1,rep,name=instances,proto3" json:"instances,omitempty"` + Instances []*Instance `protobuf:"bytes,1,rep,name=instances,proto3" json:"instances,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (x *TopologyResponse) Reset() { - *x = TopologyResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_topology_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } +func (m *TopologyResponse) Reset() { *m = TopologyResponse{} } +func (m *TopologyResponse) String() string { return proto.CompactTextString(m) } +func (*TopologyResponse) ProtoMessage() {} +func (*TopologyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a326f5bb56fea2fc, []int{1} } -func (x *TopologyResponse) String() string { - return protoimpl.X.MessageStringOf(x) +func (m *TopologyResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_TopologyResponse.Unmarshal(m, b) } - -func (*TopologyResponse) ProtoMessage() {} - -func (x *TopologyResponse) ProtoReflect() protoreflect.Message { - mi := &file_topology_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) +func (m *TopologyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_TopologyResponse.Marshal(b, m, deterministic) } - -// Deprecated: Use TopologyResponse.ProtoReflect.Descriptor instead. -func (*TopologyResponse) Descriptor() ([]byte, []int) { - return file_topology_proto_rawDescGZIP(), []int{1} +func (m *TopologyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_TopologyResponse.Merge(m, src) +} +func (m *TopologyResponse) XXX_Size() int { + return xxx_messageInfo_TopologyResponse.Size(m) +} +func (m *TopologyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_TopologyResponse.DiscardUnknown(m) } -func (x *TopologyResponse) GetInstances() []*Instance { - if x != nil { - return x.Instances +var xxx_messageInfo_TopologyResponse proto.InternalMessageInfo + +func (m *TopologyResponse) GetInstances() []*Instance { + if m != nil { + return m.Instances } return nil } type Instance struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - InstanceType string `protobuf:"bytes,2,opt,name=instance_type,json=instanceType,proto3" json:"instance_type,omitempty"` - Provider string `protobuf:"bytes,3,opt,name=provider,proto3" json:"provider,omitempty"` - Region string `protobuf:"bytes,4,opt,name=region,proto3" json:"region,omitempty"` - DataCenter string `protobuf:"bytes,5,opt,name=data_center,json=dataCenter,proto3" json:"data_center,omitempty"` - NetworkLayers []string `protobuf:"bytes,6,rep,name=network_layers,json=networkLayers,proto3" json:"network_layers,omitempty"` - NvlinkDomain string `protobuf:"bytes,7,opt,name=nvlink_domain,json=nvlinkDomain,proto3" json:"nvlink_domain,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + InstanceType string `protobuf:"bytes,2,opt,name=instance_type,json=instanceType,proto3" json:"instance_type,omitempty"` + Provider string `protobuf:"bytes,3,opt,name=provider,proto3" json:"provider,omitempty"` + Region string `protobuf:"bytes,4,opt,name=region,proto3" json:"region,omitempty"` + DataCenter string `protobuf:"bytes,5,opt,name=data_center,json=dataCenter,proto3" json:"data_center,omitempty"` + NetworkLayers []string `protobuf:"bytes,6,rep,name=network_layers,json=networkLayers,proto3" json:"network_layers,omitempty"` + NvlinkDomain string `protobuf:"bytes,7,opt,name=nvlink_domain,json=nvlinkDomain,proto3" json:"nvlink_domain,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Instance) Reset() { *m = Instance{} } +func (m *Instance) String() string { return proto.CompactTextString(m) } +func (*Instance) ProtoMessage() {} +func (*Instance) Descriptor() ([]byte, []int) { + return fileDescriptor_a326f5bb56fea2fc, []int{2} } -func (x *Instance) Reset() { - *x = Instance{} - if protoimpl.UnsafeEnabled { - mi := &file_topology_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } +func (m *Instance) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Instance.Unmarshal(m, b) } - -func (x *Instance) String() string { - return protoimpl.X.MessageStringOf(x) +func (m *Instance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Instance.Marshal(b, m, deterministic) } - -func (*Instance) ProtoMessage() {} - -func (x *Instance) ProtoReflect() protoreflect.Message { - mi := &file_topology_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) +func (m *Instance) XXX_Merge(src proto.Message) { + xxx_messageInfo_Instance.Merge(m, src) } - -// Deprecated: Use Instance.ProtoReflect.Descriptor instead. -func (*Instance) Descriptor() ([]byte, []int) { - return file_topology_proto_rawDescGZIP(), []int{2} +func (m *Instance) XXX_Size() int { + return xxx_messageInfo_Instance.Size(m) +} +func (m *Instance) XXX_DiscardUnknown() { + xxx_messageInfo_Instance.DiscardUnknown(m) } -func (x *Instance) GetId() string { - if x != nil { - return x.Id +var xxx_messageInfo_Instance proto.InternalMessageInfo + +func (m *Instance) GetId() string { + if m != nil { + return m.Id } return "" } -func (x *Instance) GetInstanceType() string { - if x != nil { - return x.InstanceType +func (m *Instance) GetInstanceType() string { + if m != nil { + return m.InstanceType } return "" } -func (x *Instance) GetProvider() string { - if x != nil { - return x.Provider +func (m *Instance) GetProvider() string { + if m != nil { + return m.Provider } return "" } -func (x *Instance) GetRegion() string { - if x != nil { - return x.Region +func (m *Instance) GetRegion() string { + if m != nil { + return m.Region } return "" } -func (x *Instance) GetDataCenter() string { - if x != nil { - return x.DataCenter +func (m *Instance) GetDataCenter() string { + if m != nil { + return m.DataCenter } return "" } -func (x *Instance) GetNetworkLayers() []string { - if x != nil { - return x.NetworkLayers +func (m *Instance) GetNetworkLayers() []string { + if m != nil { + return m.NetworkLayers } return nil } -func (x *Instance) GetNvlinkDomain() string { - if x != nil { - return x.NvlinkDomain +func (m *Instance) GetNvlinkDomain() string { + if m != nil { + return m.NvlinkDomain } return "" } -var File_topology_proto protoreflect.FileDescriptor - -var file_topology_proto_rawDesc = []byte{ - 0x0a, 0x0e, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x12, 0x08, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x22, 0x68, 0x0a, 0x0f, 0x54, 0x6f, - 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, - 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x67, - 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x67, 0x69, 0x6f, - 0x6e, 0x12, 0x21, 0x0a, 0x0c, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x69, 0x64, - 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, - 0x65, 0x49, 0x64, 0x73, 0x22, 0x44, 0x0a, 0x10, 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x30, 0x0a, 0x09, 0x69, 0x6e, 0x73, 0x74, - 0x61, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x74, 0x6f, - 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, - 0x09, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x22, 0xe0, 0x01, 0x0a, 0x08, 0x49, - 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x69, 0x6e, 0x73, 0x74, 0x61, - 0x6e, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, - 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, - 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, - 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x67, 0x69, - 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, - 0x12, 0x1f, 0x0a, 0x0b, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x43, 0x65, 0x6e, 0x74, 0x65, - 0x72, 0x12, 0x25, 0x0a, 0x0e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x5f, 0x6c, 0x61, 0x79, - 0x65, 0x72, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0d, 0x6e, 0x65, 0x74, 0x77, 0x6f, - 0x72, 0x6b, 0x4c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x76, 0x6c, 0x69, - 0x6e, 0x6b, 0x5f, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0c, 0x6e, 0x76, 0x6c, 0x69, 0x6e, 0x6b, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x32, 0x5e, 0x0a, - 0x0f, 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x12, 0x4b, 0x0a, 0x10, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x54, 0x6f, 0x70, 0x6f, - 0x6c, 0x6f, 0x67, 0x79, 0x12, 0x19, 0x2e, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2e, - 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1a, 0x2e, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2e, 0x54, 0x6f, 0x70, 0x6f, 0x6c, - 0x6f, 0x67, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0b, 0x5a, - 0x09, 0x2e, 0x2f, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, -} - -var ( - file_topology_proto_rawDescOnce sync.Once - file_topology_proto_rawDescData = file_topology_proto_rawDesc -) - -func file_topology_proto_rawDescGZIP() []byte { - file_topology_proto_rawDescOnce.Do(func() { - file_topology_proto_rawDescData = protoimpl.X.CompressGZIP(file_topology_proto_rawDescData) - }) - return file_topology_proto_rawDescData -} - -var file_topology_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_topology_proto_goTypes = []any{ - (*TopologyRequest)(nil), // 0: topology.TopologyRequest - (*TopologyResponse)(nil), // 1: topology.TopologyResponse - (*Instance)(nil), // 2: topology.Instance -} -var file_topology_proto_depIdxs = []int32{ - 2, // 0: topology.TopologyResponse.instances:type_name -> topology.Instance - 0, // 1: topology.TopologyService.DescribeTopology:input_type -> topology.TopologyRequest - 1, // 2: topology.TopologyService.DescribeTopology:output_type -> topology.TopologyResponse - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_topology_proto_init() } -func file_topology_proto_init() { - if File_topology_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_topology_proto_msgTypes[0].Exporter = func(v any, i int) any { - switch v := v.(*TopologyRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_topology_proto_msgTypes[1].Exporter = func(v any, i int) any { - switch v := v.(*TopologyResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_topology_proto_msgTypes[2].Exporter = func(v any, i int) any { - switch v := v.(*Instance); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_topology_proto_rawDesc, - NumEnums: 0, - NumMessages: 3, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_topology_proto_goTypes, - DependencyIndexes: file_topology_proto_depIdxs, - MessageInfos: file_topology_proto_msgTypes, - }.Build() - File_topology_proto = out.File - file_topology_proto_rawDesc = nil - file_topology_proto_goTypes = nil - file_topology_proto_depIdxs = nil +func init() { + proto.RegisterType((*TopologyRequest)(nil), "topology.TopologyRequest") + proto.RegisterType((*TopologyResponse)(nil), "topology.TopologyResponse") + proto.RegisterType((*Instance)(nil), "topology.Instance") +} + +func init() { + proto.RegisterFile("topology.proto", fileDescriptor_a326f5bb56fea2fc) +} + +var fileDescriptor_a326f5bb56fea2fc = []byte{ + // 319 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x41, 0x4f, 0xf2, 0x40, + 0x10, 0x86, 0xbf, 0xd2, 0x4f, 0xa4, 0x53, 0x41, 0xb2, 0x07, 0xb3, 0x72, 0x11, 0x6b, 0x4c, 0x38, + 0xa1, 0xc1, 0xa3, 0x37, 0xe5, 0x42, 0xf4, 0x54, 0x39, 0x79, 0xb0, 0x29, 0xdd, 0x09, 0x6e, 0xc0, + 0xdd, 0x75, 0x77, 0xc5, 0xf4, 0xdf, 0xfa, 0x53, 0x0c, 0xcb, 0xb6, 0x0d, 0x46, 0x4f, 0xed, 0x3c, + 0xef, 0x24, 0x7d, 0x66, 0xa6, 0xd0, 0xb3, 0x52, 0xc9, 0xb5, 0x5c, 0x96, 0x63, 0xa5, 0xa5, 0x95, + 0xa4, 0x53, 0xd5, 0xc9, 0x2b, 0x1c, 0xcf, 0xfd, 0x7b, 0x8a, 0xef, 0x1f, 0x68, 0x2c, 0x19, 0x40, + 0x47, 0x69, 0xb9, 0xe1, 0x0c, 0x35, 0x0d, 0x86, 0xc1, 0x28, 0x4a, 0xeb, 0x9a, 0x9c, 0x40, 0x5b, + 0xe3, 0x92, 0x4b, 0x41, 0x5b, 0x2e, 0xf1, 0x15, 0x39, 0x87, 0x23, 0x2e, 0x8c, 0xcd, 0x45, 0x81, + 0x19, 0x67, 0x86, 0x86, 0xc3, 0x70, 0x14, 0xa5, 0x71, 0xc5, 0x66, 0xcc, 0x24, 0x53, 0xe8, 0x37, + 0x5f, 0x32, 0x4a, 0x0a, 0x83, 0xe4, 0x1a, 0xa2, 0xaa, 0xc5, 0xd0, 0x60, 0x18, 0x8e, 0xe2, 0x09, + 0x19, 0xd7, 0xae, 0x33, 0x1f, 0xa5, 0x4d, 0x53, 0xf2, 0x15, 0x40, 0xa7, 0xe2, 0xa4, 0x07, 0x2d, + 0xce, 0xbc, 0x63, 0x8b, 0x33, 0x72, 0x01, 0xdd, 0xda, 0xc2, 0x96, 0x0a, 0xbd, 0x64, 0xad, 0x36, + 0x2f, 0x15, 0xee, 0x8d, 0x17, 0xfe, 0x39, 0xde, 0xff, 0xbd, 0xf1, 0xce, 0x20, 0x66, 0xb9, 0xcd, + 0xb3, 0x02, 0x85, 0x45, 0x4d, 0x0f, 0x5c, 0x08, 0x5b, 0x74, 0xef, 0x08, 0xb9, 0x84, 0x9e, 0x40, + 0xfb, 0x29, 0xf5, 0x2a, 0x5b, 0xe7, 0x25, 0x6a, 0x43, 0xdb, 0x6e, 0x03, 0x5d, 0x4f, 0x1f, 0x1d, + 0xdc, 0x0a, 0x8a, 0xcd, 0x9a, 0x8b, 0x55, 0xc6, 0xe4, 0x5b, 0xce, 0x05, 0x3d, 0xdc, 0x09, 0xee, + 0xe0, 0xd4, 0xb1, 0xc9, 0x4b, 0x73, 0x92, 0x27, 0xd4, 0x1b, 0x5e, 0x20, 0x79, 0x80, 0xfe, 0x14, + 0x4d, 0xa1, 0xf9, 0x02, 0xab, 0x88, 0x9c, 0x36, 0x8b, 0xfa, 0x71, 0xc1, 0xc1, 0xe0, 0xb7, 0x68, + 0xb7, 0xf2, 0xe4, 0xdf, 0x5d, 0xfc, 0x1c, 0x8d, 0xaf, 0x6e, 0xdd, 0x8f, 0x60, 0x16, 0x6d, 0xf7, + 0xbc, 0xf9, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x8e, 0xc6, 0xe8, 0x6b, 0x22, 0x02, 0x00, 0x00, } diff --git a/pkg/protos/topology_grpc.pb.go b/pkg/protos/topology_grpc.pb.go index 637747c..a5ec5ea 100644 --- a/pkg/protos/topology_grpc.pb.go +++ b/pkg/protos/topology_grpc.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.5.1 -// - protoc v5.27.0 +// - protoc v3.12.4 // source: topology.proto package protos diff --git a/pkg/providers/aws/instance_topology.go b/pkg/providers/aws/instance_topology.go index a3c333e..bcee680 100644 --- a/pkg/providers/aws/instance_topology.go +++ b/pkg/providers/aws/instance_topology.go @@ -191,6 +191,9 @@ func toGraph(topology []types.InstanceTopology, cis []common.ComputeInstances) ( root := &common.Vertex{ Vertices: make(map[string]*common.Vertex), + Metadata: map[string]string{ + common.KeyPlugin: common.TopologyTree, + }, } for name, node := range forest { root.Vertices[name] = node diff --git a/pkg/providers/aws/instance_topology_test.go b/pkg/providers/aws/instance_topology_test.go index 9ddbe53..d169616 100644 --- a/pkg/providers/aws/instance_topology_test.go +++ b/pkg/providers/aws/instance_topology_test.go @@ -105,9 +105,17 @@ func TestNewInstanceTopology(t *testing.T) { }, } - v1 := &common.Vertex{ID: "nn-098f9e7674016cb1c", Vertices: map[string]*common.Vertex{"nn-224a2a4d9df61a975": v2}} + v1 := &common.Vertex{ + ID: "nn-098f9e7674016cb1c", + Vertices: map[string]*common.Vertex{"nn-224a2a4d9df61a975": v2}, + } - expected := &common.Vertex{Vertices: map[string]*common.Vertex{"nn-098f9e7674016cb1c": v1}} + expected := &common.Vertex{ + Vertices: map[string]*common.Vertex{"nn-098f9e7674016cb1c": v1}, + Metadata: map[string]string{ + common.KeyPlugin: common.TopologyTree, + }, + } tree, err := toGraph(topology, []common.ComputeInstances{{Instances: i2n}}) require.NoError(t, err) diff --git a/pkg/providers/baremetal/mnnvl.go b/pkg/providers/baremetal/mnnvl.go index 405b1d0..7014b77 100644 --- a/pkg/providers/baremetal/mnnvl.go +++ b/pkg/providers/baremetal/mnnvl.go @@ -188,7 +188,7 @@ func toGraph(domainMap map[string]domain, treeRoot *common.Vertex) *common.Verte blockRoot := &common.Vertex{ Vertices: make(map[string]*common.Vertex), } - root.Vertices[common.ValTopologyTree] = treeRoot + root.Vertices[common.TopologyTree] = treeRoot for domainName, domain := range domainMap { tree := &common.Vertex{ ID: domainName, @@ -201,8 +201,8 @@ func toGraph(domainMap map[string]domain, treeRoot *common.Vertex) *common.Verte } // add root metadata root.Metadata[common.KeyEngine] = common.EngineSLURM - root.Metadata[common.KeyPlugin] = common.ValTopologyBlock - root.Vertices[common.ValTopologyBlock] = blockRoot + root.Metadata[common.KeyPlugin] = common.TopologyBlock + root.Vertices[common.TopologyBlock] = blockRoot return root } diff --git a/pkg/providers/gcp/instance_topology.go b/pkg/providers/gcp/instance_topology.go index d4d6b14..d18470c 100644 --- a/pkg/providers/gcp/instance_topology.go +++ b/pkg/providers/gcp/instance_topology.go @@ -148,6 +148,9 @@ func (cfg *InstanceTopology) toGraph() (*common.Vertex, error) { root := &common.Vertex{ Vertices: make(map[string]*common.Vertex), + Metadata: map[string]string{ + common.KeyPlugin: common.TopologyTree, + }, } for name, node := range forest { root.Vertices[name] = node diff --git a/pkg/providers/oci/instance_topology.go b/pkg/providers/oci/instance_topology.go index d3a6c2f..f4b7510 100644 --- a/pkg/providers/oci/instance_topology.go +++ b/pkg/providers/oci/instance_topology.go @@ -224,6 +224,9 @@ func toGraph(bareMetalHostSummaries []*core.ComputeBareMetalHostSummary, cis []c root := &common.Vertex{ Vertices: make(map[string]*common.Vertex), + Metadata: map[string]string{ + common.KeyPlugin: common.TopologyTree, + }, } for name, node := range forest { root.Vertices[name] = node diff --git a/pkg/server/grpc_client.go b/pkg/server/grpc_client.go index e6c439e..dcddbe8 100644 --- a/pkg/server/grpc_client.go +++ b/pkg/server/grpc_client.go @@ -69,7 +69,7 @@ func getTopologyFormat(params map[string]string) string { return format } } - return common.ValTopologyTree + return common.TopologyTree } func toGraph(response *pb.TopologyResponse, cis []common.ComputeInstances, format string) *common.Vertex { @@ -169,7 +169,7 @@ func toGraph(response *pb.TopologyResponse, cis []common.ComputeInstances, forma } metadata := map[string]string{common.KeyPlugin: format} - if format == common.ValTopologyBlock { + if format == common.TopologyBlock { blockRoot := &common.Vertex{ Vertices: make(map[string]*common.Vertex), } @@ -179,14 +179,13 @@ func toGraph(response *pb.TopologyResponse, cis []common.ComputeInstances, forma return &common.Vertex{ Vertices: map[string]*common.Vertex{ - common.ValTopologyBlock: blockRoot, - common.ValTopologyTree: treeRoot, + common.TopologyBlock: blockRoot, + common.TopologyTree: treeRoot, }, Metadata: metadata, } } else { treeRoot.Metadata = metadata - return treeRoot } } diff --git a/pkg/server/grpc_client_test.go b/pkg/server/grpc_client_test.go index ed4479c..664fe93 100644 --- a/pkg/server/grpc_client_test.go +++ b/pkg/server/grpc_client_test.go @@ -139,11 +139,11 @@ func TestToGraph(t *testing.T) { treeRoot := &common.Vertex{Vertices: map[string]*common.Vertex{"nvlink-nv1": nv1, "sw3": sw3, common.NoTopology: extra}} blockRoot := &common.Vertex{Vertices: map[string]*common.Vertex{"nvlink-nv1": nv1}} root := &common.Vertex{ - Vertices: map[string]*common.Vertex{common.ValTopologyBlock: blockRoot, common.ValTopologyTree: treeRoot}, - Metadata: map[string]string{common.KeyPlugin: common.ValTopologyBlock}, + Vertices: map[string]*common.Vertex{common.TopologyBlock: blockRoot, common.TopologyTree: treeRoot}, + Metadata: map[string]string{common.KeyPlugin: common.TopologyBlock}, } - require.Equal(t, root, toGraph(&pb.TopologyResponse{Instances: instances}, cis, common.ValTopologyBlock)) + require.Equal(t, root, toGraph(&pb.TopologyResponse{Instances: instances}, cis, common.TopologyBlock)) } func TestGetTopologyFormat(t *testing.T) { @@ -155,27 +155,27 @@ func TestGetTopologyFormat(t *testing.T) { { name: "Case 1: nil params", params: nil, - format: common.ValTopologyTree, + format: common.TopologyTree, }, { name: "Case 2: empty params", params: make(map[string]string), - format: common.ValTopologyTree, + format: common.TopologyTree, }, { name: "Case 3: missing key", params: map[string]string{"a": "b"}, - format: common.ValTopologyTree, + format: common.TopologyTree, }, { name: "Case 4: block topology", - params: map[string]string{common.KeyPlugin: common.ValTopologyBlock}, - format: common.ValTopologyBlock, + params: map[string]string{common.KeyPlugin: common.TopologyBlock}, + format: common.TopologyBlock, }, { name: "Case 5: tree topology", - params: map[string]string{common.KeyPlugin: common.ValTopologyTree}, - format: common.ValTopologyTree, + params: map[string]string{common.KeyPlugin: common.TopologyTree}, + format: common.TopologyTree, }, } diff --git a/pkg/translate/output.go b/pkg/translate/output.go index b8dd593..2890bac 100644 --- a/pkg/translate/output.go +++ b/pkg/translate/output.go @@ -28,10 +28,14 @@ import ( ) func ToGraph(wr io.Writer, root *common.Vertex) error { - if len(root.Metadata) != 0 && root.Metadata[common.KeyPlugin] == common.ValTopologyBlock { - return toBlockTopology(wr, root) + if len(root.Metadata) != 0 { + if root.Metadata[common.KeyPlugin] == common.TopologyBlock { + return toBlockTopology(wr, root) + } else if root.Metadata[common.KeyPlugin] == common.TopologyTree { + return toTreeTopology(wr, root) + } } - return toTreeTopology(wr, root) + return fmt.Errorf("topology metadata not set in root node") } func printBlock(wr io.Writer, block *common.Vertex, domainVisited map[string]int) error { @@ -109,8 +113,8 @@ func getBlockSize(domainVisited map[string]int, adminBlockSize string) string { func toBlockTopology(wr io.Writer, root *common.Vertex) error { // traverse tree topology and when a node is reached, check within blockRoot for domain and print that domain. // keep a map of which domain has been printed - treeRoot := root.Vertices[common.ValTopologyTree] - blockRoot := root.Vertices[common.ValTopologyBlock] + treeRoot := root.Vertices[common.TopologyTree] + blockRoot := root.Vertices[common.TopologyBlock] visited := make(map[string]bool) queue := []*common.Vertex{treeRoot} domainVisited := make(map[string]int) @@ -368,6 +372,9 @@ func GetTreeTestSet(testForLongLabelName bool) (*common.Vertex, map[string]strin } root := &common.Vertex{ Vertices: map[string]*common.Vertex{"S1": sw1}, + Metadata: map[string]string{ + common.KeyPlugin: common.TopologyTree, + }, } return root, instance2node @@ -455,10 +462,10 @@ func GetBlockWithMultiIBTestSet() (*common.Vertex, map[string]string) { } root := &common.Vertex{ - Vertices: map[string]*common.Vertex{common.ValTopologyBlock: blockRoot, common.ValTopologyTree: treeRoot}, + Vertices: map[string]*common.Vertex{common.TopologyBlock: blockRoot, common.TopologyTree: treeRoot}, Metadata: map[string]string{ common.KeyEngine: common.EngineSLURM, - common.KeyPlugin: common.ValTopologyBlock, + common.KeyPlugin: common.TopologyBlock, common.KeyBlockSizes: "3", }, } @@ -509,10 +516,10 @@ func GetBlockWithIBTestSet() (*common.Vertex, map[string]string) { } root := &common.Vertex{ - Vertices: map[string]*common.Vertex{common.ValTopologyBlock: blockRoot, common.ValTopologyTree: treeRoot}, + Vertices: map[string]*common.Vertex{common.TopologyBlock: blockRoot, common.TopologyTree: treeRoot}, Metadata: map[string]string{ common.KeyEngine: common.EngineSLURM, - common.KeyPlugin: common.ValTopologyBlock, + common.KeyPlugin: common.TopologyBlock, common.KeyBlockSizes: "3", }, } @@ -547,10 +554,10 @@ func GetBlockTestSet() (*common.Vertex, map[string]string) { } root := &common.Vertex{ - Vertices: map[string]*common.Vertex{common.ValTopologyBlock: blockRoot}, + Vertices: map[string]*common.Vertex{common.TopologyBlock: blockRoot}, Metadata: map[string]string{ common.KeyEngine: common.EngineSLURM, - common.KeyPlugin: common.ValTopologyBlock, + common.KeyPlugin: common.TopologyBlock, common.KeyBlockSizes: "3", }, } diff --git a/pkg/translate/output_test.go b/pkg/translate/output_test.go index 0f96019..8c25aab 100644 --- a/pkg/translate/output_test.go +++ b/pkg/translate/output_test.go @@ -56,6 +56,7 @@ SwitchName=switch.1.2 Nodes=node-2 func TestToTreeTopology(t *testing.T) { v, _ := GetTreeTestSet(false) + require.Equal(t, v.Metadata[common.KeyPlugin], common.TopologyTree) buf := &bytes.Buffer{} err := ToGraph(buf, v) require.NoError(t, err) @@ -64,6 +65,7 @@ func TestToTreeTopology(t *testing.T) { func TestToBlockTopology(t *testing.T) { v, _ := GetBlockTestSet() + require.Equal(t, v.Metadata[common.KeyPlugin], common.TopologyBlock) buf := &bytes.Buffer{} err := ToGraph(buf, v) require.NoError(t, err) @@ -72,6 +74,7 @@ func TestToBlockTopology(t *testing.T) { func TestToBlockMultiIBTopology(t *testing.T) { v, _ := GetBlockWithMultiIBTestSet() + require.Equal(t, v.Metadata[common.KeyPlugin], common.TopologyBlock) buf := &bytes.Buffer{} err := ToGraph(buf, v) require.NoError(t, err) @@ -85,6 +88,7 @@ func TestToBlockMultiIBTopology(t *testing.T) { func TestToBlockIBTopology(t *testing.T) { v, _ := GetBlockWithIBTestSet() + require.Equal(t, v.Metadata[common.KeyPlugin], common.TopologyBlock) buf := &bytes.Buffer{} err := ToGraph(buf, v) require.NoError(t, err) @@ -138,8 +142,12 @@ func TestToSlurmNameShortener(t *testing.T) { }, }, }, + Metadata: map[string]string{ + common.KeyPlugin: common.TopologyTree, + }, } + require.Equal(t, v.Metadata[common.KeyPlugin], common.TopologyTree) buf := &bytes.Buffer{} err := ToGraph(buf, v) require.NoError(t, err) diff --git a/tests/models/medium-block.yaml b/tests/models/medium-block.yaml index 8f15efe..1cf37ac 100644 --- a/tests/models/medium-block.yaml +++ b/tests/models/medium-block.yaml @@ -1,3 +1,4 @@ +topology: "topology/block" switches: - name: spine1 switches: [ibleaf1,ibleaf2] diff --git a/tests/models/medium-h100.yaml b/tests/models/medium-h100.yaml index 769c52a..61d3d7d 100644 --- a/tests/models/medium-h100.yaml +++ b/tests/models/medium-h100.yaml @@ -11,6 +11,7 @@ # ------- ------- ------- ------- ------- # cb10 cb11 cb12 cb13 cb14 # +topology: "topology/tree" switches: - name: sw3 switches: [sw21,sw22] diff --git a/tests/models/small-h100.yaml b/tests/models/small-h100.yaml index ffb09e2..b05fe2d 100644 --- a/tests/models/small-h100.yaml +++ b/tests/models/small-h100.yaml @@ -10,6 +10,7 @@ # ------ ------ # CB2 CB3 # +topology: "topology/tree" switches: - name: S1 switches: [S2,S3] From aaaff6be118f697d75f69a55743f207a91605684 Mon Sep 17 00:00:00 2001 From: Henry Haase Date: Fri, 8 Nov 2024 14:31:19 -0600 Subject: [PATCH 2/5] Removed topology field from model file specification Signed-off-by: Henry Haase --- pkg/models/model.go | 11 +++++------ pkg/models/model_test.go | 2 -- tests/models/medium-block.yaml | 1 - tests/models/medium-h100.yaml | 1 - tests/models/small-h100.yaml | 1 - 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/pkg/models/model.go b/pkg/models/model.go index e887876..3442352 100644 --- a/pkg/models/model.go +++ b/pkg/models/model.go @@ -26,7 +26,6 @@ import ( ) type Model struct { - Topology string `yaml:"topology"` Switches []Switch `yaml:"switches"` CapacityBlocks []CapacityBlock `yaml:"capacity_blocks"` @@ -65,10 +64,6 @@ func NewModelFromFile(fname string) (*Model, error) { return nil, fmt.Errorf("failed to parse %s: %v", fname, err) } - if model.Topology != topology.TopologyTree && model.Topology != topology.TopologyBlock { - return nil, fmt.Errorf("unsupported topology type set in model: %s", model.Topology) - } - if err = model.setNodeMap(); err != nil { return nil, err } @@ -151,6 +146,7 @@ func (model *Model) ToGraph() (*topology.Vertex, map[string]string) { swVertexMap := make(map[string]*topology.Vertex) swRootMap := make(map[string]bool) blockVertexMap := make(map[string]*topology.Vertex) + var block_topology bool = false // Create all the vertices for each node for k, v := range model.Nodes { @@ -170,6 +166,9 @@ func (model *Model) ToGraph() (*topology.Vertex, map[string]string) { for _, node := range cb.Nodes { blockVertexMap[cb.Name].Vertices[node] = nodeVertexMap[node] } + if len(cb.NVLink) != 0 { + block_topology = true + } } // Connect all the switches to their sub-switches and sub-nodes @@ -201,7 +200,7 @@ func (model *Model) ToGraph() (*topology.Vertex, map[string]string) { for k, v := range blockVertexMap { blockRoot.Vertices[k] = v } - if model.Topology == topology.TopologyBlock { + if block_topology { root := &topology.Vertex{ Vertices: map[string]*topology.Vertex{topology.TopologyBlock: blockRoot, topology.TopologyTree: treeRoot}, Metadata: map[string]string{topology.KeyPlugin: topology.TopologyTree}, diff --git a/pkg/models/model_test.go b/pkg/models/model_test.go index caecfe7..3d2a2ce 100644 --- a/pkg/models/model_test.go +++ b/pkg/models/model_test.go @@ -19,7 +19,6 @@ package models import ( "testing" - "github.com/NVIDIA/topograph/pkg/topology" "github.com/stretchr/testify/require" ) @@ -28,7 +27,6 @@ func TestNewModelFromFile(t *testing.T) { require.NoError(t, err) expected := &Model{ - Topology: topology.TopologyTree, Switches: []Switch{ { Name: "sw3", diff --git a/tests/models/medium-block.yaml b/tests/models/medium-block.yaml index 1cf37ac..8f15efe 100644 --- a/tests/models/medium-block.yaml +++ b/tests/models/medium-block.yaml @@ -1,4 +1,3 @@ -topology: "topology/block" switches: - name: spine1 switches: [ibleaf1,ibleaf2] diff --git a/tests/models/medium-h100.yaml b/tests/models/medium-h100.yaml index 61d3d7d..769c52a 100644 --- a/tests/models/medium-h100.yaml +++ b/tests/models/medium-h100.yaml @@ -11,7 +11,6 @@ # ------- ------- ------- ------- ------- # cb10 cb11 cb12 cb13 cb14 # -topology: "topology/tree" switches: - name: sw3 switches: [sw21,sw22] diff --git a/tests/models/small-h100.yaml b/tests/models/small-h100.yaml index b05fe2d..ffb09e2 100644 --- a/tests/models/small-h100.yaml +++ b/tests/models/small-h100.yaml @@ -10,7 +10,6 @@ # ------ ------ # CB2 CB3 # -topology: "topology/tree" switches: - name: S1 switches: [S2,S3] From 63508cbd3b1bd377621a531f898317e079e2af7d Mon Sep 17 00:00:00 2001 From: Henry Haase Date: Fri, 8 Nov 2024 15:05:05 -0600 Subject: [PATCH 3/5] Small fix Signed-off-by: Henry Haase --- pkg/ib/ib.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/ib/ib.go b/pkg/ib/ib.go index da0bb71..dc038e7 100644 --- a/pkg/ib/ib.go +++ b/pkg/ib/ib.go @@ -66,12 +66,12 @@ func GenerateTopologyConfig(data []byte) (*topology.Vertex, error) { root.simplify(root.getHeight()) rootNode, err := root.toGraph() if err != nil { - rootNode.Metadata = map[string]string{ - topology.KeyPlugin: topology.TopologyTree, - } - return rootNode, nil + return nil, err + } + rootNode.Metadata = map[string]string{ + topology.KeyPlugin: topology.TopologyTree, } - return nil, err + return rootNode, nil } func (sw *Switch) toGraph() (*topology.Vertex, error) { From d1ed19f67b77a1febe15d1d13c88cdc5457f2233 Mon Sep 17 00:00:00 2001 From: Henry Haase Date: Tue, 12 Nov 2024 13:49:56 -0600 Subject: [PATCH 4/5] Small doc change Signed-off-by: Henry Haase --- docs/slurm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/slurm.md b/docs/slurm.md index cc365b1..db671bd 100644 --- a/docs/slurm.md +++ b/docs/slurm.md @@ -47,7 +47,7 @@ Then run the topograph service as normal. You must then start the toposim service as such, setting the path to the test model that you want to use in simulation: ```bash -/usr/local/bin/topograph -m /usr/local/bin/tests/models/.yaml +/usr/local/bin/toposim -m /usr/local/bin/tests/models/.yaml ``` You can then verify the topology results via simulation by querying topograph, and specifying the test model path as a parameter to the provider. From 035d92ee8785334cb9cc5babff93ea98c8bde8dc Mon Sep 17 00:00:00 2001 From: Henry Haase Date: Thu, 14 Nov 2024 16:47:17 -0600 Subject: [PATCH 5/5] Fixed small issue in model Signed-off-by: Henry Haase --- pkg/models/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/models/model.go b/pkg/models/model.go index 3442352..4aac239 100644 --- a/pkg/models/model.go +++ b/pkg/models/model.go @@ -203,7 +203,7 @@ func (model *Model) ToGraph() (*topology.Vertex, map[string]string) { if block_topology { root := &topology.Vertex{ Vertices: map[string]*topology.Vertex{topology.TopologyBlock: blockRoot, topology.TopologyTree: treeRoot}, - Metadata: map[string]string{topology.KeyPlugin: topology.TopologyTree}, + Metadata: map[string]string{topology.KeyPlugin: topology.TopologyBlock}, } return root, instance2node }