class ChaosController
Controller for chaos operations.
Handles registration of victims, victim lookup, and status queries.
Definitions
attr :server
Signature
-
attribute
Server The server instance.
attr :connection
Signature
-
attribute
Connection The connection instance.
attr :id
Signature
-
attribute
Integer The ID assigned to this victim.
attr :process_id
Signature
-
attribute
Integer The process ID of the victim.
attr :victim
Signature
-
attribute
Proxy The proxy to the victim controller.
def register(victim, process_id:)
Register a victim connection with the chaos server.
Allocates a unique sequential ID, stores the victim controller proxy, and notifies all chaos operations of the new connection.
Signature
-
parameter
victimProxy The proxy to the victim controller.
-
parameter
process_idInteger The process ID of the victim.
-
returns
Integer The connection ID assigned to the victim.
Implementation
def register(victim, process_id:)
raise RuntimeError, "Already registered" if @id
@id = @server.next_id
@process_id = process_id
@victim = victim
@server.add(self)
return @id
end
def [](id)
Get a victim controller proxy by connection ID.
Returns a proxy to the victim controller that can be used to invoke operations directly on the victim. The proxy uses multi-hop forwarding to route calls through the chaos server to the victim.
Signature
-
parameter
idInteger The ID of the victim.
-
returns
Proxy A proxy to the victim controller.
-
raises
ArgumentError If the connection ID is not found.
Implementation
def [](id)
unless id
raise ArgumentError, "Missing 'id' parameter"
end
chaos_controller = @server.controllers[id]
unless chaos_controller
raise ArgumentError, "Connection not found: #{id}"
end
victim = chaos_controller.victim
unless victim
raise ArgumentError, "Victim controller not found for connection: #{id}"
end
return victim
end
def keys
List all registered victim IDs.
Signature
-
returns
Array(Integer) An array of IDs for all registered victims.
Implementation
def keys
@server.controllers.keys
end
def status
Query the status of the chaos server and all connected victims.
Returns an array of status information from each chaos operation. Each chaos operation provides its own status representation.
Signature
-
returns
Array An array of status information from each chaos operation.
Implementation
def status
@server.chaos_operations.map do |chaos|
begin
chaos.status
rescue => error
error
end
end.compact
end