Documentation
¶
Overview ¶
Package memory provides an in-memory implementation of the Job Distributor client.
This package is designed for testing purposes when you don't need a real JD backend. All data is stored in memory and is lost when the client is garbage collected.
Thread Safety ¶
The MemoryJobDistributor implementation is thread-safe and uses sync.RWMutex to protect concurrent access to internal data structures. Multiple goroutines can safely call methods on the same MemoryJobDistributor instance concurrently.
Usage ¶
Create a new in-memory JD client:
client := memory.NewMemoryJobDistributor()
Use it like any other JD client:
resp, err := client.ProposeJob(ctx, &jobv1.ProposeJobRequest{
NodeId: "test-node",
Spec: "job spec here",
})
Limitations ¶
- No persistence: All data is stored in memory only - Test-only: This implementation is intended for testing and should not be used in production environments
Implementation Details ¶
The client maintains four in-memory maps:
- jobs: Stores job instances by job ID
- proposals: Stores job proposals by proposal ID
- nodes: Stores node registrations by node ID
- keypairs: Stores CSA keypairs by public key
All write operations (create, update, delete) modify these maps directly, and read operations return data from these maps.
Index ¶
- type MemoryJobDistributor
- func (m *MemoryJobDistributor) AddChainConfig(nodeID string, config *nodev1.ChainConfig) error
- func (m *MemoryJobDistributor) AddKeypair(keypair *csav1.Keypair)
- func (m *MemoryJobDistributor) BatchProposeJob(ctx context.Context, in *jobv1.BatchProposeJobRequest, opts ...grpc.CallOption) (*jobv1.BatchProposeJobResponse, error)
- func (m *MemoryJobDistributor) DeleteJob(ctx context.Context, in *jobv1.DeleteJobRequest, opts ...grpc.CallOption) (*jobv1.DeleteJobResponse, error)
- func (m *MemoryJobDistributor) DisableNode(ctx context.Context, in *nodev1.DisableNodeRequest, opts ...grpc.CallOption) (*nodev1.DisableNodeResponse, error)
- func (m *MemoryJobDistributor) EnableNode(ctx context.Context, in *nodev1.EnableNodeRequest, opts ...grpc.CallOption) (*nodev1.EnableNodeResponse, error)
- func (m *MemoryJobDistributor) GetJob(ctx context.Context, in *jobv1.GetJobRequest, opts ...grpc.CallOption) (*jobv1.GetJobResponse, error)
- func (m *MemoryJobDistributor) GetKeypair(ctx context.Context, in *csav1.GetKeypairRequest, opts ...grpc.CallOption) (*csav1.GetKeypairResponse, error)
- func (m *MemoryJobDistributor) GetNode(ctx context.Context, in *nodev1.GetNodeRequest, opts ...grpc.CallOption) (*nodev1.GetNodeResponse, error)
- func (m *MemoryJobDistributor) GetProposal(ctx context.Context, in *jobv1.GetProposalRequest, opts ...grpc.CallOption) (*jobv1.GetProposalResponse, error)
- func (m *MemoryJobDistributor) ListJobs(ctx context.Context, in *jobv1.ListJobsRequest, opts ...grpc.CallOption) (*jobv1.ListJobsResponse, error)
- func (m *MemoryJobDistributor) ListKeypairs(ctx context.Context, in *csav1.ListKeypairsRequest, opts ...grpc.CallOption) (*csav1.ListKeypairsResponse, error)
- func (m *MemoryJobDistributor) ListNodeChainConfigs(ctx context.Context, in *nodev1.ListNodeChainConfigsRequest, ...) (*nodev1.ListNodeChainConfigsResponse, error)
- func (m *MemoryJobDistributor) ListNodes(ctx context.Context, in *nodev1.ListNodesRequest, opts ...grpc.CallOption) (*nodev1.ListNodesResponse, error)
- func (m *MemoryJobDistributor) ListProposals(ctx context.Context, in *jobv1.ListProposalsRequest, opts ...grpc.CallOption) (*jobv1.ListProposalsResponse, error)
- func (m *MemoryJobDistributor) ProposeJob(ctx context.Context, in *jobv1.ProposeJobRequest, opts ...grpc.CallOption) (*jobv1.ProposeJobResponse, error)
- func (m *MemoryJobDistributor) RegisterNode(ctx context.Context, in *nodev1.RegisterNodeRequest, opts ...grpc.CallOption) (*nodev1.RegisterNodeResponse, error)
- func (m *MemoryJobDistributor) RevokeJob(ctx context.Context, in *jobv1.RevokeJobRequest, opts ...grpc.CallOption) (*jobv1.RevokeJobResponse, error)
- func (m *MemoryJobDistributor) UpdateJob(ctx context.Context, in *jobv1.UpdateJobRequest, opts ...grpc.CallOption) (*jobv1.UpdateJobResponse, error)
- func (m *MemoryJobDistributor) UpdateNode(ctx context.Context, in *nodev1.UpdateNodeRequest, opts ...grpc.CallOption) (*nodev1.UpdateNodeResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemoryJobDistributor ¶
type MemoryJobDistributor struct {
// contains filtered or unexported fields
}
MemoryJobDistributor is an in-memory implementation of the Job Distributor client. It stores jobs, proposals, nodes, and keypairs in memory without persisting to any backend. This implementation is thread-safe and can be used concurrently from multiple goroutines.
func NewMemoryJobDistributor ¶
func NewMemoryJobDistributor() *MemoryJobDistributor
NewMemoryJobDistributor creates a new in-memory Job Distributor client.
func (*MemoryJobDistributor) AddChainConfig ¶
func (m *MemoryJobDistributor) AddChainConfig(nodeID string, config *nodev1.ChainConfig) error
AddChainConfig is a helper method to add chain configurations for testing purposes. This is not part of the standard interface but is useful for setting up test data.
func (*MemoryJobDistributor) AddKeypair ¶
func (m *MemoryJobDistributor) AddKeypair(keypair *csav1.Keypair)
AddKeypair is a helper method to add a CSA keypair for testing purposes. This is not part of the standard interface but is useful for setting up test data.
func (*MemoryJobDistributor) BatchProposeJob ¶
func (m *MemoryJobDistributor) BatchProposeJob(ctx context.Context, in *jobv1.BatchProposeJobRequest, opts ...grpc.CallOption) (*jobv1.BatchProposeJobResponse, error)
BatchProposeJob creates multiple job proposals in a batch.
func (*MemoryJobDistributor) DeleteJob ¶
func (m *MemoryJobDistributor) DeleteJob(ctx context.Context, in *jobv1.DeleteJobRequest, opts ...grpc.CallOption) (*jobv1.DeleteJobResponse, error)
DeleteJob soft deletes a job, setting the DeletedAt field to the current time.
func (*MemoryJobDistributor) DisableNode ¶
func (m *MemoryJobDistributor) DisableNode(ctx context.Context, in *nodev1.DisableNodeRequest, opts ...grpc.CallOption) (*nodev1.DisableNodeResponse, error)
DisableNode disables a node.
func (*MemoryJobDistributor) EnableNode ¶
func (m *MemoryJobDistributor) EnableNode(ctx context.Context, in *nodev1.EnableNodeRequest, opts ...grpc.CallOption) (*nodev1.EnableNodeResponse, error)
EnableNode enables a disabled node.
func (*MemoryJobDistributor) GetJob ¶
func (m *MemoryJobDistributor) GetJob(ctx context.Context, in *jobv1.GetJobRequest, opts ...grpc.CallOption) (*jobv1.GetJobResponse, error)
GetJob retrieves a job by its ID.
func (*MemoryJobDistributor) GetKeypair ¶
func (m *MemoryJobDistributor) GetKeypair(ctx context.Context, in *csav1.GetKeypairRequest, opts ...grpc.CallOption) (*csav1.GetKeypairResponse, error)
GetKeypair retrieves the first CSA keypair (simulates getting the active keypair).
func (*MemoryJobDistributor) GetNode ¶
func (m *MemoryJobDistributor) GetNode(ctx context.Context, in *nodev1.GetNodeRequest, opts ...grpc.CallOption) (*nodev1.GetNodeResponse, error)
GetNode retrieves a node by its ID.
func (*MemoryJobDistributor) GetProposal ¶
func (m *MemoryJobDistributor) GetProposal(ctx context.Context, in *jobv1.GetProposalRequest, opts ...grpc.CallOption) (*jobv1.GetProposalResponse, error)
GetProposal retrieves a proposal by its ID.
func (*MemoryJobDistributor) ListJobs ¶
func (m *MemoryJobDistributor) ListJobs(ctx context.Context, in *jobv1.ListJobsRequest, opts ...grpc.CallOption) (*jobv1.ListJobsResponse, error)
ListJobs returns all jobs stored in memory.
func (*MemoryJobDistributor) ListKeypairs ¶
func (m *MemoryJobDistributor) ListKeypairs(ctx context.Context, in *csav1.ListKeypairsRequest, opts ...grpc.CallOption) (*csav1.ListKeypairsResponse, error)
ListKeypairs returns all CSA keypairs stored in memory.
func (*MemoryJobDistributor) ListNodeChainConfigs ¶
func (m *MemoryJobDistributor) ListNodeChainConfigs(ctx context.Context, in *nodev1.ListNodeChainConfigsRequest, opts ...grpc.CallOption) (*nodev1.ListNodeChainConfigsResponse, error)
ListNodeChainConfigs returns chain configurations for nodes.
func (*MemoryJobDistributor) ListNodes ¶
func (m *MemoryJobDistributor) ListNodes(ctx context.Context, in *nodev1.ListNodesRequest, opts ...grpc.CallOption) (*nodev1.ListNodesResponse, error)
ListNodes returns all nodes stored in memory.
func (*MemoryJobDistributor) ListProposals ¶
func (m *MemoryJobDistributor) ListProposals(ctx context.Context, in *jobv1.ListProposalsRequest, opts ...grpc.CallOption) (*jobv1.ListProposalsResponse, error)
ListProposals returns all proposals stored in memory.
func (*MemoryJobDistributor) ProposeJob ¶
func (m *MemoryJobDistributor) ProposeJob( ctx context.Context, in *jobv1.ProposeJobRequest, opts ...grpc.CallOption, ) (*jobv1.ProposeJobResponse, error)
ProposeJob creates a new job proposal and stores it in memory.
func (*MemoryJobDistributor) RegisterNode ¶
func (m *MemoryJobDistributor) RegisterNode(ctx context.Context, in *nodev1.RegisterNodeRequest, opts ...grpc.CallOption) (*nodev1.RegisterNodeResponse, error)
RegisterNode registers a new node in memory.
func (*MemoryJobDistributor) RevokeJob ¶
func (m *MemoryJobDistributor) RevokeJob(ctx context.Context, in *jobv1.RevokeJobRequest, opts ...grpc.CallOption) (*jobv1.RevokeJobResponse, error)
RevokeJob revokes an existing job proposal.
func (*MemoryJobDistributor) UpdateJob ¶
func (m *MemoryJobDistributor) UpdateJob(ctx context.Context, in *jobv1.UpdateJobRequest, opts ...grpc.CallOption) (*jobv1.UpdateJobResponse, error)
UpdateJob updates an existing job in memory.
func (*MemoryJobDistributor) UpdateNode ¶
func (m *MemoryJobDistributor) UpdateNode(ctx context.Context, in *nodev1.UpdateNodeRequest, opts ...grpc.CallOption) (*nodev1.UpdateNodeResponse, error)
UpdateNode updates an existing node in memory.