Files
oc-lib/tools/enums.go

248 lines
5.1 KiB
Go
Raw Normal View History

2024-10-02 10:45:52 +02:00
package tools
2024-07-19 10:54:58 +02:00
2026-02-12 13:20:06 +01:00
import (
"strings"
"cloud.o-forge.io/core/oc-lib/config"
)
2026-01-28 16:22:42 +01:00
2024-07-19 10:54:58 +02:00
type DataType int
// DataType - Enum for the different types of resources in db accessible from the outside
2024-07-19 10:54:58 +02:00
const (
INVALID DataType = iota
DATA_RESOURCE
PROCESSING_RESOURCE
STORAGE_RESOURCE
2024-11-07 11:05:24 +01:00
COMPUTE_RESOURCE
2024-07-19 10:54:58 +02:00
WORKFLOW_RESOURCE
WORKFLOW
2024-07-23 16:14:46 +02:00
WORKFLOW_EXECUTION
2024-07-25 09:28:55 +02:00
WORKSPACE
2024-08-12 12:03:58 +02:00
PEER
2024-09-27 13:23:24 +02:00
COLLABORATIVE_AREA
2024-08-12 12:03:58 +02:00
RULE
2024-08-12 14:18:13 +02:00
BOOKING
2024-10-02 11:35:22 +02:00
WORKFLOW_HISTORY
WORKSPACE_HISTORY
ORDER
2025-02-10 09:58:46 +01:00
PURCHASE_RESOURCE
2025-06-24 11:29:04 +02:00
LIVE_DATACENTER
LIVE_STORAGE
2025-06-20 07:51:32 +02:00
BILL
2026-01-13 16:04:31 +01:00
NATIVE_TOOL
EXECUTION_VERIFICATION
2026-03-25 10:20:16 +01:00
ALLOWED_IMAGE
2024-07-19 10:54:58 +02:00
)
2026-02-12 13:20:06 +01:00
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
}
2026-03-12 15:11:50 +01:00
var SCHEDULERAPI = func() string {
return config.GetConfig().InternalSchedulerAPI
}
2026-02-12 13:20:06 +01:00
var PURCHASEAPI = func() string {
return config.GetConfig().InternalCatalogAPI + "/purchase"
}
2024-10-02 10:18:33 +02:00
// Bind the standard API name to the data type
2026-02-12 13:39:52 +01:00
var InnerDefaultAPI = [...]func() string{
2024-10-02 10:18:33 +02:00
NOAPI,
CATALOGAPI,
CATALOGAPI,
CATALOGAPI,
CATALOGAPI,
CATALOGAPI,
WORKFLOWAPI,
NOAPI,
WORKSPACEAPI,
PEERSAPI,
SHAREDAPI,
SHAREDAPI,
2026-03-12 15:11:50 +01:00
SCHEDULERAPI,
2024-10-02 11:35:22 +02:00
NOAPI,
NOAPI,
NOAPI,
2025-06-20 08:10:52 +02:00
PURCHASEAPI,
2025-06-17 14:21:37 +02:00
DATACENTERAPI,
2025-06-24 11:29:04 +02:00
DATACENTERAPI,
2025-06-20 07:51:32 +02:00
NOAPI,
2026-01-13 16:04:31 +01:00
CATALOGAPI,
2026-03-12 15:11:50 +01:00
SCHEDULERAPI,
2026-03-25 10:20:16 +01:00
DATACENTERAPI,
2024-08-21 08:54:29 +02:00
}
// Bind the standard data name to the data type
2024-07-26 14:15:55 +02:00
var Str = [...]string{
2024-07-19 10:54:58 +02:00
"invalid",
"data_resource",
"processing_resource",
"storage_resource",
2024-11-07 11:05:24 +01:00
"compute_resource",
2024-07-19 10:54:58 +02:00
"workflow_resource",
"workflow",
2024-07-24 08:58:40 +02:00
"workflow_execution",
2024-07-25 09:28:55 +02:00
"workspace",
2024-08-12 12:03:58 +02:00
"peer",
2024-11-20 10:39:20 +01:00
"collaborative_area",
2024-08-12 12:03:58 +02:00
"rule",
2024-08-12 14:18:13 +02:00
"booking",
2024-10-02 11:35:22 +02:00
"workflow_history",
"workspace_history",
"order",
2025-02-10 09:58:46 +01:00
"purchase_resource",
2025-06-24 11:29:04 +02:00
"live_datacenter",
"live_storage",
2025-06-20 07:51:32 +02:00
"bill",
2026-01-13 16:04:31 +01:00
"native_tool",
"execution_verification",
2026-03-25 10:20:16 +01:00
"allowed_image",
2024-07-19 10:54:58 +02:00
}
2026-02-18 12:24:19 +01:00
func FromString(comp string) int {
for i, str := range Str {
if str == comp {
return i
}
}
return -1
}
2024-07-19 10:54:58 +02:00
func FromInt(i int) string {
2024-07-26 14:15:55 +02:00
return Str[i]
2024-07-19 10:54:58 +02:00
}
2026-02-12 13:39:52 +01:00
func (d DataType) InnerAPI() string { // API - Returns the API name of the data type
return InnerDefaultAPI[d]()
2024-08-21 08:54:29 +02:00
}
func (d DataType) String() string { // String - Returns the string name of the data type
2026-02-03 08:44:47 +01:00
if d < 0 {
return ""
}
2024-07-26 14:15:55 +02:00
return Str[d]
2024-07-19 10:54:58 +02:00
}
// EnumIndex - Creating common behavior-give the type a EnumIndex functio
func (d DataType) EnumIndex() int {
return int(d)
}
2025-01-17 10:56:45 +01:00
func DataTypeList() []DataType {
2025-06-20 07:51:32 +02:00
return []DataType{DATA_RESOURCE, PROCESSING_RESOURCE, STORAGE_RESOURCE, COMPUTE_RESOURCE, WORKFLOW_RESOURCE,
2026-01-22 13:58:21 +01:00
WORKFLOW, WORKFLOW_EXECUTION, WORKSPACE, PEER, COLLABORATIVE_AREA, RULE, BOOKING, WORKFLOW_HISTORY, WORKSPACE_HISTORY,
2026-02-24 13:00:19 +01:00
ORDER, PURCHASE_RESOURCE,
2026-03-30 10:21:09 +02:00
LIVE_DATACENTER, LIVE_STORAGE, BILL, NATIVE_TOOL, EXECUTION_VERIFICATION, ALLOWED_IMAGE}
2025-01-17 10:56:45 +01:00
}
2026-01-28 16:22:42 +01:00
2026-01-28 16:44:47 +01:00
type PropalgationMessage struct {
DataType int `json:"datatype"`
Action PubSubAction `json:"action"`
Payload []byte `json:"payload"`
2026-01-28 16:44:47 +01:00
}
2026-01-28 16:22:42 +01:00
type PubSubAction int
const (
PB_SEARCH PubSubAction = iota
2026-02-23 09:25:38 +01:00
PB_SEARCH_RESPONSE
2026-01-28 16:22:42 +01:00
PB_CREATE
PB_UPDATE
PB_DELETE
2026-02-23 09:25:38 +01:00
PB_PLANNER
2026-02-23 09:30:03 +01:00
PB_CLOSE_PLANNER
2026-02-23 17:26:37 +01:00
PB_CONSIDERS
2026-02-24 14:08:21 +01:00
PB_ADMIRALTY_CONFIG
PB_MINIO_CONFIG
2026-03-23 11:53:21 +01:00
PB_PVC_CONFIG
2026-03-12 15:11:50 +01:00
PB_CLOSE_SEARCH
2026-01-28 16:22:42 +01:00
NONE
2026-04-17 09:45:00 +02:00
PB_OBSERVE
PB_OBSERVE_CLOSE
// PB_PROPAGATE is used by oc-discovery to broadcast a peer's online/offline
// state to other oc-discovery nodes in the federation via PROPALGATION_EVENT.
PB_PROPAGATE
2026-01-28 16:22:42 +01:00
)
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
2026-02-23 09:25:38 +01:00
case "search_response":
return PB_SEARCH_RESPONSE
2026-02-23 09:20:00 +01:00
case "planner":
return PB_PLANNER
2026-02-23 09:30:03 +01:00
case "close_planner":
return PB_CLOSE_PLANNER
2026-02-23 17:26:37 +01:00
case "considers":
return PB_CONSIDERS
2026-02-24 14:08:21 +01:00
case "admiralty_config":
return PB_ADMIRALTY_CONFIG
case "minio_config":
return PB_MINIO_CONFIG
2026-03-12 15:11:50 +01:00
case "close_search":
return PB_CLOSE_SEARCH
2026-04-17 09:45:00 +02:00
case "observe":
return PB_OBSERVE
case "observe_close":
return PB_OBSERVE_CLOSE
case "propagate":
return PB_PROPAGATE
2026-01-28 16:22:42 +01:00
default:
return NONE
}
}
2026-04-17 09:45:00 +02:00
// path aligns with PubSubAction iota values for String().
var path = []string{
"search", // 0 PB_SEARCH
"search_response", // 1 PB_SEARCH_RESPONSE
"create", // 2 PB_CREATE
"update", // 3 PB_UPDATE
"delete", // 4 PB_DELETE
"planner", // 5 PB_PLANNER
"close_planner", // 6 PB_CLOSE_PLANNER
"considers", // 7 PB_CONSIDERS
"admiralty_config", // 8 PB_ADMIRALTY_CONFIG
"minio_config", // 9 PB_MINIO_CONFIG
"pvc_config", // 10 PB_PVC_CONFIG
"close_search", // 11 PB_CLOSE_SEARCH
"none", // 12 NONE
"observe", // 13 PB_OBSERVE
"observe_close", // 14 PB_OBSERVE_CLOSE
"propagate", // 15 PB_PROPAGATE
}
2026-01-28 16:22:42 +01:00
func (m PubSubAction) String() string {
2026-04-17 09:45:00 +02:00
if int(m) >= len(path) {
return "unknown"
}
2026-01-28 16:22:42 +01:00
return strings.ToUpper(path[m])
}