github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/model/v1beta1/apiversion_convert_v1alpha1.go (about) 1 package v1beta1 2 3 import ( 4 "github.com/filecoin-project/bacalhau/pkg/model/v1alpha1" 5 ) 6 7 func ConvertV1alpha1StorageSpec(data v1alpha1.StorageSpec) StorageSpec { 8 return StorageSpec{ 9 StorageSource: StorageSourceType(data.StorageSource), 10 Name: data.Name, 11 CID: data.CID, 12 URL: data.URL, 13 Path: data.Path, 14 Metadata: data.Metadata, 15 } 16 } 17 18 func ConvertV1alpha1StorageSpecs(data []v1alpha1.StorageSpec) []StorageSpec { 19 if data == nil { 20 return nil 21 } 22 ret := []StorageSpec{} 23 for _, spec := range data { 24 ret = append(ret, ConvertV1alpha1StorageSpec(spec)) 25 } 26 return ret 27 } 28 29 func ConvertV1alpha1Spec( 30 data v1alpha1.Spec, 31 executionPlan v1alpha1.JobExecutionPlan, 32 deal v1alpha1.Deal, 33 ) Spec { 34 return Spec{ 35 Engine: Engine(data.Engine), 36 Verifier: Verifier(data.Verifier), 37 Publisher: Publisher(data.Publisher), 38 Docker: JobSpecDocker(data.Docker), 39 Language: JobSpecLanguage{ 40 Language: data.Language.Language, 41 LanguageVersion: data.Language.LanguageVersion, 42 Deterministic: data.Language.Deterministic, 43 Context: ConvertV1alpha1StorageSpec(data.Language.Context), 44 Command: data.Language.Command, 45 ProgramPath: data.Language.ProgramPath, 46 RequirementsPath: data.Language.RequirementsPath, 47 }, 48 Wasm: JobSpecWasm{ 49 EntryPoint: data.Wasm.EntryPoint, 50 Parameters: data.Wasm.Parameters, 51 EnvironmentVariables: data.Wasm.EnvironmentVariables, 52 ImportModules: ConvertV1alpha1StorageSpecs(data.Wasm.ImportModules), 53 }, 54 Resources: ResourceUsageConfig(data.Resources), 55 Timeout: data.Timeout, 56 Inputs: ConvertV1alpha1StorageSpecs(data.Inputs), 57 Outputs: ConvertV1alpha1StorageSpecs(data.Outputs), 58 Contexts: ConvertV1alpha1StorageSpecs(data.Contexts), 59 Annotations: data.Annotations, 60 Sharding: JobShardingConfig(data.Sharding), 61 DoNotTrack: data.DoNotTrack, 62 ExecutionPlan: JobExecutionPlan(executionPlan), 63 Deal: Deal(deal), 64 } 65 } 66 67 func ConvertV1alpha1RunCommandResult(data *v1alpha1.RunCommandResult) *RunCommandResult { 68 var runOutput *RunCommandResult 69 if data != nil { 70 converted := RunCommandResult(*data) 71 runOutput = &converted 72 } 73 return runOutput 74 } 75 76 func ConvertV1alpha1ShardState(data v1alpha1.JobShardState) JobShardState { 77 return JobShardState{ 78 NodeID: data.NodeID, 79 ShardIndex: data.ShardIndex, 80 State: JobStateType(data.State), 81 Status: data.Status, 82 VerificationProposal: data.VerificationProposal, 83 VerificationResult: VerificationResult(data.VerificationResult), 84 PublishedResult: ConvertV1alpha1StorageSpec(data.PublishedResult), 85 RunOutput: ConvertV1alpha1RunCommandResult(data.RunOutput), 86 } 87 } 88 89 func ConvertV1alpha1JobState(data v1alpha1.JobState) JobState { 90 nodes := map[string]JobNodeState{} 91 for nodeID, nodeData := range data.Nodes { 92 shards := map[int]JobShardState{} 93 for shardID, shardData := range nodeData.Shards { 94 shards[shardID] = ConvertV1alpha1ShardState(shardData) 95 } 96 nodes[nodeID] = JobNodeState{ 97 Shards: shards, 98 } 99 } 100 return JobState{ 101 Nodes: nodes, 102 } 103 } 104 105 func ConvertV1alpha1JobEvent(event v1alpha1.JobEvent) JobEvent { 106 return JobEvent{ 107 APIVersion: APIVersionLatest().String(), 108 JobID: event.JobID, 109 ShardIndex: event.ShardIndex, 110 ClientID: event.ClientID, 111 SourceNodeID: event.SourceNodeID, 112 TargetNodeID: event.TargetNodeID, 113 EventName: JobEventType(event.EventName), 114 Spec: ConvertV1alpha1Spec(event.Spec, event.JobExecutionPlan, event.Deal), 115 JobExecutionPlan: JobExecutionPlan(event.JobExecutionPlan), 116 Deal: Deal(event.Deal), 117 Status: event.Status, 118 VerificationProposal: event.VerificationProposal, 119 VerificationResult: VerificationResult(event.VerificationResult), 120 PublishedResult: ConvertV1alpha1StorageSpec(event.PublishedResult), 121 EventTime: event.EventTime, 122 SenderPublicKey: PublicKey(event.SenderPublicKey), 123 RunOutput: ConvertV1alpha1RunCommandResult(event.RunOutput), 124 } 125 } 126 127 func ConvertV1alpha1JobEvents(events []v1alpha1.JobEvent) []JobEvent { 128 if events == nil { 129 return nil 130 } 131 ret := []JobEvent{} 132 for _, event := range events { 133 ret = append(ret, ConvertV1alpha1JobEvent(event)) 134 } 135 return ret 136 } 137 138 func ConvertV1alpha1JobLocalEvent(event v1alpha1.JobLocalEvent) JobLocalEvent { 139 return JobLocalEvent{ 140 EventName: JobLocalEventType(event.EventName), 141 JobID: event.JobID, 142 ShardIndex: event.ShardIndex, 143 TargetNodeID: event.TargetNodeID, 144 } 145 } 146 147 func ConvertV1alpha1JobLocalEvents(events []v1alpha1.JobLocalEvent) []JobLocalEvent { 148 if events == nil { 149 return nil 150 } 151 ret := []JobLocalEvent{} 152 for _, event := range events { 153 ret = append(ret, ConvertV1alpha1JobLocalEvent(event)) 154 } 155 return ret 156 } 157 158 func ConvertV1alpha1Job(data v1alpha1.Job) Job { 159 return Job{ 160 APIVersion: APIVersionLatest().String(), 161 Metadata: Metadata{ 162 ID: data.ID, 163 CreatedAt: data.CreatedAt, 164 ClientID: data.ClientID, 165 }, 166 Spec: ConvertV1alpha1Spec(data.Spec, data.ExecutionPlan, data.Deal), 167 Status: JobStatus{ 168 State: ConvertV1alpha1JobState(data.State), 169 Events: ConvertV1alpha1JobEvents(data.Events), 170 LocalEvents: ConvertV1alpha1JobLocalEvents(data.LocalEvents), 171 Requester: JobRequester{ 172 RequesterNodeID: data.RequesterNodeID, 173 RequesterPublicKey: PublicKey(data.RequesterPublicKey), 174 }, 175 }, 176 } 177 }