Register message handler
This commit is contained in:
parent
6cf08d8131
commit
b70919b579
@ -30,6 +30,7 @@ func _messageHandler(m *nats.Msg) error {
|
|||||||
"list": listEventHandler,
|
"list": listEventHandler,
|
||||||
"get": getEventHandler,
|
"get": getEventHandler,
|
||||||
"create": createEventHandler,
|
"create": createEventHandler,
|
||||||
|
"register": registerEventHandler,
|
||||||
"update": updateEventHandler,
|
"update": updateEventHandler,
|
||||||
"delete": deleteEventHandler,
|
"delete": deleteEventHandler,
|
||||||
"stop": stopEventHandler,
|
"stop": stopEventHandler,
|
||||||
@ -177,6 +178,35 @@ func createEventHandler(m *nats.Msg, message *RequestMessage) error {
|
|||||||
return nil
|
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
|
// Update existing app
|
||||||
func updateEventHandler(m *nats.Msg, message *RequestMessage) error {
|
func updateEventHandler(m *nats.Msg, message *RequestMessage) error {
|
||||||
appTemplate := apps.App{}
|
appTemplate := apps.App{}
|
||||||
|
Loading…
Reference in New Issue
Block a user