From e2bebbc6763875bc89ebc2a77c5edb599fc8920c Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Fri, 30 Oct 2020 14:49:56 +0100 Subject: [PATCH] Do not create ICs with state gone, add some logging info for AMQP-related actions #31 #41 --- routes/infrastructure-component/ic_methods.go | 10 ++++++++-- routes/infrastructure-component/ic_validators.go | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/routes/infrastructure-component/ic_methods.go b/routes/infrastructure-component/ic_methods.go index 13fda99..c6a55ff 100644 --- a/routes/infrastructure-component/ic_methods.go +++ b/routes/infrastructure-component/ic_methods.go @@ -110,7 +110,11 @@ func createNewICviaAMQP(payload ICUpdate) error { } else { 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 { newICReq.InfrastructureComponent.WebsocketURL = *payload.Properties.WS_url @@ -151,17 +155,19 @@ func createNewICviaAMQP(payload ICUpdate) error { } func (s *InfrastructureComponent) updateICviaAMQP(payload ICUpdate) error { + var updatedICReq UpdateICRequest if payload.State != nil { updatedICReq.InfrastructureComponent.State = *payload.State if *payload.State == "gone" { // remove IC from DB + log.Println("########## AMQP: Deleting IC with state gone") err := s.delete(true) if err != nil { // 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 - 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)") } } diff --git a/routes/infrastructure-component/ic_validators.go b/routes/infrastructure-component/ic_validators.go index af28299..46a9eff 100644 --- a/routes/infrastructure-component/ic_validators.go +++ b/routes/infrastructure-component/ic_validators.go @@ -28,6 +28,7 @@ import ( "github.com/jinzhu/gorm/dialects/postgres" "github.com/nsf/jsondiff" "gopkg.in/go-playground/validator.v9" + "log" "time" ) @@ -131,6 +132,7 @@ func (r *AddICRequest) createIC(receivedViaAMQP bool) (InfrastructureComponent, *action.Properties.UUID = r.InfrastructureComponent.UUID } + log.Println("########## AMQP: Sending request to create new IC") err = sendActionAMQP(action) // s remains empty