Commit 065a897f authored by Stefan Dähling's avatar Stefan Dähling
Browse files

move agency client to new package

parent 8afc46a8
Pipeline #439422 failed with stages
in 6 minutes and 28 seconds
...@@ -48,7 +48,6 @@ COPY go.sum . ...@@ -48,7 +48,6 @@ COPY go.sum .
RUN go mod download RUN go mod download
COPY cmd/ams cmd/ams COPY cmd/ams cmd/ams
COPY pkg/ams pkg/ams COPY pkg/ams pkg/ams
COPY pkg/agency/client pkg/agency/client
COPY pkg/client pkg/client COPY pkg/client pkg/client
COPY pkg/schemas pkg/schemas COPY pkg/schemas pkg/schemas
COPY pkg/status pkg/status COPY pkg/status pkg/status
......
...@@ -51,14 +51,14 @@ import ( ...@@ -51,14 +51,14 @@ import (
"net/http" "net/http"
"strconv" "strconv"
agencyclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/agency/client" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
) )
// remoteAgency holds the channel used for sending messages to remot agency // remoteAgency holds the channel used for sending messages to remot agency
type remoteAgency struct { type remoteAgency struct {
msgIn chan schemas.ACLMessage // ACL message inbox msgIn chan schemas.ACLMessage // ACL message inbox
agencyClient *agencyclient.Client agencyClient *client.AgencyClient
// agents map[int]*agent.Agent // agents map[int]*agent.Agent
} }
......
...@@ -58,7 +58,6 @@ import ( ...@@ -58,7 +58,6 @@ import (
"syscall" "syscall"
"time" "time"
agencyclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/agency/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client"
"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"
...@@ -78,7 +77,7 @@ type Agency struct { ...@@ -78,7 +77,7 @@ type Agency struct {
mqttClient *mqttClient mqttClient *mqttClient
dfClient *client.DFClient dfClient *client.DFClient
amsClient *client.AMSClient amsClient *client.AMSClient
agencyClient *agencyclient.Client agencyClient *client.AgencyClient
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
} }
...@@ -94,7 +93,7 @@ func StartAgency(task func(*Agent) error) (err error) { ...@@ -94,7 +93,7 @@ func StartAgency(task func(*Agent) error) (err error) {
msgIn: make(chan []schemas.ACLMessage, 1000), msgIn: make(chan []schemas.ACLMessage, 1000),
dfClient: client.NewDFClient(time.Second*60, time.Second*1, 4), dfClient: client.NewDFClient(time.Second*60, time.Second*1, 4),
amsClient: client.NewAMSClient(time.Second*60, time.Second*1, 4), amsClient: client.NewAMSClient(time.Second*60, time.Second*1, 4),
agencyClient: agencyclient.New(time.Second*60, time.Second*1, 4), agencyClient: client.NewAgencyClient(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()
......
...@@ -56,7 +56,6 @@ import ( ...@@ -56,7 +56,6 @@ import (
"strconv" "strconv"
"time" "time"
agclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/agency/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
) )
...@@ -67,7 +66,7 @@ type AMS struct { ...@@ -67,7 +66,7 @@ type AMS struct {
depl deployment // interface for local or cloud deployment depl deployment // interface for local or cloud deployment
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
agencyClient *agclient.Client agencyClient *client.AgencyClient
dfClient *client.DFClient dfClient *client.DFClient
} }
...@@ -76,7 +75,7 @@ type AMS struct { ...@@ -76,7 +75,7 @@ type AMS struct {
func StartAMS() (err error) { func StartAMS() (err error) {
ams := &AMS{ ams := &AMS{
logError: log.New(os.Stderr, "[ERROR] ", log.LstdFlags), logError: log.New(os.Stderr, "[ERROR] ", log.LstdFlags),
agencyClient: agclient.New(time.Second*60, time.Second*1, 4), agencyClient: client.NewAgencyClient(time.Second*60, time.Second*1, 4),
dfClient: client.NewDFClient(time.Second*60, time.Second*1, 4), dfClient: client.NewDFClient(time.Second*60, time.Second*1, 4),
} }
// create storage and deployment object according to specified deployment type // create storage and deployment object according to specified deployment type
......
...@@ -53,7 +53,6 @@ import ( ...@@ -53,7 +53,6 @@ import (
"testing" "testing"
"time" "time"
agclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/agency/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/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"
...@@ -70,7 +69,7 @@ func TestAMS(t *testing.T) { ...@@ -70,7 +69,7 @@ func TestAMS(t *testing.T) {
ams := &AMS{ ams := &AMS{
logError: log.New(os.Stderr, "[ERROR] ", log.LstdFlags), logError: log.New(os.Stderr, "[ERROR] ", log.LstdFlags),
logInfo: log.New(os.Stdout, "[INFO] ", log.LstdFlags), logInfo: log.New(os.Stdout, "[INFO] ", log.LstdFlags),
agencyClient: agclient.New(time.Second*60, time.Second*1, 4), agencyClient: client.NewAgencyClient(time.Second*60, time.Second*1, 4),
dfClient: client.NewDFClient(time.Second*60, time.Second*1, 4), dfClient: client.NewDFClient(time.Second*60, time.Second*1, 4),
} }
// create storage and deployment object according to specified deployment type // create storage and deployment object according to specified deployment type
......
...@@ -42,7 +42,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ...@@ -42,7 +42,6 @@ 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 agency
package client package client
import ( import (
...@@ -56,8 +55,8 @@ import ( ...@@ -56,8 +55,8 @@ import (
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/status" "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/status"
) )
// Client is the ams client // AgencyClient is the ams client
type Client struct { type AgencyClient struct {
httpClient *http.Client // http client httpClient *http.Client // http client
Port int // ams port Port int // ams port
delay time.Duration // delay between two retries delay time.Duration // delay between two retries
...@@ -65,7 +64,7 @@ type Client struct { ...@@ -65,7 +64,7 @@ type Client struct {
} }
// GetInfo requests the agency info // GetInfo requests the agency info
func (cli *Client) GetInfo(agency string) (agencyInfo schemas.AgencyInfo, httpStatus int, func (cli *AgencyClient) GetInfo(agency string) (agencyInfo schemas.AgencyInfo, httpStatus int,
err error) { err error) {
var body []byte var body []byte
body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix(agency)+"/api/agency", body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix(agency)+"/api/agency",
...@@ -81,7 +80,7 @@ func (cli *Client) GetInfo(agency string) (agencyInfo schemas.AgencyInfo, httpSt ...@@ -81,7 +80,7 @@ func (cli *Client) GetInfo(agency string) (agencyInfo schemas.AgencyInfo, httpSt
} }
// GetAgents requests the agents running in agency // GetAgents requests the agents running in agency
func (cli *Client) GetAgents(agency string) (agentInfo []schemas.AgentInfo, httpStatus int, func (cli *AgencyClient) GetAgents(agency string) (agentInfo []schemas.AgentInfo, httpStatus int,
err error) { err error) {
var body []byte var body []byte
body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix(agency)+"/api/agency/agents", body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix(agency)+"/api/agency/agents",
...@@ -97,7 +96,7 @@ func (cli *Client) GetAgents(agency string) (agentInfo []schemas.AgentInfo, http ...@@ -97,7 +96,7 @@ func (cli *Client) GetAgents(agency string) (agentInfo []schemas.AgentInfo, http
} }
// GetAgent requests one agent running in agency // GetAgent requests one agent running in agency
func (cli *Client) GetAgent(agency string, agentID int) (agentInfo schemas.AgentInfo, func (cli *AgencyClient) GetAgent(agency string, agentID int) (agentInfo schemas.AgentInfo,
httpStatus int, err error) { httpStatus int, err error) {
var body []byte var body []byte
body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix(agency)+"/api/agency/agents/"+ body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix(agency)+"/api/agency/agents/"+
...@@ -113,7 +112,7 @@ func (cli *Client) GetAgent(agency string, agentID int) (agentInfo schemas.Agent ...@@ -113,7 +112,7 @@ func (cli *Client) GetAgent(agency string, agentID int) (agentInfo schemas.Agent
} }
// PostAgent post an agent to agency // PostAgent post an agent to agency
func (cli *Client) PostAgent(agency string, agent schemas.AgentInfo) (httpStatus int, err error) { func (cli *AgencyClient) PostAgent(agency string, agent schemas.AgentInfo) (httpStatus int, err error) {
js, _ := json.Marshal(agent) js, _ := json.Marshal(agent)
_, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix(agency)+"/api/agency/agents", _, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix(agency)+"/api/agency/agents",
"application/json", js, time.Second*2, 2) "application/json", js, time.Second*2, 2)
...@@ -121,14 +120,14 @@ func (cli *Client) PostAgent(agency string, agent schemas.AgentInfo) (httpStatus ...@@ -121,14 +120,14 @@ func (cli *Client) PostAgent(agency string, agent schemas.AgentInfo) (httpStatus
} }
// DeleteAgent requests an agent to terminate // DeleteAgent requests an agent to terminate
func (cli *Client) DeleteAgent(agency string, agentID int) (httpStatus int, err error) { func (cli *AgencyClient) DeleteAgent(agency string, agentID int) (httpStatus int, err error) {
httpStatus, err = httpretry.Delete(cli.httpClient, cli.prefix(agency)+"/api/agency/agents/"+ httpStatus, err = httpretry.Delete(cli.httpClient, cli.prefix(agency)+"/api/agency/agents/"+
strconv.Itoa(agentID), nil, time.Second*2, 2) strconv.Itoa(agentID), nil, time.Second*2, 2)
return return
} }
// GetAgentStatus requests status from agent and returns it // GetAgentStatus requests status from agent and returns it
func (cli *Client) GetAgentStatus(agency string, agentID int) (agentStatus schemas.Status, func (cli *AgencyClient) GetAgentStatus(agency string, agentID int) (agentStatus schemas.Status,
httpStatus int, err error) { httpStatus int, err error) {
var temp schemas.Status var temp schemas.Status
var body []byte var body []byte
...@@ -148,7 +147,7 @@ func (cli *Client) GetAgentStatus(agency string, agentID int) (agentStatus schem ...@@ -148,7 +147,7 @@ func (cli *Client) GetAgentStatus(agency string, agentID int) (agentStatus schem
} }
// PostMsgs post an agent message to the agent // PostMsgs post an agent message to the agent
func (cli *Client) PostMsgs(agency string, msgs []schemas.ACLMessage) (httpStatus int, err error) { func (cli *AgencyClient) PostMsgs(agency string, msgs []schemas.ACLMessage) (httpStatus int, err error) {
js, _ := json.Marshal(msgs) js, _ := json.Marshal(msgs)
_, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix(agency)+"/api/agency/msgs", _, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix(agency)+"/api/agency/msgs",
"application/json", js, time.Second*2, 2) "application/json", js, time.Second*2, 2)
...@@ -156,7 +155,7 @@ func (cli *Client) PostMsgs(agency string, msgs []schemas.ACLMessage) (httpStatu ...@@ -156,7 +155,7 @@ func (cli *Client) PostMsgs(agency string, msgs []schemas.ACLMessage) (httpStatu
} }
// ReturnMsg return undeliverable msg // ReturnMsg return undeliverable msg
func (cli *Client) ReturnMsg(agency string, msg schemas.ACLMessage) (httpStatus int, err error) { func (cli *AgencyClient) ReturnMsg(agency string, msg schemas.ACLMessage) (httpStatus int, err error) {
js, _ := json.Marshal(msg) js, _ := json.Marshal(msg)
_, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix(agency)+"/api/agency/msgundeliv", _, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix(agency)+"/api/agency/msgundeliv",
"application/json", js, time.Second*2, 2) "application/json", js, time.Second*2, 2)
...@@ -164,21 +163,21 @@ func (cli *Client) ReturnMsg(agency string, msg schemas.ACLMessage) (httpStatus ...@@ -164,21 +163,21 @@ func (cli *Client) ReturnMsg(agency string, msg schemas.ACLMessage) (httpStatus
} }
// PutAgentCustom puts agent custom data // PutAgentCustom puts agent custom data
func (cli *Client) PutAgentCustom(agency string, agentID int, custom string) (httpStatus int, func (cli *AgencyClient) PutAgentCustom(agency string, agentID int, custom string) (httpStatus int,
err error) { err error) {
_, httpStatus, err = httpretry.Put(cli.httpClient, cli.prefix(agency)+"/api/agency/agents/"+ _, httpStatus, err = httpretry.Put(cli.httpClient, cli.prefix(agency)+"/api/agency/agents/"+
strconv.Itoa(agentID)+"/custom", []byte(custom), time.Second*2, 2) strconv.Itoa(agentID)+"/custom", []byte(custom), time.Second*2, 2)
return return
} }
func (cli *Client) prefix(agency string) (ret string) { func (cli *AgencyClient) prefix(agency string) (ret string) {
ret = "http://" + agency + ":" + strconv.Itoa(cli.Port) ret = "http://" + agency + ":" + strconv.Itoa(cli.Port)
return return
} }
// New creates a new AMS client // NewAgencyClient creates a new AMS client
func New(timeout time.Duration, del time.Duration, numRet int) (cli *Client) { func NewAgencyClient(timeout time.Duration, del time.Duration, numRet int) (cli *AgencyClient) {
cli = &Client{ cli = &AgencyClient{
httpClient: &http.Client{Timeout: timeout}, httpClient: &http.Client{Timeout: timeout},
Port: 10000, Port: 10000,
delay: del, delay: del,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment