Save metadata endpoint
This commit is contained in:
parent
a3d0ee92ce
commit
31ba1ce5a3
4 changed files with 76 additions and 0 deletions
24
glue/main.go
24
glue/main.go
|
@ -634,6 +634,30 @@ func (p *Processor) GetHostKey() (string, error) {
|
|||
return hostKey, nil
|
||||
}
|
||||
|
||||
// Save meta data about app into a file
|
||||
func (p *Processor) SaveMetadata(metadata string) error {
|
||||
container, err := p.getContainer()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
volumePath := container.VolumeHostPath()
|
||||
|
||||
f, err := os.Create(path.Join(volumePath, ".metadata.json"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
_, err = f.Write([]byte(metadata))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Processes returns list of supervisord processes
|
||||
func (p *Processor) Processes() ([]docker.Process, error) {
|
||||
container, err := p.getContainer()
|
||||
|
|
28
handlers.go
28
handlers.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -362,6 +363,33 @@ func getOrphansHander(c echo.Context) error {
|
|||
return c.JSON(http.StatusOK, []string{})
|
||||
}
|
||||
|
||||
// Save metadata for the app
|
||||
func saveMetadataHandler(c echo.Context) error {
|
||||
name := c.Param("name")
|
||||
|
||||
processor := glue.Processor{
|
||||
AppName: name,
|
||||
DB: common.GetDBConnection(),
|
||||
SnapshotProcessor: &snapshotProcessor,
|
||||
DockerSock: config.DockerSocket,
|
||||
BindIPHTTP: config.AppsBindIPHTTP,
|
||||
BindIPSSH: config.AppsBindIPSSH,
|
||||
AppsPath: config.AppsPath,
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(c.Request().Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading request body: %v", err)
|
||||
}
|
||||
|
||||
err = processor.SaveMetadata(string(body))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while save metadata: %v", err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Return info about the node including performance index
|
||||
func getNodeInfoHandler(c echo.Context) error {
|
||||
processor := glue.Processor{
|
||||
|
|
|
@ -63,6 +63,7 @@ func _messageHandler(m *nats.Msg) error {
|
|||
"add_label": addLabelEventHandler,
|
||||
"remove_label": removeLabelEventHandler,
|
||||
"list_orphans": listOrphansEventHandler,
|
||||
"save_metadata": saveMetadataEventHandler,
|
||||
"node": getNodeEventHandler,
|
||||
"create_snapshot": createSnapshotEventHandler,
|
||||
"restore_from_snapshot": restoreFromSnapshotEventHandler,
|
||||
|
@ -719,6 +720,26 @@ func listOrphansEventHandler(m *nats.Msg, message *RequestMessage) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Save metadata for the app
|
||||
func saveMetadataEventHandler(m *nats.Msg, message *RequestMessage) error {
|
||||
processor := glue.Processor{
|
||||
AppName: message.AppName,
|
||||
DB: common.GetDBConnection(),
|
||||
SnapshotProcessor: &snapshotProcessor,
|
||||
DockerSock: config.DockerSocket,
|
||||
BindIPHTTP: config.AppsBindIPHTTP,
|
||||
BindIPSSH: config.AppsBindIPSSH,
|
||||
AppsPath: config.AppsPath,
|
||||
}
|
||||
|
||||
err := processor.SaveMetadata(message.Payload)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while save metadata: %v", err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
getNodeEventHandler returns info about the node including performance index
|
||||
*/
|
||||
|
|
3
main.go
3
main.go
|
@ -183,6 +183,9 @@ func main() {
|
|||
// Rebuilds existing app, it keeps the data but creates the container again
|
||||
e.PUT("/v1/apps/:name/rebuild", rebuildAppHandler)
|
||||
|
||||
// Save metadata about app
|
||||
e.POST("/v1/apps/:name", saveMetadataHandler)
|
||||
|
||||
// Adds new label
|
||||
e.POST("/v1/apps/:name/labels", addLabelHandler)
|
||||
|
||||
|
|
Loading…
Reference in a new issue