implement statuscode in packets
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m2s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m2s
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
@@ -26,7 +25,6 @@ type RemoteHost struct {
|
||||
*Client
|
||||
Host string
|
||||
MissedPings int
|
||||
//Pool *RemoteGrainPool
|
||||
}
|
||||
|
||||
type SyncedPool struct {
|
||||
@@ -248,21 +246,27 @@ const (
|
||||
)
|
||||
|
||||
func (h *RemoteHost) Negotiate(knownHosts []string) ([]string, error) {
|
||||
data, err := h.Call(RemoteNegotiate, RemoteNegotiateResponse, []byte(strings.Join(knownHosts, ";")))
|
||||
reply, err := h.Call(RemoteNegotiate, RemoteNegotiateResponse, []byte(strings.Join(knownHosts, ";")))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if reply.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("remote returned error on negotiate: %s", string(reply.Data))
|
||||
}
|
||||
|
||||
return strings.Split(string(data), ";"), nil
|
||||
return strings.Split(string(reply.Data), ";"), nil
|
||||
}
|
||||
|
||||
func (g *RemoteHost) GetCartMappings() ([]CartId, error) {
|
||||
data, err := g.Call(GetCartIds, CartIdsResponse, []byte{})
|
||||
reply, err := g.Call(GetCartIds, CartIdsResponse, []byte{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
parts := strings.Split(string(data), ";")
|
||||
if reply.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("remote returned error: %s", string(reply.Data))
|
||||
}
|
||||
parts := strings.Split(string(reply.Data), ";")
|
||||
ids := make([]CartId, 0, len(parts))
|
||||
for _, p := range parts {
|
||||
ids = append(ids, ToCartId(p))
|
||||
@@ -289,13 +293,13 @@ func (p *SyncedPool) Negotiate(knownHosts []string) ([]string, error) {
|
||||
}
|
||||
|
||||
func (r *RemoteHost) ConfirmChange(id CartId, host string) error {
|
||||
data, err := r.Call(RemoteGrainChanged, AckChange, []byte(fmt.Sprintf("%s;%s", id, host)))
|
||||
reply, err := r.Call(RemoteGrainChanged, AckChange, []byte(fmt.Sprintf("%s;%s", id, host)))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if string(data) != "ok" {
|
||||
return fmt.Errorf("remote grain change failed %s", string(data))
|
||||
if string(reply.Data) != "ok" {
|
||||
return fmt.Errorf("remote grain change failed %s", string(reply.Data))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -443,9 +447,9 @@ func (p *SyncedPool) getGrain(id CartId) (Grain, error) {
|
||||
return localGrain, nil
|
||||
}
|
||||
|
||||
func (p *SyncedPool) Process(id CartId, messages ...Message) ([]byte, error) {
|
||||
func (p *SyncedPool) Process(id CartId, messages ...Message) (*CallResult, error) {
|
||||
pool, err := p.getGrain(id)
|
||||
var res []byte
|
||||
var res *CallResult
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -458,7 +462,7 @@ func (p *SyncedPool) Process(id CartId, messages ...Message) ([]byte, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (p *SyncedPool) Get(id CartId) ([]byte, error) {
|
||||
func (p *SyncedPool) Get(id CartId) (*CallResult, error) {
|
||||
grain, err := p.getGrain(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -467,5 +471,5 @@ func (p *SyncedPool) Get(id CartId) ([]byte, error) {
|
||||
return remoteGrain.GetCurrentState()
|
||||
}
|
||||
|
||||
return json.Marshal(grain)
|
||||
return grain.GetCurrentState()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user