Files
oc-lib/tools/enums.go
2026-02-24 14:08:21 +01:00

201 lines
3.8 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tools
import (
"strings"
"cloud.o-forge.io/core/oc-lib/config"
)
type DataType int
// DataType - Enum for the different types of resources in db accessible from the outside
const (
INVALID DataType = iota
DATA_RESOURCE
PROCESSING_RESOURCE
STORAGE_RESOURCE
COMPUTE_RESOURCE
WORKFLOW_RESOURCE
WORKFLOW
WORKFLOW_EXECUTION
WORKSPACE
PEER
COLLABORATIVE_AREA
RULE
BOOKING
WORKFLOW_HISTORY
WORKSPACE_HISTORY
ORDER
PURCHASE_RESOURCE
LIVE_DATACENTER
LIVE_STORAGE
BILL
NATIVE_TOOL
)
var NOAPI = func() string {
return ""
}
var CATALOGAPI = func() string {
return config.GetConfig().InternalCatalogAPI
}
var SHAREDAPI = func() string {
return config.GetConfig().InternalSharedAPI
}
var WORKFLOWAPI = func() string {
return config.GetConfig().InternalWorkflowAPI
}
var WORKSPACEAPI = func() string {
return config.GetConfig().InternalWorkspaceAPI
}
var PEERSAPI = func() string {
return config.GetConfig().InternalPeerAPI
}
var DATACENTERAPI = func() string {
return config.GetConfig().InternalDatacenterAPI
}
var PURCHASEAPI = func() string {
return config.GetConfig().InternalCatalogAPI + "/purchase"
}
// Bind the standard API name to the data type
var InnerDefaultAPI = [...]func() string{
NOAPI,
CATALOGAPI,
CATALOGAPI,
CATALOGAPI,
CATALOGAPI,
CATALOGAPI,
WORKFLOWAPI,
NOAPI,
WORKSPACEAPI,
PEERSAPI,
SHAREDAPI,
SHAREDAPI,
DATACENTERAPI,
NOAPI,
NOAPI,
NOAPI,
PURCHASEAPI,
DATACENTERAPI,
DATACENTERAPI,
NOAPI,
CATALOGAPI,
}
// Bind the standard data name to the data type
var Str = [...]string{
"invalid",
"data_resource",
"processing_resource",
"storage_resource",
"compute_resource",
"workflow_resource",
"workflow",
"workflow_execution",
"workspace",
"peer",
"collaborative_area",
"rule",
"booking",
"workflow_history",
"workspace_history",
"order",
"purchase_resource",
"live_datacenter",
"live_storage",
"bill",
"native_tool",
}
func FromString(comp string) int {
for i, str := range Str {
if str == comp {
return i
}
}
return -1
}
func FromInt(i int) string {
return Str[i]
}
func (d DataType) InnerAPI() string { // API - Returns the API name of the data type
return InnerDefaultAPI[d]()
}
func (d DataType) String() string { // String - Returns the string name of the data type
if d < 0 {
return ""
}
return Str[d]
}
// EnumIndex - Creating common behavior-give the type a EnumIndex functio
func (d DataType) EnumIndex() int {
return int(d)
}
func DataTypeList() []DataType {
return []DataType{DATA_RESOURCE, PROCESSING_RESOURCE, STORAGE_RESOURCE, COMPUTE_RESOURCE, WORKFLOW_RESOURCE,
WORKFLOW, WORKFLOW_EXECUTION, WORKSPACE, PEER, COLLABORATIVE_AREA, RULE, BOOKING, WORKFLOW_HISTORY, WORKSPACE_HISTORY,
ORDER, PURCHASE_RESOURCE,
LIVE_DATACENTER, LIVE_STORAGE, BILL, NATIVE_TOOL}
}
type PropalgationMessage struct {
DataType int `json:"datatype"`
Action PubSubAction `json:"action"`
Payload []byte `json:"payload"`
}
type PubSubAction int
const (
PB_SEARCH PubSubAction = iota
PB_SEARCH_RESPONSE
PB_CREATE
PB_UPDATE
PB_DELETE
PB_PLANNER
PB_CLOSE_PLANNER
PB_CONSIDERS
PB_ADMIRALTY_CONFIG
PB_MINIO_CONFIG
NONE
)
func GetActionString(ss string) PubSubAction {
switch ss {
case "search":
return PB_SEARCH
case "create":
return PB_CREATE
case "update":
return PB_UPDATE
case "delete":
return PB_DELETE
case "search_response":
return PB_SEARCH_RESPONSE
case "planner":
return PB_PLANNER
case "close_planner":
return PB_CLOSE_PLANNER
case "considers":
return PB_CONSIDERS
case "admiralty_config":
return PB_ADMIRALTY_CONFIG
case "minio_config":
return PB_MINIO_CONFIG
default:
return NONE
}
}
var path = []string{"search", "search_response", "create", "update", "delete", "planner", "close_planner", "considers", "admiralty_config", "minio_config"}
func (m PubSubAction) String() string {
return strings.ToUpper(path[m])
}