|
| 1 | +package proto_tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "path/filepath" |
| 6 | + "time" |
| 7 | + |
| 8 | + "github.com/golang/glog" |
| 9 | + pb "github.com/kubeflow/pipelines/backend/api/v2beta1/go_client" |
| 10 | + "github.com/kubeflow/pipelines/backend/src/apiserver/server" |
| 11 | + "google.golang.org/genproto/googleapis/rpc/status" |
| 12 | + "google.golang.org/protobuf/types/known/structpb" |
| 13 | + "google.golang.org/protobuf/types/known/timestamppb" |
| 14 | +) |
| 15 | + |
| 16 | +const mockPipelineID = "9b187b86-7c0a-42ae-a0bc-2a746b6eb7a3" |
| 17 | +const mockPipelineVersionID = "e15dc3ec-b45e-4cc7-bb07-e76b5dbce99a" |
| 18 | +const pipelineSpecYamlPath = "pipelinespec.yaml" |
| 19 | + |
| 20 | +func mockPipelineSpec() *structpb.Struct { |
| 21 | + yamlContent, err := os.ReadFile(filepath.Join("testdata", pipelineSpecYamlPath)) |
| 22 | + if err != nil { |
| 23 | + glog.Fatal(err) |
| 24 | + } |
| 25 | + spec, err := server.YamlStringToPipelineSpecStruct(string(yamlContent)) |
| 26 | + if err != nil { |
| 27 | + glog.Fatal(err) |
| 28 | + } |
| 29 | + return spec |
| 30 | +} |
| 31 | + |
| 32 | +func fixedTimestamp() *timestamppb.Timestamp { |
| 33 | + return timestamppb.New(time.Date(2024, 1, 1, 12, 0, 0, 0, time.UTC)) |
| 34 | +} |
| 35 | + |
| 36 | +var completedRun = &pb.Run{ |
| 37 | + RunId: "completed-run-123", |
| 38 | + DisplayName: "Production Pipeline Run", |
| 39 | + ExperimentId: "exp-456", |
| 40 | + StorageState: pb.Run_AVAILABLE, |
| 41 | + Description: "Production pipeline execution for data processing", |
| 42 | + ServiceAccount: "sa1", |
| 43 | + CreatedAt: fixedTimestamp(), |
| 44 | + ScheduledAt: fixedTimestamp(), |
| 45 | + FinishedAt: fixedTimestamp(), |
| 46 | + RecurringRunId: "recurring-schedule-001", |
| 47 | + State: pb.RuntimeState_SUCCEEDED, |
| 48 | + PipelineSource: &pb.Run_PipelineVersionReference{ |
| 49 | + PipelineVersionReference: &pb.PipelineVersionReference{ |
| 50 | + PipelineId: mockPipelineID, |
| 51 | + PipelineVersionId: mockPipelineVersionID, |
| 52 | + }, |
| 53 | + }, |
| 54 | + RuntimeConfig: &pb.RuntimeConfig{ |
| 55 | + Parameters: map[string]*structpb.Value{ |
| 56 | + "batch_size": structpb.NewNumberValue(1000), |
| 57 | + "learning_rate": structpb.NewStringValue("foo"), |
| 58 | + }, |
| 59 | + }, |
| 60 | +} |
| 61 | + |
| 62 | +var completedRunWithPipelineSpec = &pb.Run{ |
| 63 | + RunId: "completed-run-123", |
| 64 | + DisplayName: "Production Pipeline Run", |
| 65 | + ExperimentId: "exp-456", |
| 66 | + StorageState: pb.Run_AVAILABLE, |
| 67 | + Description: "Production pipeline execution for data processing", |
| 68 | + ServiceAccount: "sa1", |
| 69 | + CreatedAt: fixedTimestamp(), |
| 70 | + ScheduledAt: fixedTimestamp(), |
| 71 | + FinishedAt: fixedTimestamp(), |
| 72 | + RecurringRunId: "recurring-schedule-001", |
| 73 | + State: pb.RuntimeState_SUCCEEDED, |
| 74 | + PipelineSource: &pb.Run_PipelineSpec{ |
| 75 | + PipelineSpec: mockPipelineSpec(), |
| 76 | + }, |
| 77 | + RuntimeConfig: &pb.RuntimeConfig{ |
| 78 | + Parameters: map[string]*structpb.Value{ |
| 79 | + "batch_size": structpb.NewNumberValue(1000), |
| 80 | + "learning_rate": structpb.NewStringValue("foo"), |
| 81 | + }, |
| 82 | + }, |
| 83 | +} |
| 84 | + |
| 85 | +var failedRun = &pb.Run{ |
| 86 | + RunId: "failed-run-456", |
| 87 | + DisplayName: "Data Processing Pipeline", |
| 88 | + ExperimentId: "exp-789", |
| 89 | + StorageState: pb.Run_AVAILABLE, |
| 90 | + Description: "Failed attempt to process customer data", |
| 91 | + ServiceAccount: "sa2", |
| 92 | + CreatedAt: fixedTimestamp(), |
| 93 | + ScheduledAt: fixedTimestamp(), |
| 94 | + FinishedAt: fixedTimestamp(), |
| 95 | + State: pb.RuntimeState_FAILED, |
| 96 | + Error: &status.Status{ |
| 97 | + Code: 1, |
| 98 | + Message: "This was a Failed Run.", |
| 99 | + }, |
| 100 | +} |
| 101 | + |
| 102 | +var pipeline = &pb.Pipeline{ |
| 103 | + PipelineId: mockPipelineID, |
| 104 | + DisplayName: "Production Data Processing Pipeline", |
| 105 | + Name: "pipeline1", |
| 106 | + Description: "Pipeline for processing and analyzing production data", |
| 107 | + CreatedAt: fixedTimestamp(), |
| 108 | + Namespace: "namespace1", |
| 109 | + Error: &status.Status{ |
| 110 | + Code: 0, |
| 111 | + Message: "This a successful pipeline.", |
| 112 | + }, |
| 113 | +} |
| 114 | + |
| 115 | +var pipelineVersion = &pb.PipelineVersion{ |
| 116 | + PipelineVersionId: mockPipelineVersionID, |
| 117 | + PipelineId: mockPipelineID, |
| 118 | + DisplayName: "v1.0.0 Production Data Processing Pipeline", |
| 119 | + Name: "pipelineversion1", |
| 120 | + Description: "First stable version of the production data processing pipeline", |
| 121 | + CreatedAt: fixedTimestamp(), |
| 122 | + PipelineSpec: mockPipelineSpec(), |
| 123 | + PackageUrl: &pb.Url{PipelineUrl: "gs://my-bucket/pipelines/pipeline1-v1.0.0.yaml"}, |
| 124 | + CodeSourceUrl: "https://github.com/org/repo/pipeline1/tree/v1.0.0", |
| 125 | + Error: &status.Status{ |
| 126 | + Code: 0, |
| 127 | + Message: "This is a successful pipeline version.", |
| 128 | + }, |
| 129 | +} |
| 130 | + |
| 131 | +var experiment = &pb.Experiment{ |
| 132 | + ExperimentId: "exp-456", |
| 133 | + DisplayName: "Production Data Processing Experiment", |
| 134 | + Description: "Experiment for testing production data processing pipeline", |
| 135 | + CreatedAt: fixedTimestamp(), |
| 136 | + Namespace: "namespace1", |
| 137 | + StorageState: pb.Experiment_AVAILABLE, |
| 138 | + LastRunCreatedAt: fixedTimestamp(), |
| 139 | +} |
0 commit comments