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
VILLASframework
VILLASweb-backend-go
Commits
8a5b276b
Commit
8a5b276b
authored
Jan 18, 2021
by
Sonja Happ
Browse files
AMQP: remove UUID from ICstatus, fake headers in IC testing
parent
f4bcc49f
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
routes/infrastructure-component/ic_amqpclient.go
View file @
8a5b276b
...
...
@@ -56,7 +56,6 @@ type Action struct {
}
type
ICStatus
struct
{
UUID
*
string
`json:"uuid"`
State
*
string
`json:"state"`
Name
*
string
`json:"name"`
Category
*
string
`json:"category"`
...
...
@@ -262,14 +261,12 @@ func processMessage(message amqp.Delivery) error {
return
fmt
.
Errorf
(
"AMQP: Could not unmarshal message to JSON: %v err: %v"
,
string
(
message
.
Body
),
err
)
}
//payload.Status.UUID = new(string)
headers
:=
amqp
.
Table
(
message
.
Headers
)
*
payload
.
Status
.
UUID
=
fmt
.
Sprintf
(
"%v"
,
headers
[
"uuid"
])
if
payload
.
Status
!=
nil
{
//log.Println("Processing AMQP message: ", string(message.Body))
// if a message contains a "state" field, it is an update for an IC
ICUUID
:=
*
payload
.
Status
.
UUID
headers
:=
amqp
.
Table
(
message
.
Headers
)
ICUUID
:=
fmt
.
Sprintf
(
"%v"
,
headers
[
"uuid"
])
_
,
err
=
uuid
.
Parse
(
ICUUID
)
if
err
!=
nil
{
...
...
@@ -280,7 +277,7 @@ func processMessage(message amqp.Delivery) error {
if
err
==
gorm
.
ErrRecordNotFound
{
// create new record
err
=
createExternalIC
(
payload
)
err
=
createExternalIC
(
payload
,
ICUUID
)
}
else
if
err
!=
nil
{
// database error
err
=
fmt
.
Errorf
(
"AMQP: Database error for IC %v DB error message: %v"
,
ICUUID
,
err
)
...
...
@@ -292,10 +289,10 @@ func processMessage(message amqp.Delivery) error {
return
err
}
func
createExternalIC
(
payload
ICUpdate
)
error
{
func
createExternalIC
(
payload
ICUpdate
,
ICUUID
string
)
error
{
var
newICReq
AddICRequest
newICReq
.
InfrastructureComponent
.
UUID
=
*
payload
.
Status
.
UUID
newICReq
.
InfrastructureComponent
.
UUID
=
IC
UUID
if
payload
.
Status
.
Name
==
nil
||
payload
.
Status
.
Category
==
nil
||
payload
.
Status
.
Type
==
nil
{
...
...
routes/infrastructure-component/ic_test.go
View file @
8a5b276b
...
...
@@ -328,8 +328,6 @@ func TestUpdateICAsAdmin(t *testing.T) {
// fake an IC update (create) message
var
update
ICUpdate
update
.
Status
=
new
(
ICStatus
)
update
.
Status
.
UUID
=
new
(
string
)
*
update
.
Status
.
UUID
=
helper
.
ICB
.
UUID
update
.
Status
.
State
=
new
(
string
)
*
update
.
Status
.
State
=
"idle"
update
.
Status
.
Name
=
new
(
string
)
...
...
@@ -342,6 +340,10 @@ func TestUpdateICAsAdmin(t *testing.T) {
payload
,
err
:=
json
.
Marshal
(
update
)
assert
.
NoError
(
t
,
err
)
var
headers
map
[
string
]
interface
{}
headers
=
make
(
map
[
string
]
interface
{})
// empty map
headers
[
"uuid"
]
=
helper
.
ICB
.
UUID
// set uuid
msg
:=
amqp
.
Publishing
{
DeliveryMode
:
2
,
Timestamp
:
time
.
Now
(),
...
...
@@ -349,6 +351,7 @@ func TestUpdateICAsAdmin(t *testing.T) {
ContentEncoding
:
"utf-8"
,
Priority
:
0
,
Body
:
payload
,
Headers
:
headers
,
}
err
=
CheckConnection
()
...
...
@@ -479,8 +482,6 @@ func TestDeleteICAsAdmin(t *testing.T) {
// fake an IC update (create) message
var
update
ICUpdate
update
.
Status
=
new
(
ICStatus
)
update
.
Status
.
UUID
=
new
(
string
)
*
update
.
Status
.
UUID
=
helper
.
ICB
.
UUID
update
.
Status
.
State
=
new
(
string
)
*
update
.
Status
.
State
=
"idle"
update
.
Status
.
Name
=
new
(
string
)
...
...
@@ -493,6 +494,10 @@ func TestDeleteICAsAdmin(t *testing.T) {
payload
,
err
:=
json
.
Marshal
(
update
)
assert
.
NoError
(
t
,
err
)
var
headers
map
[
string
]
interface
{}
headers
=
make
(
map
[
string
]
interface
{})
// empty map
headers
[
"uuid"
]
=
helper
.
ICB
.
UUID
// set uuid
msg
:=
amqp
.
Publishing
{
DeliveryMode
:
2
,
Timestamp
:
time
.
Now
(),
...
...
@@ -500,6 +505,7 @@ func TestDeleteICAsAdmin(t *testing.T) {
ContentEncoding
:
"utf-8"
,
Priority
:
0
,
Body
:
payload
,
Headers
:
headers
,
}
err
=
CheckConnection
()
...
...
@@ -777,14 +783,16 @@ func TestCreateUpdateViaAMQPRecv(t *testing.T) {
// fake an IC update message
var
update
ICUpdate
update
.
Status
=
new
(
ICStatus
)
update
.
Status
.
UUID
=
new
(
string
)
*
update
.
Status
.
UUID
=
helper
.
ICA
.
UUID
update
.
Status
.
State
=
new
(
string
)
*
update
.
Status
.
State
=
"idle"
payload
,
err
:=
json
.
Marshal
(
update
)
assert
.
NoError
(
t
,
err
)
var
headers
map
[
string
]
interface
{}
headers
=
make
(
map
[
string
]
interface
{})
// empty map
headers
[
"uuid"
]
=
helper
.
ICB
.
UUID
// set uuid
msg
:=
amqp
.
Publishing
{
DeliveryMode
:
2
,
Timestamp
:
time
.
Now
(),
...
...
@@ -792,10 +800,12 @@ func TestCreateUpdateViaAMQPRecv(t *testing.T) {
ContentEncoding
:
"utf-8"
,
Priority
:
0
,
Body
:
payload
,
Headers
:
headers
,
}
err
=
CheckConnection
()
assert
.
NoError
(
t
,
err
)
err
=
client
.
channel
.
Publish
(
VILLAS_EXCHANGE
,
""
,
false
,
...
...
@@ -900,8 +910,7 @@ func TestDeleteICViaAMQPRecv(t *testing.T) {
// fake an IC update message
var
update
ICUpdate
update
.
Status
=
new
(
ICStatus
)
update
.
Status
.
UUID
=
new
(
string
)
*
update
.
Status
.
UUID
=
helper
.
ICA
.
UUID
update
.
Status
.
State
=
new
(
string
)
*
update
.
Status
.
State
=
"idle"
// complete the (required) data of an IC
...
...
@@ -925,6 +934,10 @@ func TestDeleteICViaAMQPRecv(t *testing.T) {
payload
,
err
:=
json
.
Marshal
(
update
)
assert
.
NoError
(
t
,
err
)
var
headers
map
[
string
]
interface
{}
headers
=
make
(
map
[
string
]
interface
{})
// empty map
headers
[
"uuid"
]
=
helper
.
ICB
.
UUID
// set uuid
msg
:=
amqp
.
Publishing
{
DeliveryMode
:
2
,
Timestamp
:
time
.
Now
(),
...
...
@@ -932,6 +945,7 @@ func TestDeleteICViaAMQPRecv(t *testing.T) {
ContentEncoding
:
"utf-8"
,
Priority
:
0
,
Body
:
payload
,
Headers
:
headers
,
}
err
=
CheckConnection
()
...
...
Write
Preview
Markdown
is supported
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