@@ -11,8 +11,6 @@ import (
1111 "path/filepath"
1212 "regexp"
1313 "strings"
14-
15- "gopkg.in/yaml.v2"
1614)
1715
1816type WorkspaceState int
@@ -76,51 +74,13 @@ func (ac *AnyscaleCLI) runAnyscaleCLI(args []string) (string, error) {
7674 if err := cmd .Run (); err != nil {
7775 return outputBuf .String (), fmt .Errorf ("anyscale error: %w" , err )
7876 }
79- // If outputBuf contains "exec failed with exit code *" return error
8077 if strings .Contains (outputBuf .String (), "exec failed with exit code" ) {
8178 return "" , fmt .Errorf ("anyscale error: command failed: %s" , outputBuf .String ())
8279 }
8380
8481 return outputBuf .String (), nil
8582}
8683
87- // parseComputeConfigName parses the AWS config path and converts it to a config name.
88- // e.g., "configs/basic-single-node/aws.yaml" -> "basic-single-node-aws"
89- func parseComputeConfigName (awsConfigPath string ) string {
90- // Get the directory and filename
91- dir := filepath .Dir (awsConfigPath ) // "configs/basic-single-node"
92- base := filepath .Base (awsConfigPath ) // "aws.yaml"
93- ext := filepath .Ext (base ) // ".yaml"
94- filename := strings .TrimSuffix (base , ext ) // "aws"
95-
96- // Get the last directory component (the config name)
97- configDir := filepath .Base (dir ) // "basic-single-node"
98-
99- // Combine: "basic-single-node-aws"
100- return configDir + "-" + filename
101- }
102-
103- // isOldComputeConfigFormat checks if a YAML file uses the old compute config format
104- // by looking for old-style keys like "head_node_type" or "worker_node_types".
105- func isOldComputeConfigFormat (configFilePath string ) (bool , error ) {
106- data , err := os .ReadFile (configFilePath )
107- if err != nil {
108- return false , fmt .Errorf ("failed to read config file: %w" , err )
109- }
110-
111- // Parse into a generic map to check for old-style keys
112- var configMap map [string ]interface {}
113- if err := yaml .Unmarshal (data , & configMap ); err != nil {
114- return false , fmt .Errorf ("failed to parse config file: %w" , err )
115- }
116-
117- // Check for old format keys
118- _ , hasHeadNodeType := configMap ["head_node_type" ]
119- _ , hasWorkerNodeTypes := configMap ["worker_node_types" ]
120-
121- return hasHeadNodeType || hasWorkerNodeTypes , nil
122- }
123-
12484// CreateComputeConfig creates a new compute config from a YAML file if it doesn't already exist.
12585// If the config file uses the old format (head_node_type, worker_node_types), it will be
12686// automatically converted to the new format before creation.
@@ -327,87 +287,6 @@ func (ac *AnyscaleCLI) waitForWorkspaceState(workspaceName string, state Workspa
327287 return output , nil
328288}
329289
330- // OldComputeConfig represents the old compute config format
331- type OldComputeConfig struct {
332- HeadNodeType OldHeadNodeType `yaml:"head_node_type"`
333- WorkerNodeTypes []OldWorkerNodeType `yaml:"worker_node_types"`
334- }
335-
336- // OldHeadNodeType represents the head node configuration in old format
337- type OldHeadNodeType struct {
338- Name string `yaml:"name"`
339- InstanceType string `yaml:"instance_type"`
340- }
341-
342- // OldWorkerNodeType represents a worker node configuration in old format
343- type OldWorkerNodeType struct {
344- Name string `yaml:"name"`
345- InstanceType string `yaml:"instance_type"`
346- }
347-
348- // NewComputeConfig represents the new compute config format
349- type NewComputeConfig struct {
350- HeadNode NewHeadNode `yaml:"head_node"`
351- AutoSelectWorkerConfig bool `yaml:"auto_select_worker_config"`
352- }
353-
354- // NewHeadNode represents the head node configuration in new format
355- type NewHeadNode struct {
356- InstanceType string `yaml:"instance_type"`
357- }
358-
359- // ConvertComputeConfig converts an old format compute config to the new format.
360- // It reads the old YAML file, transforms the structure, and returns the new YAML content.
361- func ConvertComputeConfig (oldConfigPath string ) ([]byte , error ) {
362- // Read the old config file
363- data , err := os .ReadFile (oldConfigPath )
364- if err != nil {
365- return nil , fmt .Errorf ("failed to read old config file: %w" , err )
366- }
367-
368- // Parse the old format
369- var oldConfig OldComputeConfig
370- if err := yaml .Unmarshal (data , & oldConfig ); err != nil {
371- return nil , fmt .Errorf ("failed to parse old config: %w" , err )
372- }
373-
374- // Convert to new format
375- newConfig := NewComputeConfig {
376- HeadNode : NewHeadNode {
377- InstanceType : oldConfig .HeadNodeType .InstanceType ,
378- },
379- AutoSelectWorkerConfig : true ,
380- }
381-
382- // Marshal to YAML
383- newData , err := yaml .Marshal (& newConfig )
384- if err != nil {
385- return nil , fmt .Errorf ("failed to marshal new config: %w" , err )
386- }
387-
388- return newData , nil
389- }
390-
391- // ConvertComputeConfigFile converts an old format compute config file to a new format file.
392- // If outputPath is empty, the new config is written to stdout.
393- func ConvertComputeConfigFile (oldConfigPath , newConfigPath string ) error {
394- newData , err := ConvertComputeConfig (oldConfigPath )
395- if err != nil {
396- return err
397- }
398-
399- if newConfigPath == "" {
400- fmt .Print (string (newData ))
401- return nil
402- }
403-
404- if err := os .WriteFile (newConfigPath , newData , 0644 ); err != nil {
405- return fmt .Errorf ("failed to write new config file: %w" , err )
406- }
407-
408- return nil
409- }
410-
411290func convertBuildIdToImageURI (buildId string ) (string , string , error ) {
412291 // Convert build ID like "anyscaleray2441-py312-cu128" to "anyscale/ray:2.44.1-py312-cu128"
413292 const prefix = "anyscaleray"
0 commit comments