Register message handler

This commit is contained in:
Adam Štrauch 2021-04-30 23:01:34 +02:00
parent 6cf08d8131
commit b70919b579
Signed by: cx
GPG key ID: 018304FFA8988F8D

View file

@ -30,6 +30,7 @@ func _messageHandler(m *nats.Msg) error {
"list": listEventHandler,
"get": getEventHandler,
"create": createEventHandler,
"register": registerEventHandler,
"update": updateEventHandler,
"delete": deleteEventHandler,
"stop": stopEventHandler,
@ -177,6 +178,35 @@ func createEventHandler(m *nats.Msg, message *RequestMessage) error {
return nil
}
// Registers new app without creating an container
func registerEventHandler(m *nats.Msg, message *RequestMessage) error {
appTemplate := apps.App{}
body := []byte(message.Payload)
err := json.Unmarshal(body, &appTemplate)
if err != nil {
log.Println("ERROR create application problem: " + err.Error())
publish(message.AppName, "payload parsing problem", true)
return err
}
err = apps.New(message.AppName, appTemplate.SSHPort, appTemplate.HTTPPort, appTemplate.Image, appTemplate.CPU, appTemplate.Memory)
if err != nil {
if validationError, ok := err.(apps.ValidationError); ok {
log.Println("ERROR create application problem: " + validationError.Error())
publish(message.AppName, "validation problem", true)
return err
}
log.Println("ERROR create application problem: " + err.Error())
publish(message.AppName, "backend problem", true)
return err
}
publish(message.AppName, "registered", false)
return nil
}
// Update existing app
func updateEventHandler(m *nats.Msg, message *RequestMessage) error {
appTemplate := apps.App{}