|
| 1 | +package jd |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "google.golang.org/grpc" |
| 7 | + |
| 8 | + cldf_offchain "github.com/smartcontractkit/chainlink-deployments-framework/offchain" |
| 9 | + |
| 10 | + "github.com/smartcontractkit/chainlink-common/pkg/logger" |
| 11 | + csav1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/csa" |
| 12 | + jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job" |
| 13 | + nodev1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node" |
| 14 | +) |
| 15 | + |
| 16 | +// DryRunJobDistributor is a readonly JD client. |
| 17 | +// Read operations are forwarded to the real backend, while write operations are ignored. |
| 18 | +type DryRunJobDistributor struct { |
| 19 | + // Used for read-only commands |
| 20 | + realBackend cldf_offchain.Client |
| 21 | + lggr logger.Logger |
| 22 | +} |
| 23 | + |
| 24 | +var _ cldf_offchain.Client = (*DryRunJobDistributor)(nil) |
| 25 | + |
| 26 | +// NewDryRunJobDistributor creates a new DryRunJobDistributor. |
| 27 | +func NewDryRunJobDistributor(realBackend cldf_offchain.Client, lggr logger.Logger) *DryRunJobDistributor { |
| 28 | + return &DryRunJobDistributor{ |
| 29 | + realBackend: realBackend, |
| 30 | + lggr: lggr, |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +// GetJob retrieves a specific job by its ID from the Job Distributor. |
| 35 | +// This operation is forwarded to the real backend since it's a read-only operation. |
| 36 | +func (d *DryRunJobDistributor) GetJob(ctx context.Context, in *jobv1.GetJobRequest, opts ...grpc.CallOption) (*jobv1.GetJobResponse, error) { |
| 37 | + d.lggr.Infow("DryRunJobDistributor.GetJob", "in", in) |
| 38 | + return d.realBackend.GetJob(ctx, in) |
| 39 | +} |
| 40 | + |
| 41 | +// GetProposal retrieves a specific job proposal by its ID from the Job Distributor. |
| 42 | +// This operation is forwarded to the real backend since it's a read-only operation. |
| 43 | +func (d *DryRunJobDistributor) GetProposal(ctx context.Context, in *jobv1.GetProposalRequest, opts ...grpc.CallOption) (*jobv1.GetProposalResponse, error) { |
| 44 | + d.lggr.Infow("DryRunJobDistributor.GetProposal", "in", in) |
| 45 | + return d.realBackend.GetProposal(ctx, in) |
| 46 | +} |
| 47 | + |
| 48 | +// ListJobs retrieves a list of all jobs from the Job Distributor. |
| 49 | +// This operation is forwarded to the real backend since it's a read-only operation. |
| 50 | +func (d *DryRunJobDistributor) ListJobs(ctx context.Context, in *jobv1.ListJobsRequest, opts ...grpc.CallOption) (*jobv1.ListJobsResponse, error) { |
| 51 | + d.lggr.Infow("DryRunJobDistributor.ListJobs", "in", in) |
| 52 | + return d.realBackend.ListJobs(ctx, in) |
| 53 | +} |
| 54 | + |
| 55 | +// ListProposals retrieves a list of all job proposals from the Job Distributor. |
| 56 | +// This operation is forwarded to the real backend since it's a read-only operation. |
| 57 | +func (d *DryRunJobDistributor) ListProposals(ctx context.Context, in *jobv1.ListProposalsRequest, opts ...grpc.CallOption) (*jobv1.ListProposalsResponse, error) { |
| 58 | + d.lggr.Infow("DryRunJobDistributor.ListProposals", "in", in) |
| 59 | + return d.realBackend.ListProposals(ctx, in) |
| 60 | +} |
| 61 | + |
| 62 | +// ProposeJob simulates proposing a new job to the Job Distributor without actually submitting it. |
| 63 | +// In dry run mode, this returns a mock proposal response with a dummy job ID indicating |
| 64 | +// the job was not actually proposed to the node. |
| 65 | +func (d *DryRunJobDistributor) ProposeJob(ctx context.Context, in *jobv1.ProposeJobRequest, opts ...grpc.CallOption) (*jobv1.ProposeJobResponse, error) { |
| 66 | + d.lggr.Infow("DryRunJobDistributor.ProposeJob", "in", in) |
| 67 | + return &jobv1.ProposeJobResponse{ |
| 68 | + Proposal: &jobv1.Proposal{ |
| 69 | + JobId: "dryRunJobId_NOT_PROPOSED_on_node_" + in.NodeId, |
| 70 | + Spec: in.Spec, |
| 71 | + Status: jobv1.ProposalStatus_PROPOSAL_STATUS_UNSPECIFIED, |
| 72 | + }, |
| 73 | + }, nil |
| 74 | +} |
| 75 | + |
| 76 | +// BatchProposeJob simulates proposing multiple jobs in a batch to the Job Distributor without actually submitting them. |
| 77 | +// In dry run mode, this returns an empty response indicating the batch operation was logged but not executed. |
| 78 | +func (d *DryRunJobDistributor) BatchProposeJob(ctx context.Context, in *jobv1.BatchProposeJobRequest, opts ...grpc.CallOption) (*jobv1.BatchProposeJobResponse, error) { |
| 79 | + d.lggr.Infow("DryRunJobDistributor.BatchProposeJob", "in", in) |
| 80 | + return &jobv1.BatchProposeJobResponse{}, nil |
| 81 | +} |
| 82 | + |
| 83 | +// RevokeJob simulates revoking a job from the Job Distributor without actually executing the revocation. |
| 84 | +// In dry run mode, this returns an empty response indicating the revocation was logged but not executed. |
| 85 | +func (d *DryRunJobDistributor) RevokeJob(ctx context.Context, in *jobv1.RevokeJobRequest, opts ...grpc.CallOption) (*jobv1.RevokeJobResponse, error) { |
| 86 | + d.lggr.Infow("DryRunJobDistributor.RevokeJob", "in", in) |
| 87 | + return &jobv1.RevokeJobResponse{}, nil |
| 88 | +} |
| 89 | + |
| 90 | +// DeleteJob simulates deleting a job from the Job Distributor without actually executing the deletion. |
| 91 | +// In dry run mode, this returns an empty response indicating the deletion was logged but not executed. |
| 92 | +func (d *DryRunJobDistributor) DeleteJob(ctx context.Context, in *jobv1.DeleteJobRequest, opts ...grpc.CallOption) (*jobv1.DeleteJobResponse, error) { |
| 93 | + d.lggr.Infow("DryRunJobDistributor.DeleteJob", "in", in) |
| 94 | + return &jobv1.DeleteJobResponse{}, nil |
| 95 | +} |
| 96 | + |
| 97 | +// UpdateJob simulates updating an existing job in the Job Distributor without actually executing the update. |
| 98 | +// In dry run mode, this returns an empty response indicating the update was logged but not executed. |
| 99 | +func (d *DryRunJobDistributor) UpdateJob(ctx context.Context, in *jobv1.UpdateJobRequest, opts ...grpc.CallOption) (*jobv1.UpdateJobResponse, error) { |
| 100 | + d.lggr.Infow("DryRunJobDistributor.UpdateJob", "in", in) |
| 101 | + return &jobv1.UpdateJobResponse{}, nil |
| 102 | +} |
| 103 | + |
| 104 | +// DisableNode simulates disabling a node in the Job Distributor without actually executing the operation. |
| 105 | +// In dry run mode, this returns an empty response indicating the node disable operation was logged but not executed. |
| 106 | +func (d *DryRunJobDistributor) DisableNode(ctx context.Context, in *nodev1.DisableNodeRequest, opts ...grpc.CallOption) (*nodev1.DisableNodeResponse, error) { |
| 107 | + d.lggr.Infow("DryRunJobDistributor.DisableNode", "in", in) |
| 108 | + return &nodev1.DisableNodeResponse{}, nil |
| 109 | +} |
| 110 | + |
| 111 | +// EnableNode simulates enabling a node in the Job Distributor without actually executing the operation. |
| 112 | +// In dry run mode, this returns an empty response indicating the node enable operation was logged but not executed. |
| 113 | +func (d *DryRunJobDistributor) EnableNode(ctx context.Context, in *nodev1.EnableNodeRequest, opts ...grpc.CallOption) (*nodev1.EnableNodeResponse, error) { |
| 114 | + d.lggr.Infow("DryRunJobDistributor.EnableNode", "in", in) |
| 115 | + return &nodev1.EnableNodeResponse{}, nil |
| 116 | +} |
| 117 | + |
| 118 | +// GetNode retrieves information about a specific node from the Job Distributor. |
| 119 | +// This operation is forwarded to the real backend since it's a read-only operation. |
| 120 | +func (d *DryRunJobDistributor) GetNode(ctx context.Context, in *nodev1.GetNodeRequest, opts ...grpc.CallOption) (*nodev1.GetNodeResponse, error) { |
| 121 | + d.lggr.Infow("DryRunJobDistributor.GetNode", "in", in) |
| 122 | + return d.realBackend.GetNode(ctx, in) |
| 123 | +} |
| 124 | + |
| 125 | +// ListNodes retrieves a list of all nodes registered with the Job Distributor. |
| 126 | +// This operation is forwarded to the real backend since it's a read-only operation. |
| 127 | +func (d *DryRunJobDistributor) ListNodes(ctx context.Context, in *nodev1.ListNodesRequest, opts ...grpc.CallOption) (*nodev1.ListNodesResponse, error) { |
| 128 | + d.lggr.Infow("DryRunJobDistributor.ListNodes", "in", in) |
| 129 | + return d.realBackend.ListNodes(ctx, in) |
| 130 | +} |
| 131 | + |
| 132 | +// ListNodeChainConfigs retrieves chain configuration information for nodes from the Job Distributor. |
| 133 | +// This operation is forwarded to the real backend since it's a read-only operation. |
| 134 | +func (d *DryRunJobDistributor) ListNodeChainConfigs(ctx context.Context, in *nodev1.ListNodeChainConfigsRequest, opts ...grpc.CallOption) (*nodev1.ListNodeChainConfigsResponse, error) { |
| 135 | + d.lggr.Infow("DryRunJobDistributor.ListNodeChainConfigs", "in", in) |
| 136 | + return d.realBackend.ListNodeChainConfigs(ctx, in) |
| 137 | +} |
| 138 | + |
| 139 | +// RegisterNode simulates registering a new node with the Job Distributor without actually executing the registration. |
| 140 | +// In dry run mode, this returns an empty response indicating the node registration was logged but not executed. |
| 141 | +func (d *DryRunJobDistributor) RegisterNode(ctx context.Context, in *nodev1.RegisterNodeRequest, opts ...grpc.CallOption) (*nodev1.RegisterNodeResponse, error) { |
| 142 | + d.lggr.Infow("DryRunJobDistributor.RegisterNode", "in", in) |
| 143 | + return &nodev1.RegisterNodeResponse{}, nil |
| 144 | +} |
| 145 | + |
| 146 | +// UpdateNode simulates updating an existing node in the Job Distributor without actually executing the update. |
| 147 | +// In dry run mode, this returns an empty response indicating the node update was logged but not executed. |
| 148 | +func (d *DryRunJobDistributor) UpdateNode(ctx context.Context, in *nodev1.UpdateNodeRequest, opts ...grpc.CallOption) (*nodev1.UpdateNodeResponse, error) { |
| 149 | + d.lggr.Infow("DryRunJobDistributor.UpdateNode", "in", in) |
| 150 | + return &nodev1.UpdateNodeResponse{}, nil |
| 151 | +} |
| 152 | + |
| 153 | +// GetKeypair retrieves a specific CSA keypair from the Job Distributor. |
| 154 | +// This operation is forwarded to the real backend since it's a read-only operation. |
| 155 | +func (d *DryRunJobDistributor) GetKeypair(ctx context.Context, in *csav1.GetKeypairRequest, opts ...grpc.CallOption) (*csav1.GetKeypairResponse, error) { |
| 156 | + d.lggr.Infow("DryRunJobDistributor.GetKeypair", "in", in) |
| 157 | + return d.realBackend.GetKeypair(ctx, in) |
| 158 | +} |
| 159 | + |
| 160 | +// ListKeypairs retrieves a list of all CSA keypairs from the Job Distributor. |
| 161 | +// This operation is forwarded to the real backend since it's a read-only operation. |
| 162 | +func (d *DryRunJobDistributor) ListKeypairs(ctx context.Context, in *csav1.ListKeypairsRequest, opts ...grpc.CallOption) (*csav1.ListKeypairsResponse, error) { |
| 163 | + d.lggr.Infow("DryRunJobDistributor.ListKeypairs", "in", in) |
| 164 | + return d.realBackend.ListKeypairs(ctx, in) |
| 165 | +} |
0 commit comments