diff --git a/routes/infrastructure-component/ic_amqpmethods.go b/routes/infrastructure-component/ic_amqpmethods.go index 954ad84..34edb21 100644 --- a/routes/infrastructure-component/ic_amqpmethods.go +++ b/routes/infrastructure-component/ic_amqpmethods.go @@ -168,11 +168,7 @@ func createExternalIC(payload ICUpdate, ICUUID string, body []byte) error { log.Println("AMQP: Created IC with UUID ", newIC.UUID) // send ping to get full status update of this IC - if session != nil { - err = SendPing(ICUUID) - } else { - err = fmt.Errorf("cannot sent ping to %v because AMQP session is nil", ICUUID) - } + err = SendPing(ICUUID) return err } @@ -257,8 +253,17 @@ func SendPing(uuid string) error { return err } - err = session.Send(payload, uuid) - return err + if session != nil { + if session.IsReady { + err = session.Send(payload, uuid) + return err + } else { + return fmt.Errorf("could not send ping, AMQP session not ready") + } + } else { + return fmt.Errorf("could not send ping, AMQP session is nil") + } + } func sendActionAMQP(action Action, destinationUUID string) error { @@ -268,6 +273,15 @@ func sendActionAMQP(action Action, destinationUUID string) error { return err } - err = session.Send(payload, destinationUUID) - return err + if session != nil { + if session.IsReady { + err = session.Send(payload, destinationUUID) + return err + } else { + return fmt.Errorf("could not send action, AMQP session is not ready") + } + } else { + return fmt.Errorf("could not send action, AMQP session is nil") + } + } diff --git a/routes/user/scenario_duplication.go b/routes/user/scenario_duplication.go index 7b0b4a4..c5c6910 100644 --- a/routes/user/scenario_duplication.go +++ b/routes/user/scenario_duplication.go @@ -485,11 +485,15 @@ func duplicateIC(ic database.InfrastructureComponent, userName string) (string, return "", err } - if session.IsReady { - err = session.Send(payload, ic.Manager) - return newUUID, err + if session != nil { + if session.IsReady { + err = session.Send(payload, ic.Manager) + return newUUID, err + } else { + return "", fmt.Errorf("could not send IC create action, AMQP session is not ready") + } } else { - return "", fmt.Errorf("could not send IC create action, AMQP session is not ready") + return "", fmt.Errorf("could not send IC create action, AMQP session is nil") } }