Do not create ICs with state gone, add some logging info for AMQP-related actions #31 #41

This commit is contained in:
Sonja Happ 2020-10-30 14:49:56 +01:00
parent fb757b1172
commit e2bebbc676
2 changed files with 10 additions and 2 deletions

View file

@ -110,7 +110,11 @@ func createNewICviaAMQP(payload ICUpdate) error {
} else { } else {
newICReq.InfrastructureComponent.State = "unknown" newICReq.InfrastructureComponent.State = "unknown"
} }
// TODO check if state is "gone" and abort creation of IC in this case if newICReq.InfrastructureComponent.State == "gone" {
// Check if state is "gone" and abort creation of IC in this case
log.Println("########## AMQP: Aborting creation of IC with state gone")
return nil
}
if payload.Properties.WS_url != nil { if payload.Properties.WS_url != nil {
newICReq.InfrastructureComponent.WebsocketURL = *payload.Properties.WS_url newICReq.InfrastructureComponent.WebsocketURL = *payload.Properties.WS_url
@ -151,17 +155,19 @@ func createNewICviaAMQP(payload ICUpdate) error {
} }
func (s *InfrastructureComponent) updateICviaAMQP(payload ICUpdate) error { func (s *InfrastructureComponent) updateICviaAMQP(payload ICUpdate) error {
var updatedICReq UpdateICRequest var updatedICReq UpdateICRequest
if payload.State != nil { if payload.State != nil {
updatedICReq.InfrastructureComponent.State = *payload.State updatedICReq.InfrastructureComponent.State = *payload.State
if *payload.State == "gone" { if *payload.State == "gone" {
// remove IC from DB // remove IC from DB
log.Println("########## AMQP: Deleting IC with state gone")
err := s.delete(true) err := s.delete(true)
if err != nil { if err != nil {
// if component could not be deleted there are still configurations using it in the DB // if component could not be deleted there are still configurations using it in the DB
// continue with the update to save the new state of the component and get back to the deletion later // continue with the update to save the new state of the component and get back to the deletion later
log.Println("Could not delete IC because there is a config using it, deletion postponed") log.Println("########## AMQP: Deletion of IC postponed (config(s) associated to it)")
} }
} }

View file

@ -28,6 +28,7 @@ import (
"github.com/jinzhu/gorm/dialects/postgres" "github.com/jinzhu/gorm/dialects/postgres"
"github.com/nsf/jsondiff" "github.com/nsf/jsondiff"
"gopkg.in/go-playground/validator.v9" "gopkg.in/go-playground/validator.v9"
"log"
"time" "time"
) )
@ -131,6 +132,7 @@ func (r *AddICRequest) createIC(receivedViaAMQP bool) (InfrastructureComponent,
*action.Properties.UUID = r.InfrastructureComponent.UUID *action.Properties.UUID = r.InfrastructureComponent.UUID
} }
log.Println("########## AMQP: Sending request to create new IC")
err = sendActionAMQP(action) err = sendActionAMQP(action)
// s remains empty // s remains empty