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 .
RUN go mod download
COPY cmd/ams cmd/ams
COPY pkg/ams pkg/ams
COPY pkg/agency/client pkg/agency/client
COPY pkg/client pkg/client
COPY pkg/schemas pkg/schemas
COPY pkg/status pkg/status
......
......@@ -51,14 +51,14 @@ import (
"net/http"
"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"
)
// remoteAgency holds the channel used for sending messages to remot agency
type remoteAgency struct {
msgIn chan schemas.ACLMessage // ACL message inbox
agencyClient *agencyclient.Client
agencyClient *client.AgencyClient
// agents map[int]*agent.Agent
}
......
......@@ -58,7 +58,6 @@ import (
"syscall"
"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/schemas"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/status"
......@@ -78,7 +77,7 @@ type Agency struct {
mqttClient *mqttClient
dfClient *client.DFClient
amsClient *client.AMSClient
agencyClient *agencyclient.Client
agencyClient *client.AgencyClient
logInfo *log.Logger // logger for info logging
logError *log.Logger // logger for error logging
}
......@@ -94,7 +93,7 @@ func StartAgency(task func(*Agent) error) (err error) {
msgIn: make(chan []schemas.ACLMessage, 1000),
dfClient: client.NewDFClient(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),
}
err = agency.init()
......
......@@ -56,7 +56,6 @@ import (
"strconv"
"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/schemas"
)
......@@ -67,7 +66,7 @@ type AMS struct {
depl deployment // interface for local or cloud deployment
logInfo *log.Logger // logger for info logging
logError *log.Logger // logger for error logging
agencyClient *agclient.Client
agencyClient *client.AgencyClient
dfClient *client.DFClient
}
......@@ -76,7 +75,7 @@ type AMS struct {
func StartAMS() (err error) {
ams := &AMS{
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),
}
// create storage and deployment object according to specified deployment type
......
......@@ -53,7 +53,6 @@ import (
"testing"
"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/common/httpreply"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
......@@ -70,7 +69,7 @@ func TestAMS(t *testing.T) {
ams := &AMS{
logError: log.New(os.Stderr, "[ERROR] ", 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),
}
// 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
THE SOFTWARE.
*/
// Package client contains code for interaction with agency
package client
import (
......@@ -56,8 +55,8 @@ import (
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/status"
)
// Client is the ams client
type Client struct {
// AgencyClient is the ams client
type AgencyClient struct {
httpClient *http.Client // http client
Port int // ams port
delay time.Duration // delay between two retries
......@@ -65,7 +64,7 @@ type Client struct {
}
// 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) {
var body []byte
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
}
// 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) {
var body []byte
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
}
// 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) {
var body []byte
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
}
// 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)
_, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix(agency)+"/api/agency/agents",
"application/json", js, time.Second*2, 2)
......@@ -121,14 +120,14 @@ func (cli *Client) PostAgent(agency string, agent schemas.AgentInfo) (httpStatus
}
// 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/"+
strconv.Itoa(agentID), nil, time.Second*2, 2)
return
}
// 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) {
var temp schemas.Status
var body []byte
......@@ -148,7 +147,7 @@ func (cli *Client) GetAgentStatus(agency string, agentID int) (agentStatus schem
}
// 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)
_, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix(agency)+"/api/agency/msgs",
"application/json", js, time.Second*2, 2)
......@@ -156,7 +155,7 @@ func (cli *Client) PostMsgs(agency string, msgs []schemas.ACLMessage) (httpStatu
}
// 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)
_, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix(agency)+"/api/agency/msgundeliv",
"application/json", js, time.Second*2, 2)
......@@ -164,21 +163,21 @@ func (cli *Client) ReturnMsg(agency string, msg schemas.ACLMessage) (httpStatus
}
// 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) {
_, httpStatus, err = httpretry.Put(cli.httpClient, cli.prefix(agency)+"/api/agency/agents/"+
strconv.Itoa(agentID)+"/custom", []byte(custom), time.Second*2, 2)
return
}
func (cli *Client) prefix(agency string) (ret string) {
func (cli *AgencyClient) prefix(agency string) (ret string) {
ret = "http://" + agency + ":" + strconv.Itoa(cli.Port)
return
}
// New creates a new AMS client
func New(timeout time.Duration, del time.Duration, numRet int) (cli *Client) {
cli = &Client{
// NewAgencyClient creates a new AMS client
func NewAgencyClient(timeout time.Duration, del time.Duration, numRet int) (cli *AgencyClient) {
cli = &AgencyClient{
httpClient: &http.Client{Timeout: timeout},
Port: 10000,
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