mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 00:54:23 +00:00
Refactor instance node handling to use a map
This commit is contained in:
@@ -275,9 +275,19 @@ func (im *instanceManager) loadInstance(name, path string) error {
|
||||
|
||||
options := persistedInstance.GetOptions()
|
||||
|
||||
// Check if this is a remote instance
|
||||
// An instance is remote if Nodes is specified AND the first node is not the local node
|
||||
isRemote := options != nil && len(options.Nodes) > 0 && options.Nodes[0] != im.localNodeName
|
||||
// Check if this is a remote instance (local node not in the Nodes set)
|
||||
var isRemote bool
|
||||
var nodeName string
|
||||
if options != nil {
|
||||
if _, isLocal := options.Nodes[im.localNodeName]; !isLocal {
|
||||
// Get the first node from the set
|
||||
for node := range options.Nodes {
|
||||
nodeName = node
|
||||
isRemote = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var statusCallback func(oldStatus, newStatus instance.Status)
|
||||
if !isRemote {
|
||||
@@ -296,7 +306,6 @@ func (im *instanceManager) loadInstance(name, path string) error {
|
||||
|
||||
// Handle remote instance mapping
|
||||
if isRemote {
|
||||
nodeName := options.Nodes[0]
|
||||
nodeConfig, exists := im.nodeConfigMap[nodeName]
|
||||
if !exists {
|
||||
return fmt.Errorf("node %s not found for remote instance %s", nodeName, name)
|
||||
|
||||
@@ -3,7 +3,6 @@ package manager
|
||||
import (
|
||||
"fmt"
|
||||
"llamactl/pkg/backends"
|
||||
"llamactl/pkg/config"
|
||||
"llamactl/pkg/instance"
|
||||
"llamactl/pkg/validation"
|
||||
"os"
|
||||
@@ -27,10 +26,12 @@ func (im *instanceManager) updateLocalInstanceFromRemote(localInst *instance.Ins
|
||||
|
||||
// Preserve the Nodes field from the local instance
|
||||
localOptions := localInst.GetOptions()
|
||||
var preservedNodes []string
|
||||
var preservedNodes map[string]struct{}
|
||||
if localOptions != nil && len(localOptions.Nodes) > 0 {
|
||||
preservedNodes = make([]string, len(localOptions.Nodes))
|
||||
copy(preservedNodes, localOptions.Nodes)
|
||||
preservedNodes = make(map[string]struct{}, len(localOptions.Nodes))
|
||||
for node := range localOptions.Nodes {
|
||||
preservedNodes[node] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a copy of remote options and restore the Nodes field
|
||||
@@ -98,16 +99,17 @@ func (im *instanceManager) CreateInstance(name string, options *instance.Options
|
||||
return nil, fmt.Errorf("instance with name %s already exists", name)
|
||||
}
|
||||
|
||||
// Check if this is a remote instance
|
||||
// An instance is remote if Nodes is specified AND the first node is not the local node
|
||||
isRemote := len(options.Nodes) > 0 && options.Nodes[0] != im.localNodeName
|
||||
var nodeConfig *config.NodeConfig
|
||||
// Check if this is a remote instance (local node not in the Nodes set)
|
||||
if _, isLocal := options.Nodes[im.localNodeName]; !isLocal && len(options.Nodes) > 0 {
|
||||
// Get the first node from the set
|
||||
var nodeName string
|
||||
for node := range options.Nodes {
|
||||
nodeName = node
|
||||
break
|
||||
}
|
||||
|
||||
if isRemote {
|
||||
// Validate that the node exists
|
||||
nodeName := options.Nodes[0] // Use first node for now
|
||||
var exists bool
|
||||
nodeConfig, exists = im.nodeConfigMap[nodeName]
|
||||
nodeConfig, exists := im.nodeConfigMap[nodeName]
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("node %s not found", nodeName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user