Refactor Oc-Sheduler
This commit is contained in:
101
infrastructure/scheduling_resources/objects.go
Normal file
101
infrastructure/scheduling_resources/objects.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package scheduling_resources
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/purchase_resource"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type SchedulerObject interface {
|
||||
utils.DBObject
|
||||
SetIsDraft(bool)
|
||||
GetKey() string
|
||||
SetSchedulerPeerID(peerID string)
|
||||
SetExecutionsID(ei string)
|
||||
GetDestPeer() string
|
||||
GetPeerSession() string
|
||||
GetExecutionsId() string
|
||||
GetExecutionId() string
|
||||
}
|
||||
|
||||
type ScheduledPurchase struct {
|
||||
purchase_resource.PurchaseResource
|
||||
}
|
||||
|
||||
type ScheduledBooking struct {
|
||||
booking.Booking
|
||||
}
|
||||
|
||||
func FromSchedulerDBObject(dt tools.DataType, obj SchedulerObject) utils.DBObject {
|
||||
switch dt {
|
||||
case tools.BOOKING:
|
||||
o := &booking.Booking{}
|
||||
b, _ := json.Marshal(obj)
|
||||
json.Unmarshal(b, &o)
|
||||
return o
|
||||
case tools.PURCHASE_RESOURCE:
|
||||
o := &purchase_resource.PurchaseResource{}
|
||||
b, _ := json.Marshal(obj)
|
||||
json.Unmarshal(b, &o)
|
||||
return o
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FromSchedulerObject(dt tools.DataType, obj SchedulerObject) utils.ShallowDBObject {
|
||||
switch dt {
|
||||
case tools.BOOKING:
|
||||
o := &booking.Booking{}
|
||||
b, _ := json.Marshal(obj)
|
||||
json.Unmarshal(b, &o)
|
||||
return o
|
||||
case tools.PURCHASE_RESOURCE:
|
||||
o := &purchase_resource.PurchaseResource{}
|
||||
b, _ := json.Marshal(obj)
|
||||
json.Unmarshal(b, &o)
|
||||
return o
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ToSchedulerObject(dt tools.DataType, obj utils.ShallowDBObject) SchedulerObject {
|
||||
switch dt {
|
||||
case tools.BOOKING:
|
||||
o := &ScheduledBooking{}
|
||||
b, _ := json.Marshal(obj)
|
||||
json.Unmarshal(b, &o)
|
||||
return o
|
||||
case tools.PURCHASE_RESOURCE:
|
||||
o := &ScheduledPurchase{}
|
||||
b, _ := json.Marshal(obj)
|
||||
json.Unmarshal(b, &o)
|
||||
return o
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *ScheduledBooking) GetExecutionId() string { return b.ExecutionID }
|
||||
func (b *ScheduledPurchase) GetExecutionId() string { return b.ExecutionID }
|
||||
func (b *ScheduledBooking) GetExecutionsId() string { return b.ExecutionsID }
|
||||
func (b *ScheduledPurchase) GetExecutionsId() string { return b.ExecutionsID }
|
||||
func (b *ScheduledBooking) GetPeerSession() string { return b.SchedulerPeerID }
|
||||
func (b *ScheduledPurchase) GetPeerSession() string { return b.SchedulerPeerID }
|
||||
func (b *ScheduledBooking) GetDestPeer() string { return b.DestPeerID }
|
||||
func (b *ScheduledPurchase) GetDestPeer() string { return b.DestPeerID }
|
||||
|
||||
func (b *ScheduledBooking) GetKey() string {
|
||||
return b.ResourceID + "/" + b.InstanceID + "/" + tools.BOOKING.String()
|
||||
}
|
||||
func (b *ScheduledPurchase) GetKey() string {
|
||||
return b.ResourceID + "/" + b.InstanceID + "/" + tools.PURCHASE_RESOURCE.String()
|
||||
}
|
||||
|
||||
func (b *ScheduledBooking) SetIsDraft(ok bool) { b.IsDraft = ok }
|
||||
func (b *ScheduledPurchase) SetIsDraft(ok bool) { b.IsDraft = ok }
|
||||
func (b *ScheduledBooking) SetSchedulerPeerID(p string) { b.SchedulerPeerID = p }
|
||||
func (b *ScheduledPurchase) SetSchedulerPeerID(p string) { b.SchedulerPeerID = p }
|
||||
func (b *ScheduledBooking) SetExecutionsID(ei string) { b.ExecutionsID = ei }
|
||||
func (b *ScheduledPurchase) SetExecutionsID(ei string) { b.ExecutionsID = ei }
|
||||
Reference in New Issue
Block a user