simplify path reservation
This commit is contained in:
@@ -73,7 +73,7 @@ func (a *API) GetState() (State, int, error) {
|
||||
// CheckRemotePeer checks the state of a remote peer
|
||||
func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
|
||||
// Check if the database is up
|
||||
caller := NewHTTPCaller(map[string]map[METHOD]string{}) // Create a new http caller
|
||||
caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
|
||||
var resp APIStatusResponse
|
||||
b, err := caller.CallPost(url, "/status", map[string]interface{}{}) // Call the status endpoint of the peer
|
||||
if err != nil {
|
||||
@@ -94,7 +94,7 @@ func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
|
||||
func (a *API) CheckRemoteAPIs(urls map[string]string) (State, map[string]string, error) {
|
||||
// Check if the database is up
|
||||
new := map[string]string{}
|
||||
caller := NewHTTPCaller(map[string]map[METHOD]string{}) // Create a new http caller
|
||||
caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
|
||||
code := 0
|
||||
e := ""
|
||||
state := ALIVE
|
||||
|
82
tools/enums.go
Normal file
82
tools/enums.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package tools
|
||||
|
||||
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
|
||||
DATACENTER_RESOURCE
|
||||
WORKFLOW_RESOURCE
|
||||
WORKFLOW
|
||||
WORKFLOW_EXECUTION
|
||||
WORKSPACE
|
||||
RESOURCE_MODEL
|
||||
PEER
|
||||
COLLABORATIVE_AREA
|
||||
RULE
|
||||
BOOKING
|
||||
)
|
||||
|
||||
var NOAPI = ""
|
||||
var CATALOGAPI = "oc-catalog"
|
||||
var SHAREDAPI = "oc-shared"
|
||||
var WORKFLOWAPI = "oc-workflow"
|
||||
var WORKSPACEAPI = "oc-workspace"
|
||||
var PEERSAPI = "oc-peers"
|
||||
var DATACENTERAPI = "oc-datacenter"
|
||||
|
||||
// Bind the standard API name to the data type
|
||||
var DefaultAPI = [...]string{
|
||||
NOAPI,
|
||||
CATALOGAPI,
|
||||
CATALOGAPI,
|
||||
CATALOGAPI,
|
||||
CATALOGAPI,
|
||||
CATALOGAPI,
|
||||
WORKFLOWAPI,
|
||||
NOAPI,
|
||||
WORKSPACEAPI,
|
||||
NOAPI,
|
||||
PEERSAPI,
|
||||
SHAREDAPI,
|
||||
SHAREDAPI,
|
||||
DATACENTERAPI,
|
||||
}
|
||||
|
||||
// Bind the standard data name to the data type
|
||||
var Str = [...]string{
|
||||
"invalid",
|
||||
"data_resource",
|
||||
"processing_resource",
|
||||
"storage_resource",
|
||||
"datacenter_resource",
|
||||
"workflow_resource",
|
||||
"workflow",
|
||||
"workflow_execution",
|
||||
"workspace",
|
||||
"resource_model",
|
||||
"peer",
|
||||
"shared_workspace",
|
||||
"rule",
|
||||
"booking",
|
||||
}
|
||||
|
||||
func FromInt(i int) string {
|
||||
return Str[i]
|
||||
}
|
||||
|
||||
func (d DataType) API() string { // API - Returns the API name of the data type
|
||||
return DefaultAPI[d]
|
||||
}
|
||||
|
||||
func (d DataType) String() string { // String - Returns the string name of the data type
|
||||
return Str[d]
|
||||
}
|
||||
|
||||
// EnumIndex - Creating common behavior - give the type a EnumIndex functio
|
||||
func (d DataType) EnumIndex() int {
|
||||
return int(d)
|
||||
}
|
@@ -40,11 +40,11 @@ func ToMethod(str string) METHOD {
|
||||
var HTTPCallerInstance = &HTTPCaller{} // Singleton instance of the HTTPCaller
|
||||
|
||||
type HTTPCaller struct {
|
||||
URLS map[string]map[METHOD]string // Map of the different methods and their urls
|
||||
URLS map[DataType]map[METHOD]string // Map of the different methods and their urls
|
||||
}
|
||||
|
||||
// NewHTTPCaller creates a new instance of the HTTP Caller
|
||||
func NewHTTPCaller(urls map[string]map[METHOD]string) *HTTPCaller {
|
||||
func NewHTTPCaller(urls map[DataType]map[METHOD]string) *HTTPCaller {
|
||||
return &HTTPCaller{
|
||||
URLS: urls, // Set the urls defined in the config & based on the data name type & method
|
||||
}
|
||||
|
Reference in New Issue
Block a user