From bb9b146bbd33d1262e5f930bbd44538ff4124b96 Mon Sep 17 00:00:00 2001 From: Henry Haase Date: Mon, 18 Nov 2024 01:16:19 -0600 Subject: [PATCH 1/6] Added aws-sim provider Signed-off-by: Henry Haase --- README.md | 1 - pkg/providers/aws/provider_sim.go | 90 +++++++++++++++++++++++++++++++ pkg/registry/registry.go | 1 + 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 pkg/providers/aws/provider_sim.go diff --git a/README.md b/README.md index c7b5e86..ff8a3e1 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,6 @@ Topograph offers three endpoints for interacting with the service. Below are the "secret_access_key": "secret" }, "params": { - "use_simulation": "false", "model_path": "" } }, diff --git a/pkg/providers/aws/provider_sim.go b/pkg/providers/aws/provider_sim.go new file mode 100644 index 0000000..ff8c20b --- /dev/null +++ b/pkg/providers/aws/provider_sim.go @@ -0,0 +1,90 @@ +/* + * 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. + */ + +package aws + +import ( + "context" + "fmt" + + // "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + // "github.com/aws/aws-sdk-go-v2/credentials" + // "github.com/aws/aws-sdk-go-v2/credentials/ec2rolecreds" + "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" + "github.com/aws/aws-sdk-go-v2/service/ec2" + + // v1 "k8s.io/api/core/v1" + + // "github.com/NVIDIA/topograph/internal/exec" + int_config "github.com/NVIDIA/topograph/internal/config" + "github.com/NVIDIA/topograph/pkg/models" + "github.com/NVIDIA/topograph/pkg/providers" + // "github.com/NVIDIA/topograph/pkg/topology" +) + +const NAME_SIM = "aws-sim" + +type SimParams struct { + ModelPath string `mapstructure:"model_path"` +} + +type SimClient struct { + model *models.Model +} + +func (client SimClient) DescribeInstanceTopology(ctx context.Context, params *ec2.DescribeInstanceTopologyInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstanceTopologyOutput, error) { + return nil, fmt.Errorf("aws simulation not yet implemented") +} + +func getSimClient(m *models.Model) EC2Client { + return SimClient{model: m} +} + +func NamedLoaderSim() (string, providers.Loader) { + return NAME_SIM, LoaderSim +} + +func LoaderSim(ctx context.Context, cfg providers.Config) (providers.Provider, error) { + defaultCfg, err := config.LoadDefaultConfig(ctx) + if err != nil { + return nil, err + } + + imdsClient := imds.NewFromConfig(defaultCfg) + + var p SimParams + if err := int_config.Decode(cfg.Params, &p); err != nil { + return nil, fmt.Errorf("error decoding params: %w", err) + } + if len(p.ModelPath) == 0 { + return nil, fmt.Errorf("no model path for AWS simulation") + } + + clientFactory := func(region string) (*Client, error) { + csp_model, err := models.NewModelFromFile(p.ModelPath) + if err != nil { + return nil, fmt.Errorf("unable to load model file for AWS simulation, %v", err) + } + simClient := getSimClient(csp_model) + + return &Client{ + EC2: simClient, + }, nil + } + + return New(clientFactory, imdsClient), nil +} diff --git a/pkg/registry/registry.go b/pkg/registry/registry.go index f5ae1c9..0e342be 100644 --- a/pkg/registry/registry.go +++ b/pkg/registry/registry.go @@ -33,6 +33,7 @@ import ( var Providers = providers.NewRegistry( aws.NamedLoader, + aws.NamedLoaderSim, baremetal.NamedLoader, cw.NamedLoader, gcp.NamedLoader, From f81b590ea26c656f403246fb92640701bffa7005 Mon Sep 17 00:00:00 2001 From: Henry Haase Date: Tue, 19 Nov 2024 04:36:55 -0600 Subject: [PATCH 2/6] Updated model format to suport physical layers found within a CSP Signed-off-by: Henry Haase --- go.mod | 8 ++ pkg/models/model.go | 135 ++++++++++++++++-- pkg/providers/aws/provider_sim.go | 16 +-- tests/models/medium-block.yaml | 3 +- .../{medium-h100.yaml => medium-tree.yaml} | 1 + .../{small-h100.yaml => small-tree.yaml} | 28 ++++ tests/payloads/test-aws-sim.json | 31 ++++ tests/payloads/test-toposim-block.json | 19 +++ tests/payloads/test-toposim-tree.json | 14 ++ 9 files changed, 232 insertions(+), 23 deletions(-) rename tests/models/{medium-h100.yaml => medium-tree.yaml} (98%) rename tests/models/{small-h100.yaml => small-tree.yaml} (50%) create mode 100644 tests/payloads/test-aws-sim.json create mode 100644 tests/payloads/test-toposim-block.json create mode 100644 tests/payloads/test-toposim-tree.json diff --git a/go.mod b/go.mod index 068298c..eb7ee3b 100644 --- a/go.mod +++ b/go.mod @@ -105,3 +105,11 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) + +replace ( + github.com/aws/aws-sdk-go-v2 v1.32.4 => github.com/pkedy/aws-sdk-go-v2 v0.0.0-20241115203348-0198b6c98cd9 + github.com/aws/aws-sdk-go-v2/config v1.28.4 => github.com/pkedy/aws-sdk-go-v2/config v0.0.0-20241115203348-0198b6c98cd9 + // github.com/aws/aws-sdk-go-v2/credentials v1.17.45 => github.com/pkedy/aws-sdk-go-v2/credentials v0.0.0-20241115203348-0198b6c98cd9 + // github.com/aws/aws-sdk-go-v2/service/autoscaling v1.48.0 => github.com/pkedy/aws-sdk-go-v2/service/autoscaling v0.0.0-20241115203348-0198b6c98cd9 + github.com/aws/aws-sdk-go-v2/service/ec2 v1.188.0 => github.com/pkedy/aws-sdk-go-v2/service/ec2 v0.0.0-20241115203348-0198b6c98cd9 +) diff --git a/pkg/models/model.go b/pkg/models/model.go index 4aac239..1145888 100644 --- a/pkg/models/model.go +++ b/pkg/models/model.go @@ -26,8 +26,9 @@ import ( ) type Model struct { - Switches []Switch `yaml:"switches"` - CapacityBlocks []CapacityBlock `yaml:"capacity_blocks"` + Switches []Switch `yaml:"switches"` + CapacityBlocks []CapacityBlock `yaml:"capacity_blocks"` + PhysicalLayers []PhysicalLayers `yaml:"physical_layers"` // defived Nodes map[string]*Node @@ -46,11 +47,24 @@ type CapacityBlock struct { Nodes []string `yaml:"nodes"` } +type PhysicalLayers struct { + Name string `yaml:"name"` + Type string `yaml:"type"` + SubLayers []string `yaml:"sub_layers"` + CapacityBlocks []string `yaml:"capacity_blocks"` +} + +const ( + PhysicalLayerRegion = "region" + PhysicalLayerAZ = "availability_zone" +) + type Node struct { - Name string - Type string - NVLink string - NetLayers []string + Name string + Type string + NVLink string + NetLayers []string + CapacityBlock string } func NewModelFromFile(fname string) (*Model, error) { @@ -68,6 +82,10 @@ func NewModelFromFile(fname string) (*Model, error) { return nil, err } + if err = validateLayers(model.PhysicalLayers); err != nil { + return nil, err + } + return model, err } @@ -110,10 +128,11 @@ func (m *Model) setNodeMap() error { return fmt.Errorf("duplicated node name %q", name) } m.Nodes[name] = &Node{ - Name: name, - Type: cb.Type, - NVLink: cb.NVLink, - NetLayers: netLayers, + Name: name, + Type: cb.Type, + NVLink: cb.NVLink, + NetLayers: netLayers, + CapacityBlock: cb.Name, } } } @@ -140,6 +159,63 @@ func getNetworkLayers(name string, swmap map[string]string) ([]string, error) { } } +// Check to make sure each layer is unique and has only a single parent, if any, and enumerates them into a map of layer name to parent index within the layers list +// If the layer has no entry within the map, it means that the layer has no parent +func getLayerParentMap(layers []PhysicalLayers) (map[string]int, error) { + parentMap := make(map[string]int) + for i, layer := range layers { + layerName := layer.Name + var parentCount int = 0 + for j, checkLayer := range layers { + if i == j { + continue + } + if layerName == checkLayer.Name { + return nil, fmt.Errorf("duplicated physical layer name %q", layerName) + } + for _, subLayerName := range checkLayer.SubLayers { + if layerName == subLayerName { + parentMap[layerName] = j + parentCount++ + break + } + } + } + if parentCount > 1 { + return nil, fmt.Errorf("physical layer with name %q has more than one parent (%d parents)", layerName, parentCount) + } + } + return parentMap, nil +} + +func validateLayers(layers []PhysicalLayers) error { + // Validates the parent structure of the layers and gets the map of nodes to parents + parentMap, err := getLayerParentMap(layers) + if err != nil { + return err + } + + // Check to make sure there are no loops among the physical layers + for _, layer := range layers { + layerName := layer.Name + currLayerIdx, ok := parentMap[layerName] + if ok { + currLayerName := layers[currLayerIdx].Name + for { + currLayerIdx, ok = parentMap[currLayerName] + if !ok { + break + } + currLayerName = layers[currLayerIdx].Name + if currLayerName == layerName { + return fmt.Errorf("circular layer dependencies involving layer with name %q", layerName) + } + } + } + } + return nil +} + func (model *Model) ToGraph() (*topology.Vertex, map[string]string) { instance2node := make(map[string]string) nodeVertexMap := make(map[string]*topology.Vertex) @@ -210,3 +286,42 @@ func (model *Model) ToGraph() (*topology.Vertex, map[string]string) { treeRoot.Metadata = map[string]string{topology.KeyPlugin: topology.TopologyTree} return treeRoot, instance2node } + +// Get a map that maps from the name of each node in the model to the cloestest physical layer that shares the given type. +// If no entry exists for the node in the returned map, then there is no layer the node exists in with the given type +func (model *Model) NodeToLayerMap(layerType string) (map[string]string, error) { + // Maps each capacity block to a parent physical layer index + cbToLayer := make(map[string]int) + for idx, layer := range model.PhysicalLayers { + for _, cbName := range layer.CapacityBlocks { + cbToLayer[cbName] = idx + } + } + + // Goes through each node, gets the capacity block, and walks up the parent tree to find the cloest layer of the given type + nodeToLayer := make(map[string]string) + layerParentMap, err := getLayerParentMap(model.PhysicalLayers) + if err != nil { + return nil, err + } + for _, node := range model.Nodes { + cb := node.CapacityBlock + layerIdx, ok := cbToLayer[cb] + if !ok { + return nil, fmt.Errorf("capacity block %q not found in any physical layer", cb) + } + for { + layer := model.PhysicalLayers[layerIdx] + if layer.Type == layerType { + nodeToLayer[node.Name] = layer.Name + break + } + layerIdx, ok = layerParentMap[layer.Name] + if !ok { + break + } + } + } + + return nodeToLayer, nil +} diff --git a/pkg/providers/aws/provider_sim.go b/pkg/providers/aws/provider_sim.go index ff8c20b..ced66da 100644 --- a/pkg/providers/aws/provider_sim.go +++ b/pkg/providers/aws/provider_sim.go @@ -19,21 +19,15 @@ package aws import ( "context" "fmt" + "strconv" - // "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" - // "github.com/aws/aws-sdk-go-v2/credentials" - // "github.com/aws/aws-sdk-go-v2/credentials/ec2rolecreds" "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" "github.com/aws/aws-sdk-go-v2/service/ec2" - // v1 "k8s.io/api/core/v1" - - // "github.com/NVIDIA/topograph/internal/exec" int_config "github.com/NVIDIA/topograph/internal/config" "github.com/NVIDIA/topograph/pkg/models" "github.com/NVIDIA/topograph/pkg/providers" - // "github.com/NVIDIA/topograph/pkg/topology" ) const NAME_SIM = "aws-sim" @@ -47,13 +41,11 @@ type SimClient struct { } func (client SimClient) DescribeInstanceTopology(ctx context.Context, params *ec2.DescribeInstanceTopologyInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstanceTopologyOutput, error) { + fmt.Println("HERE") + fmt.Println("Count: " + strconv.Itoa(len(client.model.PhysicalLayers))) return nil, fmt.Errorf("aws simulation not yet implemented") } -func getSimClient(m *models.Model) EC2Client { - return SimClient{model: m} -} - func NamedLoaderSim() (string, providers.Loader) { return NAME_SIM, LoaderSim } @@ -79,7 +71,7 @@ func LoaderSim(ctx context.Context, cfg providers.Config) (providers.Provider, e if err != nil { return nil, fmt.Errorf("unable to load model file for AWS simulation, %v", err) } - simClient := getSimClient(csp_model) + simClient := SimClient{model: csp_model} return &Client{ EC2: simClient, diff --git a/tests/models/medium-block.yaml b/tests/models/medium-block.yaml index 8f15efe..5c1793a 100644 --- a/tests/models/medium-block.yaml +++ b/tests/models/medium-block.yaml @@ -21,4 +21,5 @@ capacity_blocks: - name: cb4 nvlink: nv4 type: H100 - nodes: [n4-1,n4-2,n4-3,n4-4] \ No newline at end of file + nodes: [n4-1,n4-2,n4-3,n4-4] +physical_layers: [] \ No newline at end of file diff --git a/tests/models/medium-h100.yaml b/tests/models/medium-tree.yaml similarity index 98% rename from tests/models/medium-h100.yaml rename to tests/models/medium-tree.yaml index 769c52a..b72000b 100644 --- a/tests/models/medium-h100.yaml +++ b/tests/models/medium-tree.yaml @@ -44,3 +44,4 @@ capacity_blocks: - name: cb14 type: H100 nodes: [n14-1,n14-2] +physical_layers: [] diff --git a/tests/models/small-h100.yaml b/tests/models/small-tree.yaml similarity index 50% rename from tests/models/small-h100.yaml rename to tests/models/small-tree.yaml index ffb09e2..77e79fe 100644 --- a/tests/models/small-h100.yaml +++ b/tests/models/small-tree.yaml @@ -1,3 +1,5 @@ +# Switch Model +# # S1 # / \ # / \ @@ -10,6 +12,16 @@ # ------ ------ # CB2 CB3 # +# Physical Layers: +# +# R1 +# / \ +# AZ1 AZ2 +# | | +# D1 D2 +# | | +# CB2 CB3 +# switches: - name: S1 switches: [S2,S3] @@ -24,3 +36,19 @@ capacity_blocks: - name: CB3 type: H100 nodes: [I34,I35,I36] +physical_layers: +- name: R1 + type: region + sub_layers: [AZ1, AZ2] +- name: AZ1 + type: availability_zone + sub_layers: [D1] +- name: AZ2 + type: availability_zone + sub_layers: [D2] +- name: D1 + type: data_center + capacity_blocks: [CB2] +- name: D2 + type: data_center + capacity_blocks: [CB3] diff --git a/tests/payloads/test-aws-sim.json b/tests/payloads/test-aws-sim.json new file mode 100644 index 0000000..ecc9e45 --- /dev/null +++ b/tests/payloads/test-aws-sim.json @@ -0,0 +1,31 @@ +{ + "provider": + { + "name": "aws-sim", + "params": + { + "model_path": "tests/models/small-tree.yaml" + } + }, + "engine": + { + "name": "test", + "params": + { + "plugin": "topology/block", + "block_sizes": "30,120" + } + }, + "nodes": + [ + { + "region": "R1", + "instances": + { + "instance1": "I21", + "instance2": "I25", + "instance3": "I36" + } + } + ] +} \ No newline at end of file diff --git a/tests/payloads/test-toposim-block.json b/tests/payloads/test-toposim-block.json new file mode 100644 index 0000000..d1f5f18 --- /dev/null +++ b/tests/payloads/test-toposim-block.json @@ -0,0 +1,19 @@ +{ + "provider": + { + "name": "test", + "params": + { + "model_path": "tests/models/medium-block.yaml" + } + }, + "engine": + { + "name": "test", + "params": + { + "plugin": "topology/block", + "block_sizes": "2,4" + } + } +} \ No newline at end of file diff --git a/tests/payloads/test-toposim-tree.json b/tests/payloads/test-toposim-tree.json new file mode 100644 index 0000000..ac680ac --- /dev/null +++ b/tests/payloads/test-toposim-tree.json @@ -0,0 +1,14 @@ +{ + "provider": + { + "name": "test", + "params": + { + "model_path": "tests/models/medium-tree.yaml" + } + }, + "engine": + { + "name": "test" + } +} \ No newline at end of file From 513779aa3289ecbc5fd27ca74e616293af3035e9 Mon Sep 17 00:00:00 2001 From: Henry Haase Date: Tue, 19 Nov 2024 06:48:07 -0600 Subject: [PATCH 3/6] Implemented describe instance topology endpoint in AWS simulation Signed-off-by: Henry Haase --- pkg/models/model.go | 1 + pkg/providers/aws/provider_sim.go | 100 ++++++++++++++++++++++++++++-- tests/models/medium-tree.yaml | 30 ++++++++- tests/models/small-tree.yaml | 27 +------- tests/payloads/test-aws-sim.json | 20 +++--- 5 files changed, 136 insertions(+), 42 deletions(-) diff --git a/pkg/models/model.go b/pkg/models/model.go index 1145888..c28448d 100644 --- a/pkg/models/model.go +++ b/pkg/models/model.go @@ -57,6 +57,7 @@ type PhysicalLayers struct { const ( PhysicalLayerRegion = "region" PhysicalLayerAZ = "availability_zone" + PhysicalLayerPG = "placement_group" ) type Node struct { diff --git a/pkg/providers/aws/provider_sim.go b/pkg/providers/aws/provider_sim.go index ced66da..e840152 100644 --- a/pkg/providers/aws/provider_sim.go +++ b/pkg/providers/aws/provider_sim.go @@ -24,6 +24,7 @@ import ( "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/aws/aws-sdk-go-v2/service/ec2/types" int_config "github.com/NVIDIA/topograph/internal/config" "github.com/NVIDIA/topograph/pkg/models" @@ -31,19 +32,108 @@ import ( ) const NAME_SIM = "aws-sim" +const DEFAULT_MAX_RESULTS = 20 type SimParams struct { ModelPath string `mapstructure:"model_path"` } type SimClient struct { - model *models.Model + Model *models.Model + Outputs map[string](*[]types.InstanceTopology) + NextTokens map[string]string } func (client SimClient) DescribeInstanceTopology(ctx context.Context, params *ec2.DescribeInstanceTopologyInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstanceTopologyOutput, error) { - fmt.Println("HERE") - fmt.Println("Count: " + strconv.Itoa(len(client.model.PhysicalLayers))) - return nil, fmt.Errorf("aws simulation not yet implemented") + + // If we need to calculate new results (a previous token was not given) + givenToken := params.NextToken + if givenToken == nil { + // Gets availability zone and placement group for each instance + instanceAzs, err := client.Model.NodeToLayerMap(models.PhysicalLayerAZ) + if err != nil { + return nil, err + } + instancePgs, err := client.Model.NodeToLayerMap(models.PhysicalLayerPG) + if err != nil { + return nil, err + } + + // Refreshes the clients internal storage for outputs + client.Outputs = make(map[string](*[]types.InstanceTopology)) + client.NextTokens = make(map[string]string) + + // Sets the maximum number of results to return per output + var maxResults int = DEFAULT_MAX_RESULTS + if params.MaxResults != nil { + maxResults = int(*params.MaxResults) + } + + // Creates the list of instances whose topology is requested + var firstToken string + var instanceIdx int = 0 + for instanceIdx < len(params.InstanceIds) { + + // Only collect a list up to params.MaxResults + var instances []types.InstanceTopology + var i int + for i = 0; i < maxResults && i+instanceIdx < len(params.InstanceIds); i++ { + + // Gets the instance ID + instanceId := params.InstanceIds[instanceIdx+i] + + // Gets the availability zone and placement group of the instance + node := client.Model.Nodes[instanceId] + az, ok := instanceAzs[instanceId] + if !ok { + return nil, fmt.Errorf("availability zone not found for instance %q in aws simulation", instanceId) + } + pg, ok := instancePgs[instanceId] + if !ok { + return nil, fmt.Errorf("placement group not found for instance %q in aws simulation", instanceId) + } + + // Sets up the structure for the instance + var instTopo types.InstanceTopology + instTopo.InstanceId = &instanceId + instTopo.InstanceType = &node.Type + instTopo.AvailabilityZone = &az + instTopo.ZoneId = &az + instTopo.GroupName = &pg + // instTopo.CapacityBlockID = &node.CapacityBlock + var netLayers []string + for j := len(node.NetLayers) - 1; j >= 0; j-- { + netLayers = append(netLayers, node.NetLayers[j]) + } + instTopo.NetworkNodes = netLayers + instances = append(instances, instTopo) + } + + token := strconv.Itoa(instanceIdx) + if instanceIdx == 0 { + firstToken = token + } + client.Outputs[token] = &instances + instanceIdx += i + if instanceIdx < len(params.InstanceIds) { + var nextToken string = strconv.Itoa(instanceIdx) + client.NextTokens[token] = nextToken + } + } + + // Sets the given token to the first token generated, then proceed normally + givenToken = &firstToken + } + + // Otherwise return the requested, already calculated output + output := ec2.DescribeInstanceTopologyOutput{ + Instances: *client.Outputs[*givenToken], + } + nextToken, ok := client.NextTokens[*givenToken] + if ok { + output.NextToken = &nextToken + } + return &output, nil } func NamedLoaderSim() (string, providers.Loader) { @@ -71,7 +161,7 @@ func LoaderSim(ctx context.Context, cfg providers.Config) (providers.Provider, e if err != nil { return nil, fmt.Errorf("unable to load model file for AWS simulation, %v", err) } - simClient := SimClient{model: csp_model} + simClient := SimClient{Model: csp_model} return &Client{ EC2: simClient, diff --git a/tests/models/medium-tree.yaml b/tests/models/medium-tree.yaml index b72000b..689fbb3 100644 --- a/tests/models/medium-tree.yaml +++ b/tests/models/medium-tree.yaml @@ -11,6 +11,19 @@ # ------- ------- ------- ------- ------- # cb10 cb11 cb12 cb13 cb14 # +# Physical Layers: +# +# R1 +# / \ +# / \ +# AZ1 AZ2 +# | | +# G1 G2 +# | | +# cb10, cb13 +# cb11, cb14 +# cb12 +# switches: - name: sw3 switches: [sw21,sw22] @@ -44,4 +57,19 @@ capacity_blocks: - name: cb14 type: H100 nodes: [n14-1,n14-2] -physical_layers: [] +physical_layers: +- name: R1 + type: region + sub_layers: [AZ1, AZ2] +- name: AZ1 + type: availability_zone + sub_layers: [G1] +- name: AZ2 + type: availability_zone + sub_layers: [G2] +- name: G1 + type: placement_group + capacity_blocks: [cb10, cb11, cb12] +- name: G2 + type: placement_group + capacity_blocks: [cb13, cb14] diff --git a/tests/models/small-tree.yaml b/tests/models/small-tree.yaml index 77e79fe..4fffa6d 100644 --- a/tests/models/small-tree.yaml +++ b/tests/models/small-tree.yaml @@ -12,16 +12,6 @@ # ------ ------ # CB2 CB3 # -# Physical Layers: -# -# R1 -# / \ -# AZ1 AZ2 -# | | -# D1 D2 -# | | -# CB2 CB3 -# switches: - name: S1 switches: [S2,S3] @@ -36,19 +26,4 @@ capacity_blocks: - name: CB3 type: H100 nodes: [I34,I35,I36] -physical_layers: -- name: R1 - type: region - sub_layers: [AZ1, AZ2] -- name: AZ1 - type: availability_zone - sub_layers: [D1] -- name: AZ2 - type: availability_zone - sub_layers: [D2] -- name: D1 - type: data_center - capacity_blocks: [CB2] -- name: D2 - type: data_center - capacity_blocks: [CB3] +physical_layers: [] diff --git a/tests/payloads/test-aws-sim.json b/tests/payloads/test-aws-sim.json index ecc9e45..6fa3a34 100644 --- a/tests/payloads/test-aws-sim.json +++ b/tests/payloads/test-aws-sim.json @@ -4,17 +4,12 @@ "name": "aws-sim", "params": { - "model_path": "tests/models/small-tree.yaml" + "model_path": "tests/models/medium-tree.yaml" } }, "engine": { - "name": "test", - "params": - { - "plugin": "topology/block", - "block_sizes": "30,120" - } + "name": "test" }, "nodes": [ @@ -22,9 +17,14 @@ "region": "R1", "instances": { - "instance1": "I21", - "instance2": "I25", - "instance3": "I36" + "n11-1": "n11-1", + "n11-2": "n11-2", + "n12-1": "n12-1", + "n12-2": "n12-2", + "n13-1": "n13-1", + "n13-2": "n13-2", + "n14-1": "n14-1", + "n14-2": "n14-2" } } ] From bfcba457029260627a0f99663869571b4d768d97 Mon Sep 17 00:00:00 2001 From: Henry Haase Date: Tue, 19 Nov 2024 06:57:04 -0600 Subject: [PATCH 4/6] Updated model tests to match change in model structure Signed-off-by: Henry Haase --- go.mod | 14 +++--- pkg/models/model_test.go | 104 ++++++++++++++++++++++++++------------- 2 files changed, 77 insertions(+), 41 deletions(-) diff --git a/go.mod b/go.mod index eb7ee3b..d1f434b 100644 --- a/go.mod +++ b/go.mod @@ -106,10 +106,10 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) -replace ( - github.com/aws/aws-sdk-go-v2 v1.32.4 => github.com/pkedy/aws-sdk-go-v2 v0.0.0-20241115203348-0198b6c98cd9 - github.com/aws/aws-sdk-go-v2/config v1.28.4 => github.com/pkedy/aws-sdk-go-v2/config v0.0.0-20241115203348-0198b6c98cd9 - // github.com/aws/aws-sdk-go-v2/credentials v1.17.45 => github.com/pkedy/aws-sdk-go-v2/credentials v0.0.0-20241115203348-0198b6c98cd9 - // github.com/aws/aws-sdk-go-v2/service/autoscaling v1.48.0 => github.com/pkedy/aws-sdk-go-v2/service/autoscaling v0.0.0-20241115203348-0198b6c98cd9 - github.com/aws/aws-sdk-go-v2/service/ec2 v1.188.0 => github.com/pkedy/aws-sdk-go-v2/service/ec2 v0.0.0-20241115203348-0198b6c98cd9 -) +// replace ( +// github.com/aws/aws-sdk-go-v2 v1.32.4 => github.com/pkedy/aws-sdk-go-v2 v0.0.0-20241115203348-0198b6c98cd9 +// github.com/aws/aws-sdk-go-v2/config v1.28.4 => github.com/pkedy/aws-sdk-go-v2/config v0.0.0-20241115203348-0198b6c98cd9 +// // github.com/aws/aws-sdk-go-v2/credentials v1.17.45 => github.com/pkedy/aws-sdk-go-v2/credentials v0.0.0-20241115203348-0198b6c98cd9 +// // github.com/aws/aws-sdk-go-v2/service/autoscaling v1.48.0 => github.com/pkedy/aws-sdk-go-v2/service/autoscaling v0.0.0-20241115203348-0198b6c98cd9 +// github.com/aws/aws-sdk-go-v2/service/ec2 v1.188.0 => github.com/pkedy/aws-sdk-go-v2/service/ec2 v0.0.0-20241115203348-0198b6c98cd9 +// ) diff --git a/pkg/models/model_test.go b/pkg/models/model_test.go index 3d2a2ce..4e2915c 100644 --- a/pkg/models/model_test.go +++ b/pkg/models/model_test.go @@ -23,7 +23,7 @@ import ( ) func TestNewModelFromFile(t *testing.T) { - cfg, err := NewModelFromFile("../../tests/models/medium-h100.yaml") + cfg, err := NewModelFromFile("../../tests/models/medium-tree.yaml") require.NoError(t, err) expected := &Model{ @@ -86,59 +86,95 @@ func TestNewModelFromFile(t *testing.T) { Nodes: []string{"n14-1", "n14-2"}, }, }, - + PhysicalLayers: []PhysicalLayers{ + { + Name: "R1", + Type: "region", + SubLayers: []string{"AZ1", "AZ2"}, + }, + { + Name: "AZ1", + Type: "availability_zone", + SubLayers: []string{"G1"}, + }, + { + Name: "AZ2", + Type: "availability_zone", + SubLayers: []string{"G2"}, + }, + { + Name: "G1", + Type: "placement_group", + CapacityBlocks: []string{"cb10", "cb11", "cb12"}, + }, + { + Name: "G2", + Type: "placement_group", + CapacityBlocks: []string{"cb13", "cb14"}, + }, + }, Nodes: map[string]*Node{ "n10-1": { - Name: "n10-1", - Type: "H100", - NVLink: "nv1", + Name: "n10-1", + Type: "H100", + NVLink: "nv1", + CapacityBlock: "cb10", }, "n10-2": { - Name: "n10-2", - Type: "H100", - NVLink: "nv1", + Name: "n10-2", + Type: "H100", + NVLink: "nv1", + CapacityBlock: "cb10", }, "n11-1": { - Name: "n11-1", - Type: "H100", - NVLink: "nv1", - NetLayers: []string{"sw11", "sw21", "sw3"}, + Name: "n11-1", + Type: "H100", + NVLink: "nv1", + NetLayers: []string{"sw11", "sw21", "sw3"}, + CapacityBlock: "cb11", }, "n11-2": { - Name: "n11-2", - Type: "H100", - NVLink: "nv1", - NetLayers: []string{"sw11", "sw21", "sw3"}, + Name: "n11-2", + Type: "H100", + NVLink: "nv1", + NetLayers: []string{"sw11", "sw21", "sw3"}, + CapacityBlock: "cb11", }, "n12-1": { - Name: "n12-1", - Type: "H100", - NetLayers: []string{"sw12", "sw21", "sw3"}, + Name: "n12-1", + Type: "H100", + NetLayers: []string{"sw12", "sw21", "sw3"}, + CapacityBlock: "cb12", }, "n12-2": { - Name: "n12-2", - Type: "H100", - NetLayers: []string{"sw12", "sw21", "sw3"}, + Name: "n12-2", + Type: "H100", + NetLayers: []string{"sw12", "sw21", "sw3"}, + CapacityBlock: "cb12", }, "n13-1": { - Name: "n13-1", - Type: "H100", - NetLayers: []string{"sw13", "sw22", "sw3"}, + Name: "n13-1", + Type: "H100", + NetLayers: []string{"sw13", "sw22", "sw3"}, + CapacityBlock: "cb13", }, "n13-2": { - Name: "n13-2", - Type: "H100", - NetLayers: []string{"sw13", "sw22", "sw3"}, + Name: "n13-2", + Type: "H100", + NetLayers: []string{"sw13", "sw22", "sw3"}, + CapacityBlock: "cb13", }, "n14-1": { - Name: "n14-1", - Type: "H100", - NetLayers: []string{"sw14", "sw22", "sw3"}, + Name: "n14-1", + Type: "H100", + NetLayers: []string{"sw14", "sw22", "sw3"}, + CapacityBlock: "cb14", }, "n14-2": { - Name: "n14-2", - Type: "H100", - NetLayers: []string{"sw14", "sw22", "sw3"}, + Name: "n14-2", + Type: "H100", + NetLayers: []string{"sw14", "sw22", "sw3"}, + CapacityBlock: "cb14", }, }, } From a3b87bcc88a00e421f8dc5f95f769b3da7bf833c Mon Sep 17 00:00:00 2001 From: Dmitry Shmulevich Date: Tue, 19 Nov 2024 09:47:49 -0800 Subject: [PATCH 5/6] fix typos Signed-off-by: Dmitry Shmulevich --- go.mod | 22 +++++++++++----------- go.sum | 20 ++++++++++---------- pkg/providers/aws/provider_sim.go | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index d1f434b..b79abe7 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( cloud.google.com/go/compute v1.28.2 cloud.google.com/go/compute/metadata v0.5.2 github.com/agrea/ptr v0.2.0 - github.com/aws/aws-sdk-go-v2 v1.32.3 + github.com/aws/aws-sdk-go-v2 v1.32.4 github.com/aws/aws-sdk-go-v2/config v1.28.1 github.com/aws/aws-sdk-go-v2/credentials v1.17.42 github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18 @@ -36,11 +36,11 @@ require ( require ( cloud.google.com/go/auth v0.10.0 // indirect cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.22 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.22 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.23 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.23 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.3 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.4 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.24.3 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.3 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.32.3 // indirect @@ -106,10 +106,10 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) -// replace ( -// github.com/aws/aws-sdk-go-v2 v1.32.4 => github.com/pkedy/aws-sdk-go-v2 v0.0.0-20241115203348-0198b6c98cd9 -// github.com/aws/aws-sdk-go-v2/config v1.28.4 => github.com/pkedy/aws-sdk-go-v2/config v0.0.0-20241115203348-0198b6c98cd9 -// // github.com/aws/aws-sdk-go-v2/credentials v1.17.45 => github.com/pkedy/aws-sdk-go-v2/credentials v0.0.0-20241115203348-0198b6c98cd9 -// // github.com/aws/aws-sdk-go-v2/service/autoscaling v1.48.0 => github.com/pkedy/aws-sdk-go-v2/service/autoscaling v0.0.0-20241115203348-0198b6c98cd9 -// github.com/aws/aws-sdk-go-v2/service/ec2 v1.188.0 => github.com/pkedy/aws-sdk-go-v2/service/ec2 v0.0.0-20241115203348-0198b6c98cd9 -// ) +replace ( + github.com/aws/aws-sdk-go-v2 v1.32.4 => github.com/pkedy/aws-sdk-go-v2 v0.0.0-20241115203348-0198b6c98cd9 + github.com/aws/aws-sdk-go-v2/config v1.28.4 => github.com/pkedy/aws-sdk-go-v2/config v0.0.0-20241115203348-0198b6c98cd9 + github.com/aws/aws-sdk-go-v2/credentials v1.17.45 => github.com/pkedy/aws-sdk-go-v2/credentials v0.0.0-20241115203348-0198b6c98cd9 + github.com/aws/aws-sdk-go-v2/service/autoscaling v1.48.0 => github.com/pkedy/aws-sdk-go-v2/service/autoscaling v0.0.0-20241115203348-0198b6c98cd9 + github.com/aws/aws-sdk-go-v2/service/ec2 v1.187.0 => github.com/pkedy/aws-sdk-go-v2/service/ec2 v0.0.0-20241115203348-0198b6c98cd9 +) diff --git a/go.sum b/go.sum index e295e7f..ef432f7 100644 --- a/go.sum +++ b/go.sum @@ -12,26 +12,22 @@ cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/yb github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/agrea/ptr v0.2.0 h1:QSyCkddC52uOrIvkypI8vTqUFw0KAnP71u1JU36EvBk= github.com/agrea/ptr v0.2.0/go.mod h1:O85aMmwHY6iqdSLPiaHMVz9AI7qvsZk3JPZ/i13Ec3Y= -github.com/aws/aws-sdk-go-v2 v1.32.3 h1:T0dRlFBKcdaUPGNtkBSwHZxrtis8CQU17UpNBZYd0wk= -github.com/aws/aws-sdk-go-v2 v1.32.3/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= github.com/aws/aws-sdk-go-v2/config v1.28.1 h1:oxIvOUXy8x0U3fR//0eq+RdCKimWI900+SV+10xsCBw= github.com/aws/aws-sdk-go-v2/config v1.28.1/go.mod h1:bRQcttQJiARbd5JZxw6wG0yIK3eLeSCPdg6uqmmlIiI= github.com/aws/aws-sdk-go-v2/credentials v1.17.42 h1:sBP0RPjBU4neGpIYyx8mkU2QqLPl5u9cmdTWVzIpHkM= github.com/aws/aws-sdk-go-v2/credentials v1.17.42/go.mod h1:FwZBfU530dJ26rv9saAbxa9Ej3eF/AK0OAY86k13n4M= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18 h1:68jFVtt3NulEzojFesM/WVarlFpCaXLKaBxDpzkQ9OQ= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18/go.mod h1:Fjnn5jQVIo6VyedMc0/EhPpfNlPl7dHV916O6B+49aE= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.22 h1:Jw50LwEkVjuVzE1NzkhNKkBf9cRN7MtE1F/b2cOKTUM= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.22/go.mod h1:Y/SmAyPcOTmpeVaWSzSKiILfXTVJwrGmYZhcRbhWuEY= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.22 h1:981MHwBaRZM7+9QSR6XamDzF/o7ouUGxFzr+nVSIhrs= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.22/go.mod h1:1RA1+aBEfn+CAB/Mh0MB6LsdCYCnjZm7tKXtnk499ZQ= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.23 h1:A2w6m6Tmr+BNXjDsr7M90zkWjsu4JXHwrzPg235STs4= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.23/go.mod h1:35EVp9wyeANdujZruvHiQUAo9E3vbhnIO1mTCAxMlY0= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.23 h1:pgYW9FCabt2M25MoHYCfMrVY2ghiiBKYWUVXfwZs+sU= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.23/go.mod h1:c48kLgzO19wAu3CPkDWC28JbaJ+hfQlsdl7I2+oqIbk= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc= -github.com/aws/aws-sdk-go-v2/service/ec2 v1.187.0 h1:cA4hWo269CN5RY7Arqt8BfzXF0KIN8DSNo/KcqHKkWk= -github.com/aws/aws-sdk-go-v2/service/ec2 v1.187.0/go.mod h1:ossaD9Z1ugYb6sq9QIqQLEOorCGcqUoxlhud9M9yE70= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0/go.mod h1:0jp+ltwkf+SwG2fm/PKo8t4y8pJSgOCO4D8Lz3k0aHQ= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.3 h1:qcxX0JYlgWH3hpPUnd6U0ikcl6LLA9sLkXE2w1fpMvY= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.3/go.mod h1:cLSNEmI45soc+Ef8K/L+8sEA3A3pYFEYf5B5UI+6bH4= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.4 h1:tHxQi/XHPK0ctd/wdOw0t7Xrc2OxcRCnVzv8lwWPu0c= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.4/go.mod h1:4GQbF1vJzG60poZqWatZlhP31y8PGCCVTvIGPdaaYJ0= github.com/aws/aws-sdk-go-v2/service/sso v1.24.3 h1:UTpsIf0loCIWEbrqdLb+0RxnTXfWh2vhw4nQmFi4nPc= github.com/aws/aws-sdk-go-v2/service/sso v1.24.3/go.mod h1:FZ9j3PFHHAR+w0BSEjK955w5YD2UwB/l/H0yAK3MJvI= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.3 h1:2YCmIXv3tmiItw0LlYf6v7gEHebLY45kBEnPezbUKyU= @@ -167,6 +163,10 @@ github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0= github.com/oracle/oci-go-sdk/v65 v65.78.0 h1:iM7lFFA7cJkUD4tmrlsAHWgL3HuTuF9mdvTAliMkcFA= github.com/oracle/oci-go-sdk/v65 v65.78.0/go.mod h1:IBEV9l1qBzUpo7zgGaRUhbB05BVfcDGYRFBCPlTcPp0= +github.com/pkedy/aws-sdk-go-v2 v0.0.0-20241115203348-0198b6c98cd9 h1:QhMFD0yJ9nEj4BCX9lREQ7twLM5oEL8y9UwKsRNJamo= +github.com/pkedy/aws-sdk-go-v2 v0.0.0-20241115203348-0198b6c98cd9/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= +github.com/pkedy/aws-sdk-go-v2/service/ec2 v0.0.0-20241115203348-0198b6c98cd9 h1:wA7yd0OxRH3EWuKaJ7ijRowlWgH2b99nrP+d10+0Sc4= +github.com/pkedy/aws-sdk-go-v2/service/ec2 v0.0.0-20241115203348-0198b6c98cd9/go.mod h1:0A17IIeys01WfjDKehspGP+Cyo/YH/eNADIbEbRS9yM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/pkg/providers/aws/provider_sim.go b/pkg/providers/aws/provider_sim.go index e840152..d8fa454 100644 --- a/pkg/providers/aws/provider_sim.go +++ b/pkg/providers/aws/provider_sim.go @@ -100,7 +100,7 @@ func (client SimClient) DescribeInstanceTopology(ctx context.Context, params *ec instTopo.AvailabilityZone = &az instTopo.ZoneId = &az instTopo.GroupName = &pg - // instTopo.CapacityBlockID = &node.CapacityBlock + instTopo.CapacityBlockId = &node.CapacityBlock var netLayers []string for j := len(node.NetLayers) - 1; j >= 0; j-- { netLayers = append(netLayers, node.NetLayers[j]) From 3468bb97746584b0a8d95648db2d00e69c99de5d Mon Sep 17 00:00:00 2001 From: Henry Haase Date: Wed, 20 Nov 2024 01:56:38 -0600 Subject: [PATCH 6/6] Changed a few style nits Signed-off-by: Henry Haase --- go.mod | 4 ++-- pkg/providers/aws/provider_sim.go | 30 +++++++++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index b79abe7..d9d32bd 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18 github.com/aws/aws-sdk-go-v2/service/ec2 v1.187.0 github.com/go-playground/validator/v10 v10.22.1 + github.com/golang/protobuf v1.5.4 github.com/google/uuid v1.6.0 github.com/googleapis/gax-go/v2 v2.13.0 github.com/hashicorp/golang-lru v1.0.2 @@ -25,7 +26,6 @@ require ( golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c google.golang.org/api v0.204.0 google.golang.org/grpc v1.67.1 - google.golang.org/protobuf v1.35.1 gopkg.in/yaml.v3 v3.0.1 k8s.io/api v0.31.2 k8s.io/apimachinery v0.31.2 @@ -62,7 +62,6 @@ require ( github.com/gofrs/flock v0.12.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/protobuf v1.5.4 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect @@ -97,6 +96,7 @@ require ( google.golang.org/genproto v0.0.0-20241104194629-dd2ea8efbc28 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect + google.golang.org/protobuf v1.35.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect k8s.io/kube-openapi v0.0.0-20241009091222-67ed5848f094 // indirect diff --git a/pkg/providers/aws/provider_sim.go b/pkg/providers/aws/provider_sim.go index d8fa454..7a0e9a2 100644 --- a/pkg/providers/aws/provider_sim.go +++ b/pkg/providers/aws/provider_sim.go @@ -44,6 +44,8 @@ type SimClient struct { NextTokens map[string]string } +var simulationClient *Client = nil + func (client SimClient) DescribeInstanceTopology(ctx context.Context, params *ec2.DescribeInstanceTopologyInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstanceTopologyOutput, error) { // If we need to calculate new results (a previous token was not given) @@ -94,18 +96,19 @@ func (client SimClient) DescribeInstanceTopology(ctx context.Context, params *ec } // Sets up the structure for the instance - var instTopo types.InstanceTopology - instTopo.InstanceId = &instanceId - instTopo.InstanceType = &node.Type - instTopo.AvailabilityZone = &az - instTopo.ZoneId = &az - instTopo.GroupName = &pg - instTopo.CapacityBlockId = &node.CapacityBlock var netLayers []string for j := len(node.NetLayers) - 1; j >= 0; j-- { netLayers = append(netLayers, node.NetLayers[j]) } - instTopo.NetworkNodes = netLayers + instTopo := types.InstanceTopology{ + InstanceId: &instanceId, + InstanceType: &node.Type, + AvailabilityZone: &az, + ZoneId: &az, + GroupName: &pg, + CapacityBlockId: &node.CapacityBlock, + NetworkNodes: netLayers, + } instances = append(instances, instTopo) } @@ -156,16 +159,21 @@ func LoaderSim(ctx context.Context, cfg providers.Config) (providers.Provider, e return nil, fmt.Errorf("no model path for AWS simulation") } - clientFactory := func(region string) (*Client, error) { + // Initializes the singleton, simulation client to be used, if not already done + if simulationClient == nil { csp_model, err := models.NewModelFromFile(p.ModelPath) if err != nil { return nil, fmt.Errorf("unable to load model file for AWS simulation, %v", err) } simClient := SimClient{Model: csp_model} - return &Client{ + simulationClient = &Client{ EC2: simClient, - }, nil + } + } + + clientFactory := func(region string) (*Client, error) { + return simulationClient, nil } return New(clientFactory, imdsClient), nil