Compare commits
3 Commits
bugfix/lag
...
debug/chec
Author | SHA1 | Date | |
---|---|---|---|
41ddf1f7cb | |||
18c723ee42 | |||
d4f000466f |
@@ -287,7 +287,7 @@ func (m *MongoDB) Search(filters *dbs.Filters, collection_name string) (*mongo.C
|
||||
return nil, 503, err
|
||||
}
|
||||
opts := options.Find()
|
||||
opts.SetLimit(1000)
|
||||
opts.SetLimit(100)
|
||||
targetDBCollection := CollectionMap[collection_name]
|
||||
orList := bson.A{}
|
||||
andList := bson.A{}
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
@@ -31,7 +32,7 @@ type PeerCache struct {
|
||||
func (p *PeerCache) urlFormat(hostUrl string, dt tools.DataType) string {
|
||||
// localhost is replaced by the local peer URL
|
||||
// because localhost must collide on a web request security protocol
|
||||
/*localhost := ""
|
||||
localhost := ""
|
||||
if strings.Contains(hostUrl, "localhost") {
|
||||
localhost = "localhost"
|
||||
}
|
||||
@@ -46,10 +47,10 @@ func (p *PeerCache) urlFormat(hostUrl string, dt tools.DataType) string {
|
||||
} else {
|
||||
hostUrl = strings.ReplaceAll(hostUrl, localhost, dt.API()+":8080/oc")
|
||||
}
|
||||
} else {*/
|
||||
hostUrl = hostUrl + "/" + strings.ReplaceAll(dt.API(), "oc-", "")
|
||||
//}
|
||||
fmt.Println("Contacting", hostUrl)
|
||||
} else {
|
||||
hostUrl = hostUrl + "/" + strings.ReplaceAll(dt.API(), "oc-", "")
|
||||
}
|
||||
fmt.Println("Host URL : ", hostUrl)
|
||||
return hostUrl
|
||||
}
|
||||
|
||||
@@ -69,16 +70,15 @@ func (p *PeerCache) checkPeerStatus(peerID string, appName string) (*Peer, bool)
|
||||
}
|
||||
|
||||
// LaunchPeerExecution launches an execution on a peer
|
||||
// The method contacts the path described by : peer.Url + datatype path (from enums) + replacement of id by dataID
|
||||
func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
||||
dt tools.DataType, method tools.METHOD, body interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
|
||||
fmt.Println("Launching peer execution on", caller.URLS, dt, method)
|
||||
methods := caller.URLS[dt] // Get the methods url of the data type
|
||||
if m, ok := methods[method]; !ok || m == "" {
|
||||
return nil, errors.New("Requested method " + method.String() + " not declared in HTTPCaller")
|
||||
return nil, errors.New("no path found")
|
||||
}
|
||||
path := methods[method] // Get the path corresponding to the action we want to execute
|
||||
path = strings.ReplaceAll(path, ":id", dataID) // Replace the id in the path in case of a DELETE / UPDATE method (it's a standard naming in OC)
|
||||
meth := methods[method] // Get the method url to execute
|
||||
meth = strings.ReplaceAll(meth, ":id", dataID) // Replace the id in the url in case of a DELETE / UPDATE method (it's a standard naming in OC)
|
||||
url := ""
|
||||
|
||||
// Check the status of the peer
|
||||
@@ -86,20 +86,20 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
||||
// If the peer is not reachable, add the execution to the failed executions list
|
||||
pexec := &PeerExecution{
|
||||
Method: method.String(),
|
||||
Url: p.urlFormat((mypeer.Url), dt) + path, // the url is constitued of : host URL + resource path + action path (ex : mypeer.com/datacenter/resourcetype/path/to/action)
|
||||
Url: p.urlFormat((mypeer.Url), dt) + meth,
|
||||
Body: body,
|
||||
DataType: dt.EnumIndex(),
|
||||
DataID: dataID,
|
||||
}
|
||||
mypeer.AddExecution(*pexec)
|
||||
NewShallowAccessor().UpdateOne(mypeer, peerID) // Update the peer in the db
|
||||
return nil, errors.New("peer is " + peerID + " not reachable")
|
||||
return nil, errors.New("peer is not reachable")
|
||||
} else {
|
||||
if mypeer == nil {
|
||||
return nil, errors.New("peer " + peerID + " not found")
|
||||
return nil, errors.New("peer not found")
|
||||
}
|
||||
// If the peer is reachable, launch the execution
|
||||
url = p.urlFormat((mypeer.Url), dt) + path // Format the URL
|
||||
url = p.urlFormat((mypeer.Url), dt) + meth // Format the URL
|
||||
tmp := mypeer.FailedExecution // Get the failed executions list
|
||||
mypeer.FailedExecution = []PeerExecution{} // Reset the failed executions list
|
||||
NewShallowAccessor().UpdateOne(mypeer, peerID) // Update the peer in the db
|
||||
|
@@ -112,8 +112,6 @@ func (d *WorkflowExecution) VerifyAuth(request *tools.APIRequest) bool {
|
||||
func (d *WorkflowExecution) Book(executionsID string, wfID string, priceds map[tools.DataType]map[string]pricing.PricedItemITF) []*booking.Booking {
|
||||
booking := d.bookEach(executionsID, wfID, tools.STORAGE_RESOURCE, priceds[tools.STORAGE_RESOURCE])
|
||||
booking = append(booking, d.bookEach(executionsID, wfID, tools.PROCESSING_RESOURCE, priceds[tools.PROCESSING_RESOURCE])...)
|
||||
booking = append(booking,d.bookEach(executionsID, wfID, tools.COMPUTE_RESOURCE, priceds[tools.COMPUTE_RESOURCE])...)
|
||||
booking = append(booking,d.bookEach(executionsID, wfID, tools.DATA_RESOURCE, priceds[tools.DATA_RESOURCE])...)
|
||||
return booking
|
||||
}
|
||||
|
||||
|
@@ -4,10 +4,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||
@@ -16,7 +14,6 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
"github.com/google/uuid"
|
||||
"github.com/robfig/cron"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -55,8 +52,6 @@ func NewScheduler(start string, end string, durationInS float64, cron string) *W
|
||||
}
|
||||
|
||||
func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest) (bool, *workflow.Workflow, []*WorkflowExecution, []*booking.Booking, error) {
|
||||
l := logs.GetLogger().With().Str("SchedulerID", ws.UUID).Logger()
|
||||
l.Debug().Msg("Checking booking")
|
||||
if request.Caller == nil && request.Caller.URLS == nil && request.Caller.URLS[tools.BOOKING] == nil || request.Caller.URLS[tools.BOOKING][tools.GET] == "" {
|
||||
return false, nil, []*WorkflowExecution{}, []*booking.Booking{}, errors.New("no caller defined")
|
||||
}
|
||||
@@ -75,71 +70,29 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest)
|
||||
if ws.End != nil && ws.Start.Add(time.Duration(longest)*time.Second).After(*ws.End) {
|
||||
ws.Warning = "The workflow may be too long to be executed in the given time frame, we will try to book it anyway\n"
|
||||
}
|
||||
l.Debug().Msg("Getting executions")
|
||||
execs, err := ws.getExecutions(wf)
|
||||
if err != nil {
|
||||
return false, wf, []*WorkflowExecution{}, []*booking.Booking{}, err
|
||||
}
|
||||
bookings := []*booking.Booking{}
|
||||
for i, exec := range execs {
|
||||
l.Debug().Msg("looping throughs execs : " + string(i))
|
||||
for _, exec := range execs {
|
||||
bookings = append(bookings, exec.Book(ws.UUID, wfID, priceds)...)
|
||||
}
|
||||
|
||||
errCh := make(chan error, len(bookings))
|
||||
var m sync.Mutex
|
||||
|
||||
for _, b := range bookings {
|
||||
go getBooking(l, b, request, wf, execs, bookings, errCh, &m)
|
||||
}
|
||||
|
||||
for i := 0; i < len(bookings); i++ {
|
||||
if err := <-errCh; err != nil {
|
||||
return false, wf, execs, bookings, err
|
||||
for _, b := range bookings {
|
||||
meth := request.Caller.URLS[tools.BOOKING][tools.GET]
|
||||
meth = strings.ReplaceAll(meth, ":id", b.ResourceID)
|
||||
meth = strings.ReplaceAll(meth, ":start_date", b.ExpectedStartDate.Format("2006-01-02T15:04:05"))
|
||||
meth = strings.ReplaceAll(meth, ":end_date", b.ExpectedEndDate.Format("2006-01-02T15:04:05"))
|
||||
request.Caller.URLS[tools.BOOKING][tools.GET] = meth
|
||||
_, err := (&peer.Peer{}).LaunchPeerExecution(b.DestPeerID, b.ResourceID, tools.BOOKING, tools.GET, nil, request.Caller)
|
||||
if err != nil {
|
||||
return false, wf, execs, bookings, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true, wf, execs, bookings, nil
|
||||
}
|
||||
|
||||
func getBooking(l zerolog.Logger, b *booking.Booking, request *tools.APIRequest, wf *workflow.Workflow, execs []*WorkflowExecution, bookings []*booking.Booking, errCh chan error, m *sync.Mutex) {
|
||||
|
||||
m.Lock()
|
||||
c, err := getCallerCopy(request, errCh)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
m.Unlock()
|
||||
|
||||
bl := l.With().Str("booking", b.UUID).Logger()
|
||||
meth := request.Caller.URLS[tools.BOOKING][tools.GET]
|
||||
meth = strings.ReplaceAll(meth, ":id", b.ResourceID)
|
||||
meth = strings.ReplaceAll(meth, ":start_date", b.ExpectedStartDate.Format("2006-01-02T15:04:05"))
|
||||
meth = strings.ReplaceAll(meth, ":end_date", b.ExpectedEndDate.Format("2006-01-02T15:04:05"))
|
||||
request.Caller.URLS[tools.BOOKING][tools.GET] = meth
|
||||
bl.Debug().Msg("Get booking " + b.UUID + " on " + b.DestPeerID)
|
||||
_, err = (&peer.Peer{}).LaunchPeerExecution(b.DestPeerID, b.ResourceID, tools.BOOKING, tools.GET, nil, &c)
|
||||
bl.Debug().Msg("Received response from Get booking " + b.UUID + " on " + b.DestPeerID)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
|
||||
errCh <- nil
|
||||
}
|
||||
|
||||
func getCallerCopy(request *tools.APIRequest, errCh chan error) (tools.HTTPCaller, error) {
|
||||
var c tools.HTTPCaller
|
||||
err := request.Caller.DeepCopy(c)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return tools.HTTPCaller{}, nil
|
||||
}
|
||||
c.URLS = request.Caller.URLS
|
||||
return c, err
|
||||
}
|
||||
|
||||
func (ws *WorkflowSchedule) Schedules(wfID string, request *tools.APIRequest) (*WorkflowSchedule, *workflow.Workflow, []*WorkflowExecution, error) {
|
||||
if request == nil {
|
||||
return ws, nil, []*WorkflowExecution{}, errors.New("no request found")
|
||||
@@ -158,20 +111,13 @@ func (ws *WorkflowSchedule) Schedules(wfID string, request *tools.APIRequest) (*
|
||||
return ws, nil, executions, errors.New("could not book the workflow : " + fmt.Sprintf("%v", err))
|
||||
}
|
||||
ws.Workflow = wf
|
||||
|
||||
var errCh = make(chan error, len(bookings))
|
||||
var m sync.Mutex
|
||||
|
||||
for _, booking := range bookings {
|
||||
go ws.BookExecs(booking, request, errCh, &m)
|
||||
}
|
||||
|
||||
for i := 0; i < len(bookings); i++ {
|
||||
if err := <- errCh ; err != nil {
|
||||
_, err := (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
|
||||
tools.BOOKING, tools.POST, booking.Serialize(booking), request.Caller)
|
||||
if err != nil {
|
||||
return ws, wf, executions, errors.New("could not launch the peer execution : " + fmt.Sprintf("%v", err))
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Schedules")
|
||||
for _, exec := range executions {
|
||||
err := exec.PurgeDraft(request)
|
||||
@@ -185,30 +131,6 @@ func (ws *WorkflowSchedule) Schedules(wfID string, request *tools.APIRequest) (*
|
||||
return ws, wf, executions, nil
|
||||
}
|
||||
|
||||
func (ws *WorkflowSchedule) BookExecs(booking *booking.Booking, request *tools.APIRequest, errCh chan error, m *sync.Mutex) {
|
||||
|
||||
m.Lock()
|
||||
c, err := getCallerCopy(request, errCh)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
m.Unlock()
|
||||
|
||||
l := logs.GetLogger().With().Str("SchedulerID", ws.UUID).Logger()
|
||||
l.Debug().Msg("Booking " + booking.UUID + " on " + booking.DestPeerID)
|
||||
_, err = (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
|
||||
tools.BOOKING, tools.POST, booking.Serialize(booking), &c)
|
||||
l.Debug().Msg("Received answer for booking " + booking.UUID + " on " + booking.DestPeerID)
|
||||
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
|
||||
errCh <- nil
|
||||
}
|
||||
|
||||
/*
|
||||
BOOKING IMPLIED TIME, not of subscription but of execution
|
||||
so is processing time execution time applied on computes
|
||||
|
@@ -39,7 +39,7 @@ var ADMIRALTY_SOURCEAPI = DATACENTERAPI+"/admiralty/source"
|
||||
var ADMIRALTY_TARGETAPI = DATACENTERAPI+"/admiralty/target"
|
||||
var ADMIRALTY_SECRETAPI = DATACENTERAPI+"/admiralty/secret"
|
||||
var ADMIRALTY_KUBECONFIGAPI = DATACENTERAPI+"/admiralty/kubeconfig"
|
||||
var ADMIRALTY_NODESAPI = DATACENTERAPI+"/admiralty/node"
|
||||
var ADMIRALTY_NODESAPI = DATACENTERAPI+"/admiralty/nodes"
|
||||
|
||||
// Bind the standard API name to the data type
|
||||
var DefaultAPI = [...]string{
|
||||
|
@@ -3,7 +3,6 @@ package tools
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -50,9 +49,8 @@ func ToMethod(str string) METHOD {
|
||||
var HTTPCallerInstance = &HTTPCaller{} // Singleton instance of the HTTPCaller
|
||||
|
||||
type HTTPCaller struct {
|
||||
URLS map[DataType]map[METHOD]string // Map of the different methods and their urls
|
||||
Disabled bool // Disabled flag
|
||||
LastResults map[string]interface{} // Used to store information regarding the last execution of a given method on a given data type
|
||||
URLS map[DataType]map[METHOD]string // Map of the different methods and their urls
|
||||
Disabled bool // Disabled flag
|
||||
}
|
||||
|
||||
// NewHTTPCaller creates a new instance of the HTTP Caller
|
||||
@@ -63,16 +61,6 @@ func NewHTTPCaller(urls map[DataType]map[METHOD]string) *HTTPCaller {
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a copy of the current caller, in order to have parallelized executions without race condition
|
||||
func (c* HTTPCaller) DeepCopy(dst HTTPCaller) error {
|
||||
bytes, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.Unmarshal(bytes, &dst)
|
||||
}
|
||||
|
||||
// CallGet calls the GET method on the HTTP server
|
||||
func (caller *HTTPCaller) CallGet(url string, subpath string, types ...string) ([]byte, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, url+subpath, bytes.NewBuffer([]byte("")))
|
||||
@@ -88,33 +76,17 @@ func (caller *HTTPCaller) CallGet(url string, subpath string, types ...string) (
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
err = caller.StoreResp(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return caller.LastResults["body"].([]byte), nil
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
// CallPut calls the DELETE method on the HTTP server
|
||||
func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error) {
|
||||
req, err := http.NewRequest("DELETE", url+subpath, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil || req == nil || req.Body == nil {
|
||||
resp, err := http.NewRequest("DELETE", url+subpath, nil)
|
||||
if err != nil || resp == nil || resp.Body == nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
err = caller.StoreResp(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return caller.LastResults["body"].([]byte), nil
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
// CallPost calls the POST method on the HTTP server
|
||||
@@ -133,12 +105,7 @@ func (caller *HTTPCaller) CallPost(url string, subpath string, body interface{},
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
err = caller.StoreResp(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return caller.LastResults["body"].([]byte), nil
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
// CallPost calls the POST method on the HTTP server
|
||||
@@ -156,12 +123,7 @@ func (caller *HTTPCaller) CallPut(url string, subpath string, body map[string]in
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
err = caller.StoreResp(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return caller.LastResults["body"].([]byte), nil
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
// CallRaw calls the Raw method on the HTTP server
|
||||
@@ -181,12 +143,7 @@ func (caller *HTTPCaller) CallRaw(method string, url string, subpath string,
|
||||
req.AddCookie(c)
|
||||
}
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
return client.Do(req)
|
||||
}
|
||||
|
||||
// CallRaw calls the Raw method on the HTTP server
|
||||
@@ -206,17 +163,3 @@ func (caller *HTTPCaller) CallForm(method string, url string, subpath string,
|
||||
client := &http.Client{}
|
||||
return client.Do(req)
|
||||
}
|
||||
|
||||
func (caller *HTTPCaller) StoreResp(resp *http.Response) error {
|
||||
caller.LastResults = make(map[string]interface{})
|
||||
caller.LastResults["header"] = resp.Header
|
||||
caller.LastResults["code"] = resp.StatusCode
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println("Error reading the body of the last request")
|
||||
return err
|
||||
}
|
||||
|
||||
caller.LastResults["body"] = data
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user