Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
Cloud
MAS
clonemap
Commits
71fa94d0
Commit
71fa94d0
authored
Mar 30, 2020
by
Stefan Dähling
Browse files
new api endpoint for agency info
parent
79889b7c
Pipeline
#262290
passed with stages
in 1 minute and 46 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pkg/ams/ams.go
View file @
71fa94d0
...
...
@@ -192,6 +192,12 @@ func (ams *AMS) getAgencyInfoFull(masID int, agencyID int) (ret schemas.AgencyIn
return
}
func
(
ams
*
AMS
)
getContainerAgencyInfoFull
(
masID
int
,
imID
int
,
agencyID
int
)
(
ret
schemas
.
AgencyInfoFull
,
err
error
)
{
ret
,
err
=
ams
.
stor
.
getContainerAgencyInfoFull
(
masID
,
imID
,
agencyID
)
return
}
// createMAS creates a new mas according to masconfig
func
(
ams
*
AMS
)
createMAS
(
masSpec
schemas
.
MASSpec
)
(
err
error
)
{
// fill masInfo
...
...
pkg/ams/client/client.go
View file @
71fa94d0
...
...
@@ -208,6 +208,24 @@ func GetAgencyInfoFull(masID int, agencyID int) (agency schemas.AgencyInfoFull,
return
}
// GetContainerAgencyInfoFull requests agency information
func
GetContainerAgencyInfoFull
(
masID
int
,
imID
int
,
agencyID
int
)
(
agency
schemas
.
AgencyInfoFull
,
httpStatus
int
,
err
error
)
{
var
body
[]
byte
body
,
httpStatus
,
err
=
httpretry
.
Get
(
httpClient
,
"http://"
+
Host
+
":"
+
strconv
.
Itoa
(
Port
)
+
"/api/clonemap/mas/"
+
strconv
.
Itoa
(
masID
)
+
"/container/"
+
strconv
.
Itoa
(
imID
)
+
"/"
+
strconv
.
Itoa
(
agencyID
),
time
.
Second
*
2
,
2
)
if
err
!=
nil
{
return
}
//fmt.Println(string(body))
err
=
json
.
Unmarshal
(
body
,
&
agency
)
if
err
!=
nil
{
agency
=
schemas
.
AgencyInfoFull
{}
}
return
}
// Init initializes the client
func
Init
(
timeout
time
.
Duration
,
del
time
.
Duration
,
numRet
int
)
{
httpClient
.
Timeout
=
timeout
...
...
pkg/ams/handler.go
View file @
71fa94d0
...
...
@@ -137,20 +137,17 @@ func (ams *AMS) handleAPI(w http.ResponseWriter, r *http.Request) {
cmapErr
,
httpErr
=
ams
.
handleAgentAddress
(
masID
,
agentID
,
w
,
r
)
resvalid
=
true
}
}
else
if
respath
[
5
]
==
"container"
{
var
imid
,
agencyID
int
imid
,
cmapErr
=
strconv
.
Atoi
(
respath
[
6
])
if
cmapErr
!=
nil
{
agencyID
,
cmapErr
=
strconv
.
Atoi
(
respath
[
6
])
if
cmapErr
==
nil
{
cmapErr
,
httpErr
=
ams
.
handleContainer
(
masID
,
imid
,
agencyID
,
w
,
r
)
resvalid
=
true
}
}
}
// } else if respath[5] == "agencies" {
// var agencyID int
// agencyID, cmapErr = strconv.Atoi(respath[6])
// if cmapErr == nil {
// // if respath[7] == "status" {
// // cmapErr, httpErr = ams.handleAgencyStatus(masID, agencyID, w, r)
// // resvalid = true
// // } else
// if respath[7] == "config" {
// cmapErr, httpErr = ams.handleAgencyConfig(masID, agencyID, w, r)
// resvalid = true
// }
// }
}
}
default
:
...
...
@@ -320,7 +317,7 @@ func (ams *AMS) handleAgentAddress(masID int, agentid int, w http.ResponseWriter
return
}
// handleAgen
t
is the handler for requests to path /api/cloumap/mas/{mas-id}/agencies
// handleAgen
cy
is the handler for requests to path /api/cloumap/mas/{mas-id}/agencies
func
(
ams
*
AMS
)
handleAgency
(
masID
int
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
cmapErr
,
httpErr
error
)
{
if
r
.
Method
==
"GET"
{
...
...
@@ -336,7 +333,7 @@ func (ams *AMS) handleAgency(masID int, w http.ResponseWriter, r *http.Request)
return
}
// handleAgen
t
ID is the handler for requests to path /api/cloumap/mas/{mas-id}/agencies/{agency-id}
// handleAgen
cy
ID is the handler for requests to path /api/cloumap/mas/{mas-id}/agencies/{agency-id}
func
(
ams
*
AMS
)
handleAgencyID
(
masID
int
,
agencyid
int
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
cmapErr
,
httpErr
error
)
{
if
r
.
Method
==
"GET"
{
...
...
@@ -351,22 +348,21 @@ func (ams *AMS) handleAgencyID(masID int, agencyid int, w http.ResponseWriter,
return
}
// // handleAgencyConfig is the handler for requests to path
// // /api/clonemap/mas/{mas-id}/agencies/{agency-id}/config
// func (ams *AMS) handleAgencyConfig(masID int, agencyid int, w http.ResponseWriter,
// r *http.Request) (cmapErr, httpErr error) {
// if r.Method == "GET" {
// // return config of specified agency
// var agencyConfig schemas.AgencyConfig
// agencyConfig, cmapErr = ams.getAgencyConfig(masID, agencyid)
// httpErr = httpreply.Resource(w, agencyConfig, cmapErr)
// } else {
// httpErr = httpreply.MethodNotAllowed(w)
// cmapErr = errors.New("Error: Method not allowed on path /api/clonemap/mas/{mas-id}/" +
// "agencies/{agency-id}/config")
// }
// return
// }
// handleContainer is the handler for requests to path /api/cloumap/mas/{mas-id}/container/{imid}/
// {agency-id}
func
(
ams
*
AMS
)
handleContainer
(
masID
int
,
imID
int
,
agencyid
int
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
cmapErr
,
httpErr
error
)
{
if
r
.
Method
==
"GET"
{
var
agencySpec
schemas
.
AgencyInfoFull
agencySpec
,
cmapErr
=
ams
.
getContainerAgencyInfoFull
(
masID
,
imID
,
agencyid
)
httpErr
=
httpreply
.
Resource
(
w
,
agencySpec
,
cmapErr
)
}
else
{
httpErr
=
httpreply
.
MethodNotAllowed
(
w
)
cmapErr
=
errors
.
New
(
"Error: Method not allowed on path /api/clonemap/mas/{mas-id}/"
+
"agencies/{agency-id}"
)
}
return
}
// listen opens a http server listening and serving request
func
(
ams
*
AMS
)
listen
()
(
err
error
)
{
...
...
pkg/ams/storage.go
View file @
71fa94d0
...
...
@@ -89,6 +89,10 @@ type storage interface {
// getAgencyInfoFull returns status of one agency
getAgencyInfoFull
(
masID
int
,
agencyID
int
)
(
ret
schemas
.
AgencyInfoFull
,
err
error
)
// getContainerAgencyInfoFull returns the agency info for an image id and an agency id
getContainerAgencyInfoFull
(
masID
int
,
imID
int
,
agencyID
int
)
(
ret
schemas
.
AgencyInfoFull
,
err
error
)
// registerMAS registers a new MAS with the storage and returns its ID
registerMAS
()
(
masID
int
,
err
error
)
...
...
@@ -283,6 +287,44 @@ func (stor *localStorage) getAgencyInfoFull(masID int,
return
}
// getContainerAgencyInfoFull returns info of one agency for imid and agencyID
func
(
stor
*
localStorage
)
getContainerAgencyInfoFull
(
masID
int
,
imID
int
,
agencyID
int
)
(
ret
schemas
.
AgencyInfoFull
,
err
error
)
{
agencyName
:=
"mas-"
+
strconv
.
Itoa
(
masID
)
+
"-im-"
+
strconv
.
Itoa
(
imID
)
+
"-agency-"
+
strconv
.
Itoa
(
agencyID
)
+
".mas"
+
strconv
.
Itoa
(
masID
)
+
"agencies"
realID
:=
-
1
stor
.
mutex
.
Lock
()
if
len
(
stor
.
mas
)
-
1
<
masID
{
stor
.
mutex
.
Unlock
()
err
=
errors
.
New
(
"Agency does not exist"
)
return
}
if
len
(
stor
.
mas
[
masID
]
.
ImageGroups
)
-
1
<
imID
{
stor
.
mutex
.
Unlock
()
err
=
errors
.
New
(
"Agency does not exist"
)
return
}
for
i
:=
range
stor
.
mas
[
masID
]
.
ImageGroups
[
imID
]
.
Agencies
{
tempID
:=
stor
.
mas
[
masID
]
.
ImageGroups
[
imID
]
.
Agencies
[
i
]
if
len
(
stor
.
mas
[
masID
]
.
Agencies
.
Instances
)
-
1
<
tempID
{
stor
.
mutex
.
Unlock
()
err
=
errors
.
New
(
"Agency does not exist"
)
return
}
if
stor
.
mas
[
masID
]
.
Agencies
.
Instances
[
tempID
]
.
Name
==
agencyName
{
realID
=
tempID
break
}
}
stor
.
mutex
.
Unlock
()
if
realID
==
-
1
{
err
=
errors
.
New
(
"Agency does not exist"
)
return
}
ret
,
err
=
stor
.
getAgencyInfoFull
(
masID
,
realID
)
return
}
// registerMAS registers a new MAS with the storage and returns its ID
func
(
stor
*
localStorage
)
registerMAS
()
(
masID
int
,
err
error
)
{
stor
.
mutex
.
Lock
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment