github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/runtime.go (about) 1 package model 2 3 import ( 4 "time" 5 6 "github.com/kyma-incubator/compass/components/director/pkg/pagination" 7 ) 8 9 // Runtime missing godoc 10 type Runtime struct { 11 ID string 12 Name string 13 Description *string 14 Status *RuntimeStatus 15 CreationTimestamp time.Time 16 ApplicationNamespace *string 17 } 18 19 // GetID missing godoc 20 func (runtime *Runtime) GetID() string { 21 return runtime.ID 22 } 23 24 // RuntimeStatus missing godoc 25 type RuntimeStatus struct { 26 Condition RuntimeStatusCondition 27 Timestamp time.Time 28 } 29 30 // RuntimeStatusCondition missing godoc 31 type RuntimeStatusCondition string 32 33 const ( 34 // RuntimeStatusConditionInitial missing godoc 35 RuntimeStatusConditionInitial RuntimeStatusCondition = "INITIAL" 36 // RuntimeStatusConditionProvisioning missing godoc 37 RuntimeStatusConditionProvisioning RuntimeStatusCondition = "PROVISIONING" 38 // RuntimeStatusConditionConnected missing godoc 39 RuntimeStatusConditionConnected RuntimeStatusCondition = "CONNECTED" 40 // RuntimeStatusConditionFailed missing godoc 41 RuntimeStatusConditionFailed RuntimeStatusCondition = "FAILED" 42 ) 43 44 // RuntimeRegisterInput missing godoc 45 type RuntimeRegisterInput struct { 46 Name string 47 Description *string 48 Labels map[string]interface{} 49 Webhooks []*WebhookInput 50 StatusCondition *RuntimeStatusCondition 51 ApplicationNamespace *string 52 } 53 54 // ToRuntime missing godoc 55 func (i *RuntimeRegisterInput) ToRuntime(id string, creationTimestamp, conditionTimestamp time.Time) *Runtime { 56 if i == nil { 57 return nil 58 } 59 60 return &Runtime{ 61 ID: id, 62 Name: i.Name, 63 Description: i.Description, 64 Status: &RuntimeStatus{ 65 Condition: getRuntimeStatusConditionOrDefault(i.StatusCondition), 66 Timestamp: conditionTimestamp, 67 }, 68 CreationTimestamp: creationTimestamp, 69 ApplicationNamespace: i.ApplicationNamespace, 70 } 71 } 72 73 // RuntimeUpdateInput missing godoc 74 type RuntimeUpdateInput struct { 75 Name string 76 Description *string 77 Labels map[string]interface{} 78 StatusCondition *RuntimeStatusCondition 79 ApplicationNamespace *string 80 } 81 82 // SetFromUpdateInput sets fields to model Runtime from RuntimeUpdateInput 83 func (runtime *Runtime) SetFromUpdateInput(update RuntimeUpdateInput, id string, creationTimestamp, conditionTimestamp time.Time) { 84 if runtime.Status == nil { 85 runtime.Status = &RuntimeStatus{} 86 } 87 88 runtime.ID = id 89 runtime.Name = update.Name 90 91 runtime.Status.Condition = getRuntimeStatusConditionOrDefault(update.StatusCondition) 92 runtime.Status.Timestamp = conditionTimestamp 93 runtime.CreationTimestamp = creationTimestamp 94 95 if update.Description != nil { 96 runtime.Description = update.Description 97 } 98 99 if update.ApplicationNamespace != nil { 100 runtime.ApplicationNamespace = update.ApplicationNamespace 101 } 102 } 103 104 func getRuntimeStatusConditionOrDefault(in *RuntimeStatusCondition) RuntimeStatusCondition { 105 statusCondition := RuntimeStatusConditionInitial 106 if in != nil { 107 statusCondition = *in 108 } 109 110 return statusCondition 111 } 112 113 // RuntimePage missing godoc 114 type RuntimePage struct { 115 Data []*Runtime 116 PageInfo *pagination.Page 117 TotalCount int 118 }