Commit 8afc46a8 authored by Stefan Dähling's avatar Stefan Dähling
Browse files

move df client to new pkg

parent 817ce213
Pipeline #439420 canceled with stages
......@@ -49,7 +49,6 @@ RUN go mod download
COPY cmd/agency cmd/agency
COPY pkg/agency pkg/agency
COPY pkg/client pkg/client
COPY pkg/df/client pkg/df/client
COPY pkg/schemas pkg/schemas
COPY pkg/status pkg/status
COPY pkg/common pkg/common
......
......@@ -49,7 +49,7 @@ RUN go mod download
COPY cmd/ams cmd/ams
COPY pkg/ams pkg/ams
COPY pkg/agency/client pkg/agency/client
COPY pkg/df/client pkg/df/client
COPY pkg/client pkg/client
COPY pkg/schemas pkg/schemas
COPY pkg/status pkg/status
COPY pkg/common pkg/common
......
......@@ -48,7 +48,6 @@ COPY go.sum .
RUN go mod download
COPY pkg/agency pkg/agency
COPY pkg/client pkg/client
COPY pkg/df/client pkg/df/client
COPY pkg/schemas pkg/schemas
COPY pkg/status pkg/status
COPY pkg/common pkg/common
......
......@@ -50,7 +50,6 @@ COPY cmd/frontend cmd/frontend
COPY pkg/frontend pkg/frontend
COPY pkg/common pkg/common
COPY pkg/schemas pkg/schemas
COPY pkg/df/client pkg/df/client
COPY pkg/client pkg/client
COPY web web
ENV PATH="/clonemap:${PATH}"
......
......@@ -60,7 +60,6 @@ import (
agencyclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/agency/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client"
dfclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/df/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/status"
)
......@@ -77,7 +76,7 @@ type Agency struct {
msgIn chan []schemas.ACLMessage
logCollector *client.LogCollector
mqttClient *mqttClient
dfClient *dfclient.Client
dfClient *client.DFClient
amsClient *client.AMSClient
agencyClient *agencyclient.Client
logInfo *log.Logger // logger for info logging
......@@ -93,7 +92,7 @@ func StartAgency(task func(*Agent) error) (err error) {
remoteAgents: make(map[int]*Agent),
remoteAgencies: make(map[string]*remoteAgency),
msgIn: make(chan []schemas.ACLMessage, 1000),
dfClient: dfclient.New(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),
agencyClient: agencyclient.New(time.Second*60, time.Second*1, 4),
logError: log.New(os.Stderr, "[ERROR] ", log.LstdFlags),
......
......@@ -53,7 +53,6 @@ import (
"sync"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client"
dfclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/df/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/status"
)
......@@ -82,7 +81,7 @@ type Agent struct {
// newAgent creates a new agent
func newAgent(info schemas.AgentInfo, msgIn chan schemas.ACLMessage,
aclLookup func(int) (*ACL, error), logCol *client.LogCollector, logConfig schemas.LoggerConfig,
mqtt *mqttClient, dfClient *dfclient.Client, logErr *log.Logger, logInf *log.Logger) (ag *Agent) {
mqtt *mqttClient, dfClient *client.DFClient, logErr *log.Logger, logInf *log.Logger) (ag *Agent) {
ag = &Agent{
id: info.ID,
nodeID: info.Spec.NodeID,
......
......@@ -51,7 +51,7 @@ import (
"sync"
"time"
dfclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/df/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
)
......@@ -63,7 +63,7 @@ type DF struct {
mutex *sync.Mutex
registeredServices map[string]schemas.Service
active bool // indicates if df is active (switch via env)
dfClient *dfclient.Client
dfClient *client.DFClient
logError *log.Logger
logInfo *log.Logger
}
......@@ -184,7 +184,7 @@ func (df *DF) DeregisterService(svcID string) (err error) {
}
// newDF creates a new DF object
func newDF(masID int, agentID int, nodeID int, dfCli *dfclient.Client, logErr *log.Logger,
func newDF(masID int, agentID int, nodeID int, dfCli *client.DFClient, logErr *log.Logger,
logInf *log.Logger) (df *DF) {
df = &DF{
agentID: agentID,
......
......@@ -57,7 +57,7 @@ import (
"time"
agclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/agency/client"
dfclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/df/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
)
......@@ -68,7 +68,7 @@ type AMS struct {
logInfo *log.Logger // logger for info logging
logError *log.Logger // logger for error logging
agencyClient *agclient.Client
dfClient *dfclient.Client
dfClient *client.DFClient
}
// StartAMS starts an AMS instance. It initializes the cluster and storage object and starts API
......@@ -77,7 +77,7 @@ func StartAMS() (err error) {
ams := &AMS{
logError: log.New(os.Stderr, "[ERROR] ", log.LstdFlags),
agencyClient: agclient.New(time.Second*60, time.Second*1, 4),
dfClient: dfclient.New(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
err = ams.init()
......
......@@ -56,7 +56,6 @@ import (
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"
dfclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/df/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
)
......@@ -72,7 +71,7 @@ func TestAMS(t *testing.T) {
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),
dfClient: dfclient.New(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
err := ams.init()
......
......@@ -42,7 +42,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Package client implements a df client
package client
import (
......@@ -59,8 +58,8 @@ import (
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
)
// Client is the ams client
type Client struct {
// DFClient is the ams client
type DFClient struct {
httpClient *http.Client // http client
Host string // ams host name
Port int // ams port
......@@ -69,7 +68,7 @@ type Client struct {
}
// Alive tests if alive
func (cli *Client) Alive() (alive bool) {
func (cli *DFClient) Alive() (alive bool) {
alive = false
_, httpStatus, err := httpretry.Get(cli.httpClient, cli.prefix()+"/api/alive", time.Second*2, 2)
if err == nil && httpStatus == http.StatusOK {
......@@ -79,7 +78,7 @@ func (cli *Client) Alive() (alive bool) {
}
// PostSvc post an mas
func (cli *Client) PostSvc(masID int, svc schemas.Service) (retSvc schemas.Service, httpStatus int,
func (cli *DFClient) PostSvc(masID int, svc schemas.Service) (retSvc schemas.Service, httpStatus int,
err error) {
var body []byte
js, _ := json.Marshal(svc)
......@@ -93,7 +92,7 @@ func (cli *Client) PostSvc(masID int, svc schemas.Service) (retSvc schemas.Servi
}
// GetSvc requests mas information
func (cli *Client) GetSvc(masID int, desc string) (svc []schemas.Service, httpStatus int,
func (cli *DFClient) GetSvc(masID int, desc string) (svc []schemas.Service, httpStatus int,
err error) {
var body []byte
body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix()+"/api/df/"+
......@@ -106,7 +105,7 @@ func (cli *Client) GetSvc(masID int, desc string) (svc []schemas.Service, httpSt
}
// GetLocalSvc requests mas information
func (cli *Client) GetLocalSvc(masID int, desc string, nodeID int,
func (cli *DFClient) GetLocalSvc(masID int, desc string, nodeID int,
dist float64) (svc []schemas.Service, httpStatus int, err error) {
var body []byte
body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix()+"/api/df/"+
......@@ -120,14 +119,14 @@ func (cli *Client) GetLocalSvc(masID int, desc string, nodeID int,
}
// DeleteSvc removes service from df
func (cli *Client) DeleteSvc(masID int, svcID string) (httpStatus int, err error) {
func (cli *DFClient) DeleteSvc(masID int, svcID string) (httpStatus int, err error) {
httpStatus, err = httpretry.Delete(cli.httpClient, cli.prefix()+"/api/df/"+strconv.Itoa(masID)+
"/svc/id/"+svcID, nil, time.Second*2, 2)
return
}
// PostGraph post the graph of a mas
func (cli *Client) PostGraph(masID int, gr schemas.Graph) (httpStatus int, err error) {
func (cli *DFClient) PostGraph(masID int, gr schemas.Graph) (httpStatus int, err error) {
js, _ := json.Marshal(gr)
_, httpStatus, err = httpretry.Post(cli.httpClient, cli.prefix()+"/api/df/"+
strconv.Itoa(masID)+"/graph", "application/json", js, time.Second*2, 2)
......@@ -135,7 +134,7 @@ func (cli *Client) PostGraph(masID int, gr schemas.Graph) (httpStatus int, err e
}
// GetGraph returns graph of mas
func (cli *Client) GetGraph(masID int) (graph schemas.Graph, httpStatus int, err error) {
func (cli *DFClient) GetGraph(masID int) (graph schemas.Graph, httpStatus int, err error) {
var body []byte
body, httpStatus, err = httpretry.Get(cli.httpClient, cli.prefix()+"/api/df/"+
strconv.Itoa(masID)+"/graph", time.Second*2, 2)
......@@ -146,7 +145,7 @@ func (cli *Client) GetGraph(masID int) (graph schemas.Graph, httpStatus int, err
return
}
func (cli *Client) getIP() (ret string) {
func (cli *DFClient) getIP() (ret string) {
for {
ips, err := net.LookupHost(cli.Host)
if len(ips) > 0 && err == nil {
......@@ -157,14 +156,14 @@ func (cli *Client) getIP() (ret string) {
return
}
func (cli *Client) prefix() (ret string) {
func (cli *DFClient) prefix() (ret string) {
ret = "http://" + cli.Host + ":" + 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{
// NewDFClient creates a new AMS client
func NewDFClient(timeout time.Duration, del time.Duration, numRet int) (cli *DFClient) {
cli = &DFClient{
httpClient: &http.Client{Timeout: timeout},
Host: "df",
Port: 12000,
......
......@@ -52,14 +52,13 @@ import (
"time"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client"
dfclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/df/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
)
// Frontend frontend
type Frontend struct {
amsClient *client.AMSClient
dfClient *dfclient.Client
dfClient *client.DFClient
logClient *client.LoggerClient
logInfo *log.Logger // logger for info logging
logError *log.Logger // logger for error logging
......@@ -69,7 +68,7 @@ type Frontend struct {
func StartFrontend() (err error) {
fe := &Frontend{
amsClient: client.NewAMSClient(time.Second*60, time.Second*1, 4),
dfClient: dfclient.New(time.Second*60, time.Second*1, 4),
dfClient: client.NewDFClient(time.Second*60, time.Second*1, 4),
logError: log.New(os.Stderr, "[ERROR] ", log.LstdFlags),
}
fe.logClient, _ = client.NewLoggerClient("logger", 11000, time.Second*60, time.Second*1, 4)
......
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