refactor addition in oclib for better use
This commit is contained in:
parent
88c88cac5b
commit
a3029fa3f9
@ -29,28 +29,7 @@ type PeerCache struct {
|
|||||||
|
|
||||||
// urlFormat formats the URL of the peer with the data type API function
|
// urlFormat formats the URL of the peer with the data type API function
|
||||||
func (p *PeerCache) urlFormat(hostUrl string, dt tools.DataType) string {
|
func (p *PeerCache) urlFormat(hostUrl string, dt tools.DataType) string {
|
||||||
// localhost is replaced by the local peer URL
|
return hostUrl + "/" + strings.ReplaceAll(dt.API(), "oc-", "")
|
||||||
// because localhost must collide on a web request security protocol
|
|
||||||
/*localhost := ""
|
|
||||||
if strings.Contains(hostUrl, "localhost") {
|
|
||||||
localhost = "localhost"
|
|
||||||
}
|
|
||||||
if strings.Contains(hostUrl, "127.0.0.1") {
|
|
||||||
localhost = "127.0.0.1"
|
|
||||||
}
|
|
||||||
if localhost != "" {
|
|
||||||
r := regexp.MustCompile("(" + localhost + ":[0-9]+)")
|
|
||||||
t := r.FindString(hostUrl)
|
|
||||||
if t != "" {
|
|
||||||
hostUrl = strings.Replace(hostUrl, t, dt.API()+":8080/oc", -1)
|
|
||||||
} else {
|
|
||||||
hostUrl = strings.ReplaceAll(hostUrl, localhost, dt.API()+":8080/oc")
|
|
||||||
}
|
|
||||||
} else {*/
|
|
||||||
hostUrl = hostUrl + "/" + strings.ReplaceAll(dt.API(), "oc-", "")
|
|
||||||
//}
|
|
||||||
fmt.Println("Contacting", hostUrl)
|
|
||||||
return hostUrl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkPeerStatus checks the status of a peer
|
// checkPeerStatus checks the status of a peer
|
||||||
@ -86,7 +65,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
|||||||
// If the peer is not reachable, add the execution to the failed executions list
|
// If the peer is not reachable, add the execution to the failed executions list
|
||||||
pexec := &PeerExecution{
|
pexec := &PeerExecution{
|
||||||
Method: method.String(),
|
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) + path, // the url is constitued of : host URL + resource path + action path (ex : mypeer.com/datacenter/resourcetype/path/to/action)
|
||||||
Body: body,
|
Body: body,
|
||||||
DataType: dt.EnumIndex(),
|
DataType: dt.EnumIndex(),
|
||||||
DataID: dataID,
|
DataID: dataID,
|
||||||
@ -99,7 +78,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
|||||||
return nil, errors.New("peer not found")
|
return nil, errors.New("peer not found")
|
||||||
}
|
}
|
||||||
// If the peer is reachable, launch the execution
|
// If the peer is reachable, launch the execution
|
||||||
url = p.urlFormat((mypeer.Url), dt) + path // Format the URL
|
url = p.urlFormat((mypeer.Url), dt) + path // Format the URL
|
||||||
tmp := mypeer.FailedExecution // Get the failed executions list
|
tmp := mypeer.FailedExecution // Get the failed executions list
|
||||||
mypeer.FailedExecution = []PeerExecution{} // Reset the failed executions list
|
mypeer.FailedExecution = []PeerExecution{} // Reset the failed executions list
|
||||||
NewShallowAccessor().UpdateOne(mypeer, peerID) // Update the peer in the db
|
NewShallowAccessor().UpdateOne(mypeer, peerID) // Update the peer in the db
|
||||||
|
@ -31,6 +31,43 @@ func (d *Workflow) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
|||||||
return NewAccessor(request) // Create a new instance of the accessor
|
return NewAccessor(request) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Deps struct {
|
||||||
|
Source string
|
||||||
|
Dest string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Workflow) isDependancy(id string) []Deps {
|
||||||
|
dependancyOfIDs := []Deps{}
|
||||||
|
for _, link := range w.Graph.Links {
|
||||||
|
if _, ok := w.Graph.Items[link.Destination.ID]; !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
source := w.Graph.Items[link.Destination.ID].Processing
|
||||||
|
if id == link.Source.ID && source != nil {
|
||||||
|
dependancyOfIDs = append(dependancyOfIDs, Deps{Source: source.GetName(), Dest: link.Destination.ID})
|
||||||
|
}
|
||||||
|
sourceWF := w.Graph.Items[link.Destination.ID].Workflow
|
||||||
|
if id == link.Source.ID && sourceWF != nil {
|
||||||
|
dependancyOfIDs = append(dependancyOfIDs, Deps{Source: sourceWF.GetName(), Dest: link.Destination.ID})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dependancyOfIDs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Workflow) GetDependencies(id string) (dependencies []Deps) {
|
||||||
|
for _, link := range w.Graph.Links {
|
||||||
|
if _, ok := w.Graph.Items[link.Source.ID]; !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
source := w.Graph.Items[link.Source.ID].Processing
|
||||||
|
if id == link.Destination.ID && source != nil {
|
||||||
|
dependencies = append(dependencies, Deps{Source: source.GetName(), Dest: link.Source.ID})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Workflow) GetGraphItems(f func(item graph.GraphItem) bool) (list_datas []graph.GraphItem) {
|
func (w *Workflow) GetGraphItems(f func(item graph.GraphItem) bool) (list_datas []graph.GraphItem) {
|
||||||
for _, item := range w.Graph.Items {
|
for _, item := range w.Graph.Items {
|
||||||
if f(item) {
|
if f(item) {
|
||||||
|
Loading…
Reference in New Issue
Block a user