Register message handler
This commit is contained in:
parent
6cf08d8131
commit
b70919b579
1 changed files with 30 additions and 0 deletions
|
@ -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{}
|
||||
|
|
Loading…
Reference in a new issue