Commit 916f851c authored by Stefan Dähling's avatar Stefan Dähling
Browse files

endpoint for agent custom; refactor ams client

parent aedbd515
Pipeline #404853 failed with stages
in 1 minute and 23 seconds
...@@ -52,7 +52,6 @@ import ( ...@@ -52,7 +52,6 @@ import (
"strconv" "strconv"
agencyclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/agency/client" agencyclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/agency/client"
amsclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/ams/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
) )
...@@ -144,7 +143,7 @@ func (agency *Agency) requestAgentAddress(agentID int) (address schemas.Address, ...@@ -144,7 +143,7 @@ func (agency *Agency) requestAgentAddress(agentID int) (address schemas.Address,
agency.mutex.Lock() agency.mutex.Lock()
masID := agency.info.MASID masID := agency.info.MASID
agency.mutex.Unlock() agency.mutex.Unlock()
address, _, err = amsclient.GetAgentAddress(masID, agentID) address, _, err = agency.amsClient.GetAgentAddress(masID, agentID)
return return
} }
......
...@@ -58,7 +58,7 @@ import ( ...@@ -58,7 +58,7 @@ import (
"syscall" "syscall"
"time" "time"
amsclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/ams/client" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/ams"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/status" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/status"
) )
...@@ -75,6 +75,7 @@ type Agency struct { ...@@ -75,6 +75,7 @@ type Agency struct {
msgIn chan []schemas.ACLMessage msgIn chan []schemas.ACLMessage
logger *loggerClient logger *loggerClient
mqtt *mqttClient mqtt *mqttClient
amsClient *ams.Client
logInfo *log.Logger // logger for info logging logInfo *log.Logger // logger for info logging
logError *log.Logger // logger for error logging logError *log.Logger // logger for error logging
} }
...@@ -88,6 +89,7 @@ func StartAgency(task func(*Agent) error) (err error) { ...@@ -88,6 +89,7 @@ func StartAgency(task func(*Agent) error) (err error) {
remoteAgents: make(map[int]*Agent), remoteAgents: make(map[int]*Agent),
remoteAgencies: make(map[string]*remoteAgency), remoteAgencies: make(map[string]*remoteAgency),
msgIn: make(chan []schemas.ACLMessage, 1000), msgIn: make(chan []schemas.ACLMessage, 1000),
amsClient: ams.NewClient(time.Second*60, time.Second*1, 4),
logError: log.New(os.Stderr, "[ERROR] ", log.LstdFlags), logError: log.New(os.Stderr, "[ERROR] ", log.LstdFlags),
} }
err = agency.init() err = agency.init()
...@@ -168,7 +170,7 @@ func (agency *Agency) terminate(gracefulStop chan os.Signal) { ...@@ -168,7 +170,7 @@ func (agency *Agency) terminate(gracefulStop chan os.Signal) {
func (agency *Agency) startAgents() (err error) { func (agency *Agency) startAgents() (err error) {
// request configuration // request configuration
var agencyInfoFull schemas.AgencyInfoFull var agencyInfoFull schemas.AgencyInfoFull
agencyInfoFull, _, err = amsclient.GetAgencyInfo(agency.info.MASID, agency.info.ImageGroupID, agencyInfoFull, _, err = agency.amsClient.GetAgencyInfo(agency.info.MASID, agency.info.ImageGroupID,
agency.info.ID) agency.info.ID)
agency.mutex.Lock() agency.mutex.Lock()
agency.info.ID = agencyInfoFull.ID agency.info.ID = agencyInfoFull.ID
......
...@@ -189,6 +189,16 @@ func (ams *AMS) updateAgentAddress(masID int, agentID int, address schemas.Addre ...@@ -189,6 +189,16 @@ func (ams *AMS) updateAgentAddress(masID int, agentID int, address schemas.Addre
return return
} }
// updateAgentCustom sets custom config of agent and sends PUT to agency
func (ams *AMS) updateAgentCustom(masID int, agentID int, custom string) (err error) {
err = ams.stor.setAgentCustom(masID, agentID, custom)
if err != nil {
return
}
// ToDo Post new custom to agency
return
}
// getAgencies returns specs of all agencies in MAS // getAgencies returns specs of all agencies in MAS
func (ams *AMS) getAgencies(masID int) (ret schemas.Agencies, err error) { func (ams *AMS) getAgencies(masID int) (ret schemas.Agencies, err error) {
ret, err = ams.stor.getAgencies(masID) ret, err = ams.stor.getAgencies(masID)
......
...@@ -51,7 +51,6 @@ import ( ...@@ -51,7 +51,6 @@ import (
"testing" "testing"
"time" "time"
amsclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/ams/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/common/httpreply" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/common/httpreply"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
) )
...@@ -114,12 +113,13 @@ func stubHandler(w http.ResponseWriter, r *http.Request) { ...@@ -114,12 +113,13 @@ func stubHandler(w http.ResponseWriter, r *http.Request) {
// dummyClient makes requests to ams and terminates ams server at end // dummyClient makes requests to ams and terminates ams server at end
func dummyClient(s *http.Server, t *testing.T) { func dummyClient(s *http.Server, t *testing.T) {
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
amsclient.Host = "localhost" amsClient := NewClient(time.Second*60, time.Second*1, 4)
amsclient.Port = 10000 amsClient.Host = "localhost"
amsClient.Port = 10000
var err error var err error
var httpStatus int var httpStatus int
_, httpStatus, err = amsclient.GetCloneMAP() _, httpStatus, err = amsClient.GetCloneMAP()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
...@@ -153,7 +153,7 @@ func dummyClient(s *http.Server, t *testing.T) { ...@@ -153,7 +153,7 @@ func dummyClient(s *http.Server, t *testing.T) {
}, },
}, },
} }
httpStatus, err = amsclient.PostMAS(mas) httpStatus, err = amsClient.PostMAS(mas)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
...@@ -161,7 +161,7 @@ func dummyClient(s *http.Server, t *testing.T) { ...@@ -161,7 +161,7 @@ func dummyClient(s *http.Server, t *testing.T) {
t.Error("Error PostMAS " + strconv.Itoa(httpStatus)) t.Error("Error PostMAS " + strconv.Itoa(httpStatus))
} }
_, httpStatus, err = amsclient.GetMASsShort() _, httpStatus, err = amsClient.GetMASsShort()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
...@@ -169,7 +169,7 @@ func dummyClient(s *http.Server, t *testing.T) { ...@@ -169,7 +169,7 @@ func dummyClient(s *http.Server, t *testing.T) {
t.Error("Error GetMASs " + strconv.Itoa(httpStatus)) t.Error("Error GetMASs " + strconv.Itoa(httpStatus))
} }
_, httpStatus, err = amsclient.GetMAS(0) _, httpStatus, err = amsClient.GetMAS(0)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
...@@ -177,7 +177,7 @@ func dummyClient(s *http.Server, t *testing.T) { ...@@ -177,7 +177,7 @@ func dummyClient(s *http.Server, t *testing.T) {
t.Error("Error GetMAS " + strconv.Itoa(httpStatus)) t.Error("Error GetMAS " + strconv.Itoa(httpStatus))
} }
_, httpStatus, err = amsclient.GetAgents(0) _, httpStatus, err = amsClient.GetAgents(0)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
...@@ -185,7 +185,7 @@ func dummyClient(s *http.Server, t *testing.T) { ...@@ -185,7 +185,7 @@ func dummyClient(s *http.Server, t *testing.T) {
t.Error("Error GetAgents " + strconv.Itoa(httpStatus)) t.Error("Error GetAgents " + strconv.Itoa(httpStatus))
} }
_, httpStatus, err = amsclient.GetAgent(0, 0) _, httpStatus, err = amsClient.GetAgent(0, 0)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
...@@ -193,7 +193,7 @@ func dummyClient(s *http.Server, t *testing.T) { ...@@ -193,7 +193,7 @@ func dummyClient(s *http.Server, t *testing.T) {
t.Error("Error GetAgent " + strconv.Itoa(httpStatus)) t.Error("Error GetAgent " + strconv.Itoa(httpStatus))
} }
_, httpStatus, err = amsclient.GetAgentAddress(0, 0) _, httpStatus, err = amsClient.GetAgentAddress(0, 0)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
...@@ -201,7 +201,7 @@ func dummyClient(s *http.Server, t *testing.T) { ...@@ -201,7 +201,7 @@ func dummyClient(s *http.Server, t *testing.T) {
t.Error("Error GetAgentAddress " + strconv.Itoa(httpStatus)) t.Error("Error GetAgentAddress " + strconv.Itoa(httpStatus))
} }
_, httpStatus, err = amsclient.GetAgencies(0) _, httpStatus, err = amsClient.GetAgencies(0)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
...@@ -209,7 +209,7 @@ func dummyClient(s *http.Server, t *testing.T) { ...@@ -209,7 +209,7 @@ func dummyClient(s *http.Server, t *testing.T) {
t.Error("Error GetAgencies " + strconv.Itoa(httpStatus)) t.Error("Error GetAgencies " + strconv.Itoa(httpStatus))
} }
_, httpStatus, err = amsclient.GetAgencyInfo(0, 0, 0) _, httpStatus, err = amsClient.GetAgencyInfo(0, 0, 0)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
......
...@@ -42,8 +42,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ...@@ -42,8 +42,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
// Package client contains code for interaction with ams // contains code for interaction with ams
package client
package ams
import ( import (
"encoding/json" "encoding/json"
...@@ -57,21 +58,20 @@ import ( ...@@ -57,21 +58,20 @@ import (
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
) )
// Host contains the host name of ams (IP or k8s service name) // Client is the ams client
var Host = "ams" type Client struct {
httpClient *http.Client // http client
// Port contains the port on which ams is listening Host string // ams host name
var Port = 9000 Port int // ams port
delay time.Duration // delay between two retries
var httpClient = &http.Client{Timeout: time.Second * 60} numRetries int // number of retries
var delay = time.Second * 1 }
var numRetries = 4
// Alive tests if alive // Alive tests if alive
func Alive() (alive bool) { func (cli *Client) Alive() (alive bool) {
alive = false alive = false
_, httpStatus, err := httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ _, httpStatus, err := httpretry.Get(cli.httpClient, cli.prefix()+"/api/alive",
"/api/alive", time.Second*2, 2) time.Second*2, 2)
if err == nil && httpStatus == http.StatusOK { if err == nil && httpStatus == http.StatusOK {
alive = true alive = true
} }
...@@ -79,10 +79,10 @@ func Alive() (alive bool) { ...@@ -79,10 +79,10 @@ func Alive() (alive bool) {
} }
// GetCloneMAP requests CloneMAP information // GetCloneMAP requests CloneMAP information
func GetCloneMAP() (cmap schemas.CloneMAP, httpStatus int, err error) { func (cli *Client) GetCloneMAP() (cmap schemas.CloneMAP, httpStatus int, err error) {
var body []byte var body []byte
body, httpStatus, err = httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix()+"/api/clonemap",
"/api/clonemap", time.Second*2, 2) time.Second*2, 2)
if err != nil { if err != nil {
return return
} }
...@@ -94,10 +94,10 @@ func GetCloneMAP() (cmap schemas.CloneMAP, httpStatus int, err error) { ...@@ -94,10 +94,10 @@ func GetCloneMAP() (cmap schemas.CloneMAP, httpStatus int, err error) {
} }
// GetMASsShort requests mas information // GetMASsShort requests mas information
func GetMASsShort() (mass []schemas.MASInfoShort, httpStatus int, err error) { func (cli *Client) GetMASsShort() (mass []schemas.MASInfoShort, httpStatus int, err error) {
var body []byte var body []byte
body, httpStatus, err = httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix()+"/api/clonemap/mas",
"/api/clonemap/mas", time.Second*2, 2) time.Second*2, 2)
if err != nil { if err != nil {
return return
} }
...@@ -109,18 +109,18 @@ func GetMASsShort() (mass []schemas.MASInfoShort, httpStatus int, err error) { ...@@ -109,18 +109,18 @@ func GetMASsShort() (mass []schemas.MASInfoShort, httpStatus int, err error) {
} }
// PostMAS post an mas // PostMAS post an mas
func PostMAS(mas schemas.MASSpec) (httpStatus int, err error) { func (cli *Client) PostMAS(mas schemas.MASSpec) (httpStatus int, err error) {
js, _ := json.Marshal(mas) js, _ := json.Marshal(mas)
_, httpStatus, err = httpretry.Post(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ _, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix()+"/api/clonemap/mas",
"/api/clonemap/mas", "application/json", js, time.Second*2, 2) "application/json", js, time.Second*2, 2)
return return
} }
// GetMAS requests mas information // GetMAS requests mas information
func GetMAS(masID int) (mas schemas.MASInfo, httpStatus int, err error) { func (cli *Client) GetMAS(masID int) (mas schemas.MASInfo, httpStatus int, err error) {
var body []byte var body []byte
body, httpStatus, err = httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix()+"/api/clonemap/mas/"+
"/api/clonemap/mas/"+strconv.Itoa(masID), time.Second*2, 2) strconv.Itoa(masID), time.Second*2, 2)
if err != nil { if err != nil {
return return
} }
...@@ -132,18 +132,18 @@ func GetMAS(masID int) (mas schemas.MASInfo, httpStatus int, err error) { ...@@ -132,18 +132,18 @@ func GetMAS(masID int) (mas schemas.MASInfo, httpStatus int, err error) {
} }
// DeleteMAS deletes a MAS // DeleteMAS deletes a MAS
func DeleteMAS(masID int) (httpStatus int, err error) { func (cli *Client) DeleteMAS(masID int) (httpStatus int, err error) {
httpStatus, err = httpretry.Delete(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ httpStatus, err = httpretry.Delete(cli.httpClient, cli.prefix()+"/api/clonemap/mas/"+
"/api/clonemap/mas/"+strconv.Itoa(masID), nil, strconv.Itoa(masID), nil,
time.Second*2, 2) time.Second*2, 2)
return return
} }
// GetAgents requests agent information // GetAgents requests agent information
func GetAgents(masID int) (agents schemas.Agents, httpStatus int, err error) { func (cli *Client) GetAgents(masID int) (agents schemas.Agents, httpStatus int, err error) {
var body []byte var body []byte
body, httpStatus, err = httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix()+"/api/clonemap/mas/"+
"/api/clonemap/mas/"+strconv.Itoa(masID)+"/agents", time.Second*2, 2) strconv.Itoa(masID)+"/agents", time.Second*2, 2)
if err != nil { if err != nil {
return return
} }
...@@ -155,19 +155,20 @@ func GetAgents(masID int) (agents schemas.Agents, httpStatus int, err error) { ...@@ -155,19 +155,20 @@ func GetAgents(masID int) (agents schemas.Agents, httpStatus int, err error) {
} }
// PostAgents post agents to mas // PostAgents post agents to mas
func PostAgents(masID int, ags []schemas.ImageGroupSpec) (httpStatus int, err error) { func (cli *Client) PostAgents(masID int, ags []schemas.ImageGroupSpec) (httpStatus int, err error) {
js, _ := json.Marshal(ags) js, _ := json.Marshal(ags)
_, httpStatus, err = httpretry.Post(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ _, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix()+"/api/clonemap/mas/"+
"/api/clonemap/mas/"+strconv.Itoa(masID)+"/agents", "application/json", js, time.Second*2, strconv.Itoa(masID)+"/agents", "application/json", js, time.Second*2,
2) 2)
return return
} }
// GetAgent requests agent information // GetAgent requests agent information
func GetAgent(masID int, agentID int) (agent schemas.AgentInfo, httpStatus int, err error) { func (cli *Client) GetAgent(masID int, agentID int) (agent schemas.AgentInfo, httpStatus int,
err error) {
var body []byte var body []byte
body, httpStatus, err = httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix()+"/api/clonemap/mas/"+
"/api/clonemap/mas/"+strconv.Itoa(masID)+"/agents/"+strconv.Itoa(agentID), time.Second*2, 2) strconv.Itoa(masID)+"/agents/"+strconv.Itoa(agentID), time.Second*2, 2)
if err != nil { if err != nil {
return return
} }
...@@ -179,10 +180,11 @@ func GetAgent(masID int, agentID int) (agent schemas.AgentInfo, httpStatus int, ...@@ -179,10 +180,11 @@ func GetAgent(masID int, agentID int) (agent schemas.AgentInfo, httpStatus int,
} }
// GetAgentAddress requests agent address // GetAgentAddress requests agent address
func GetAgentAddress(masID int, agentID int) (address schemas.Address, httpStatus int, err error) { func (cli *Client) GetAgentAddress(masID int, agentID int) (address schemas.Address, httpStatus int,
err error) {
var body []byte var body []byte
ip := getIP() ip := cli.getIP()
body, httpStatus, err = httpretry.Get(httpClient, "http://"+ip+":"+strconv.Itoa(Port)+ body, httpStatus, err = httpretry.Get(cli.httpClient, "http://"+ip+":"+strconv.Itoa(cli.Port)+
"/api/clonemap/mas/"+strconv.Itoa(masID)+"/agents/"+strconv.Itoa(agentID)+"/address", "/api/clonemap/mas/"+strconv.Itoa(masID)+"/agents/"+strconv.Itoa(agentID)+"/address",
time.Second*2, 2) time.Second*2, 2)
if err != nil { if err != nil {
...@@ -196,18 +198,18 @@ func GetAgentAddress(masID int, agentID int) (address schemas.Address, httpStatu ...@@ -196,18 +198,18 @@ func GetAgentAddress(masID int, agentID int) (address schemas.Address, httpStatu
} }
// DeleteAgent deletes an agent // DeleteAgent deletes an agent
func DeleteAgent(masID int, agentID int) (httpStatus int, err error) { func (cli *Client) DeleteAgent(masID int, agentID int) (httpStatus int, err error) {
httpStatus, err = httpretry.Delete(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ httpStatus, err = httpretry.Delete(cli.httpClient, cli.prefix()+"/api/clonemap/mas/"+
"/api/clonemap/mas/"+strconv.Itoa(masID)+"/agents/"+strconv.Itoa(agentID), nil, strconv.Itoa(masID)+"/agents/"+strconv.Itoa(agentID), nil,
time.Second*2, 2) time.Second*2, 2)
return return
} }
// GetAgencies requests agency information // GetAgencies requests agency information
func GetAgencies(masID int) (agencies schemas.Agencies, httpStatus int, err error) { func (cli *Client) GetAgencies(masID int) (agencies schemas.Agencies, httpStatus int, err error) {
var body []byte var body []byte
body, httpStatus, err = httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix()+"/api/clonemap/mas/"+
"/api/clonemap/mas/"+strconv.Itoa(masID)+"/agencies", time.Second*2, 2) strconv.Itoa(masID)+"/agencies", time.Second*2, 2)
if err != nil { if err != nil {
return return
} }
...@@ -219,11 +221,11 @@ func GetAgencies(masID int) (agencies schemas.Agencies, httpStatus int, err erro ...@@ -219,11 +221,11 @@ func GetAgencies(masID int) (agencies schemas.Agencies, httpStatus int, err erro
} }
// GetAgencyInfo requests agency information // GetAgencyInfo requests agency information
func GetAgencyInfo(masID int, imID int, agencyID int) (agency schemas.AgencyInfoFull, func (cli *Client) GetAgencyInfo(masID int, imID int, agencyID int) (agency schemas.AgencyInfoFull,
httpStatus int, err error) { httpStatus int, err error) {
var body []byte var body []byte
body, httpStatus, err = httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+ body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix()+"/api/clonemap/mas/"+
"/api/clonemap/mas/"+strconv.Itoa(masID)+"/imgroup/"+strconv.Itoa(imID)+"/agency/"+ strconv.Itoa(masID)+"/imgroup/"+strconv.Itoa(imID)+"/agency/"+
strconv.Itoa(agencyID), time.Second*2, 2) strconv.Itoa(agencyID), time.Second*2, 2)
if err != nil { if err != nil {
return return
...@@ -236,16 +238,9 @@ func GetAgencyInfo(masID int, imID int, agencyID int) (agency schemas.AgencyInfo ...@@ -236,16 +238,9 @@ func GetAgencyInfo(masID int, imID int, agencyID int) (agency schemas.AgencyInfo
return return
} }
// Init initializes the client func (cli *Client) getIP() (ret string) {
func Init(timeout time.Duration, del time.Duration, numRet int) {
httpClient.Timeout = timeout
delay = del
numRetries = numRet
}
func getIP() (ret string) {
for { for {
ips, err := net.LookupHost(Host) ips, err := net.LookupHost(cli.Host)
if len(ips) > 0 && err == nil { if len(ips) > 0 && err == nil {
ret = ips[0] ret = ips[0]
break break
...@@ -253,3 +248,20 @@ func getIP() (ret string) { ...@@ -253,3 +248,20 @@ func getIP() (ret string) {
} }
return return
} }
func (cli *Client) prefix() (ret string) {
ret = "http://" + cli.Host + ":" + strconv.Itoa(cli.Port)
return
}
// NewClient creates a new AMS client
func NewClient(timeout time.Duration, del time.Duration, numRet int) (cli *Client) {
cli = &Client{
httpClient: &http.Client{Timeout: timeout},
Host: "ams",
Port: 9000,
delay: del,
numRetries: numRet,
}
return
}
...@@ -56,6 +56,7 @@ THE SOFTWARE. ...@@ -56,6 +56,7 @@ THE SOFTWARE.
// ams/mas/<masID>/im/<imID>/agency/<agencyID>: schemas.AgencyInfo // ams/mas/<masID>/im/<imID>/agency/<agencyID>: schemas.AgencyInfo
// ams/mas/<masID>/agentcounter int (agentCounter) // ams/mas/<masID>/agentcounter int (agentCounter)
// ams/mas/<masID>/agent/<agentID>: schemas.AgentInfo // ams/mas/<masID>/agent/<agentID>: schemas.AgentInfo
// ams/mas/<masID>/agent/<agentID>/address: schemas.Adress
// //
// df/graph/<masID>: schemas.Graph // df/graph/<masID>: schemas.Graph
...@@ -115,8 +116,27 @@ func (stor *etcdStorage) setCloneMAPInfo(cloneMAP schemas.CloneMAP) (err error) ...@@ -115,8 +116,27 @@ func (stor *etcdStorage) setCloneMAPInfo(cloneMAP schemas.CloneMAP) (err error)
// setAgentAddress sets address of agent // setAgentAddress sets address of agent
func (stor *etcdStorage) setAgentAddress(masID int, agentID int, func (stor *etcdStorage) setAgentAddress(masID int, agentID int,
address schemas.Address) (err error) { address schemas.Address) (err error) {
err = stor.etcdPutResource("ams/mas/"+strconv.Itoa(masID)+"/agent/"+strconv.Itoa(agentID)+ var agentInfo schemas.AgentInfo
"/address", address) agentInfo, err = stor.getAgentInfo(masID, agentID)
if err != nil {
return
}
agentInfo.Address = address
err = stor.etcdPutResource("ams/mas/"+strconv.Itoa(masID)+"/agent/"+strconv.Itoa(agentID),
agentInfo)
return
}
// setAgentCustom sets custom config of agent
func (stor *etcdStorage) setAgentCustom(masID int, agentID int, custom string) (err error) {
var agentInfo schemas.AgentInfo
agentInfo, err = stor.getAgentInfo(masID, agentID)